示例#1
0
        public static IStructureBuilder GetBuilderForInsertsAssigningIfMissingId(IStructureBuilders builders, IStructureSchema schema, IDbClient dbClient)
        {
            Ensure.That(builders, "builders").IsNotNull();
            Ensure.That(schema, "schema").IsNotNull();
            Ensure.That(dbClient, "dbClient").IsNotNull();

            IStructureIdGenerator idGenerator;
            var idType = schema.IdAccessor.IdType;

            if (idType.IsGuid())
            {
                idGenerator = builders.GuidStructureIdGeneratorFn(schema);
            }
            else if (idType.IsIdentity())
            {
                idGenerator = builders.IdentityStructureIdGeneratorFn(schema, dbClient);
            }
            else if (idType.IsString())
            {
                idGenerator = new EmptyStructureIdGenerator();
            }
            else
            {
                throw new SisoDbException(ExceptionMessages.StructureBuilders_CreateForInsert.Inject(idType, schema.Name));
            }

            return(new StructureBuilderAutoId
            {
                StructureIdGenerator = idGenerator,
                StructureSerializer = builders.StructureSerializerFn()
            });
        }
        public static IStructureBuilder GetDefaultBuilderForInserts(IStructureBuilders builders, IStructureSchema schema, IDbClient dbClient)
        {
            Ensure.That(builders, "builders").IsNotNull();
            Ensure.That(schema, "schema").IsNotNull();
            Ensure.That(dbClient, "dbClient").IsNotNull();

            var idType = schema.IdAccessor.IdType;
            if (idType.IsGuid())
                return new StructureBuilder
                {
                    StructureIdGenerator = builders.GuidStructureIdGeneratorFn(schema),
                    StructureSerializer = builders.StructureSerializerFn()
                };

            if (idType.IsIdentity())
                return new StructureBuilder
                {
                    StructureIdGenerator = builders.IdentityStructureIdGeneratorFn(schema, dbClient),
                    StructureSerializer = builders.StructureSerializerFn()
                };

            if (idType.IsString())
                return new StructureBuilderPreservingId
                {
                    StructureIdGenerator = new EmptyStructureIdGenerator(),
                    StructureSerializer = builders.StructureSerializerFn()
                };

            throw new SisoDbException(ExceptionMessages.StructureBuilders_CreateForInsert.Inject(idType, schema.Name));
        }
示例#3
0
        public static IStructureBuilder GetDefaultBuilderForInserts(IStructureBuilders builders, IStructureSchema schema, IDbClient dbClient)
        {
            Ensure.That(builders, "builders").IsNotNull();
            Ensure.That(schema, "schema").IsNotNull();
            Ensure.That(dbClient, "dbClient").IsNotNull();

            var idType = schema.IdAccessor.IdType;

            if (idType.IsGuid())
            {
                return new StructureBuilder
                       {
                           StructureIdGenerator = builders.GuidStructureIdGeneratorFn(schema),
                           StructureSerializer  = builders.StructureSerializerFn()
                       }
            }
            ;

            if (idType.IsIdentity())
            {
                return new StructureBuilder
                       {
                           StructureIdGenerator = builders.IdentityStructureIdGeneratorFn(schema, dbClient),
                           StructureSerializer  = builders.StructureSerializerFn()
                       }
            }
            ;

            if (idType.IsString())
            {
                return new StructureBuilderPreservingId
                       {
                           StructureIdGenerator = new EmptyStructureIdGenerator(),
                           StructureSerializer  = builders.StructureSerializerFn()
                       }
            }
            ;

            throw new SisoDbException(ExceptionMessages.StructureBuilders_CreateForInsert.Inject(idType, schema.Name));
        }
        public static IStructureBuilder GetBuilderForInsertsAssigningIfMissingId(IStructureBuilders builders, IStructureSchema schema, IDbClient dbClient)
        {
            Ensure.That(builders, "builders").IsNotNull();
            Ensure.That(schema, "schema").IsNotNull();
            Ensure.That(dbClient, "dbClient").IsNotNull();

            IStructureIdGenerator idGenerator;
            var idType = schema.IdAccessor.IdType;

            if (idType.IsGuid())
                idGenerator = builders.GuidStructureIdGeneratorFn(schema);
            else if (idType.IsIdentity())
                idGenerator = builders.IdentityStructureIdGeneratorFn(schema, dbClient);
            else if (idType.IsString())
                idGenerator = new EmptyStructureIdGenerator();
            else
                throw new SisoDbException(ExceptionMessages.StructureBuilders_CreateForInsert.Inject(idType, schema.Name));

            return new StructureBuilderAutoId
            {
                StructureIdGenerator = idGenerator,
                StructureSerializer = builders.StructureSerializerFn()
            };
        }