コード例 #1
0
 public virtual void NotifyOnDeleted(ISession session, IStructureSchema schema, IQuery query)
 {
     foreach (var handler in OnDeletedByQueryHandlers)
     {
         handler.Invoke(session, schema, query);
     }
 }
コード例 #2
0
        public virtual void Insert(IStructureSchema structureSchema, IStructure[] structures)
        {
            var groupedIndexInsertActions = new IndexInsertAction[0];

            Task task = null;

            try
            {
                task = Task.Factory.StartNew(
                    () => groupedIndexInsertActions = CreateGroupedIndexInsertActions(structureSchema, structures));

                InsertStructures(structureSchema, structures);
                InsertUniques(structureSchema, structures);

                Task.WaitAll(task);
            }
            finally
            {
                if (task != null && task.Status == TaskStatus.RanToCompletion)
                {
                    task.Dispose();
                }
            }

            if (!groupedIndexInsertActions.Any())
            {
                return;
            }

            InsertIndexes(groupedIndexInsertActions);
        }
コード例 #3
0
        public void Synchronize(IStructureSchema structureSchema)
        {
            var keyNamesToDrop = GetKeyNamesToDrop(structureSchema);

            if (keyNamesToDrop.Count > 0)
                DeleteRecordsMatchingKeyNames(structureSchema, keyNamesToDrop);
        }
コード例 #4
0
 public virtual void NotifyOnInserted(ISession session, IStructureSchema schema, IStructure[] structures, object[] items)
 {
     for (var i = 0; i < structures.Length; i++)
     {
         NotifyOnInserted(session, schema, structures[i], items[i]);
     }
 }
コード例 #5
0
 public int CheckOutAndGetSeed(IStructureSchema structureSchema, int numOfIds)
 {
     using(var dbClient = new SqlDbClient(_connectionInfo, false))
     {
         return dbClient.GetIdentity(structureSchema.Hash, numOfIds);
     }
 }
コード例 #6
0
        public virtual void Upsert(IStructureSchema structureSchema, IDbClient dbClient, bool allowDynamicSchemaCreation, bool allowDynamicSchemaUpdates)
        {
            if (!allowDynamicSchemaCreation && !allowDynamicSchemaUpdates)
            {
                return;
            }

            var modelInfo = dbClient.GetModelTablesInfo(structureSchema);

            if (allowDynamicSchemaUpdates)
            {
                IndexesDbSchemaSynchronizer.Synchronize(structureSchema, dbClient, modelInfo.GetIndexesTableNamesForExisting());

                if (modelInfo.Statuses.UniquesTableExists)
                {
                    UniquesDbSchemaSynchronizer.Synchronize(structureSchema, dbClient);
                }
            }

            if (!allowDynamicSchemaCreation || modelInfo.Statuses.AllExists)
            {
                return;
            }

            foreach (var sql in GenerateSql(structureSchema, modelInfo))
            {
                dbClient.ExecuteNonQuery(sql, new DacParameter(DbSchemaInfo.Parameters.EntityNameParamPrefix, structureSchema.Name));
            }
        }
コード例 #7
0
        public override void Drop(IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var modelInfo = GetModelTablesInfo(structureSchema);

            var sqlDropTableFormat = SqlStatements.GetSql("DropTable");

            using (var cmd = CreateCommand(string.Empty, new DacParameter(DbSchemaInfo.Parameters.EntityNameParamPrefix, structureSchema.Name)))
            {
                DropIndexesTables(cmd, modelInfo.Statuses.IndexesTableStatuses, modelInfo.Names.IndexesTableNames);

                if (modelInfo.Statuses.UniquesTableExists)
                {
                    cmd.CommandText = sqlDropTableFormat.Inject(structureSchema.GetUniquesTableName());
                    cmd.ExecuteNonQuery();
                }

                if (modelInfo.Statuses.SpatialTableExists)
                {
                    cmd.CommandText = sqlDropTableFormat.Inject(structureSchema.GetStructureTableName());
                    cmd.ExecuteNonQuery();
                }

                if (modelInfo.Statuses.StructureTableExists)
                {
                    cmd.CommandText = sqlDropTableFormat.Inject(structureSchema.GetStructureTableName());
                    cmd.ExecuteNonQuery();
                }

                cmd.CommandText = SqlStatements.GetSql("DeleteStructureFromSisoDbIdentitiesTable");
                cmd.ExecuteNonQuery();
            }
        }
コード例 #8
0
        public virtual void BulkInsertStructures(IStructureSchema structureSchema, IStructure[] structures)
        {
            if (!structures.Any())
            {
                return;
            }

            if (HasPipe)
            {
                foreach (var structure in structures)
                {
                    structure.Data = Pipe.Writing(structureSchema, structure.Data);
                }
            }

            using (var structuresReader = new StructuresReader(new StructureStorageSchema(structureSchema, structureSchema.GetStructureTableName()), structures))
            {
                using (var bulkInserter = GetBulkCopy())
                {
                    bulkInserter.DestinationTableName = structuresReader.StorageSchema.Name;
                    bulkInserter.BatchSize            = structures.Length;

                    var fields = structuresReader.StorageSchema.GetFieldsOrderedByIndex().Where(f => !f.Equals(StructureStorageSchema.Fields.RowId)).ToArray();
                    foreach (var field in fields)
                    {
                        bulkInserter.AddColumnMapping(field.Name, field.Name);
                    }

                    bulkInserter.Write(structuresReader);
                }
            }
        }
コード例 #9
0
ファイル: Query.cs プロジェクト: ovuncgursoy/SisoDb-Provider
		public Query(IStructureSchema structureSchema)
		{
			Ensure.That(structureSchema, "structureSchema").IsNotNull();

			StructureSchema = structureSchema;
		    IsCacheable = false;
		}
コード例 #10
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));
        }
コード例 #11
0
        public override IEnumerable<string> GetJsonByIds(IEnumerable<IStructureId> ids, IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();
            var sqlFormat = SqlStatements.GetSql("GetJsonByIds").Inject(structureSchema.GetStructureTableName(), "{0}");

            using (var cmd = CreateCommand(string.Empty))
            {
                foreach (var batchedIds in ids.Batch<IStructureId, IDacParameter>(MaxBatchedIdsSize, (id, batchCount) => new DacParameter(string.Concat("id", batchCount), id.Value)))
                {
                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd, batchedIds);

                    var paramsString = string.Join(",", batchedIds.Select(p => p.Name));
                    cmd.CommandText = sqlFormat.Inject(paramsString);

                    using (var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SequentialAccess))
                    {
                        while (reader.Read())
                        {
                            yield return reader.GetString(0);
                        }
                        reader.Close();
                    }
                }
            }
        }
コード例 #12
0
        protected virtual IStructure[] CreateStructuresInParallel <T>(T[] items, IStructureSchema structureSchema) where T : class
        {
            var structureIds = StructureIdGenerator.Generate(structureSchema, items.Length);
            var structures   = new IStructure[items.Length];
            var timeStamp    = SysDateTime.Now;

            Parallel.For(0, items.Length, i =>
            {
                var id  = structureIds[i];
                var itm = items[i];

                structureSchema.IdAccessor.SetValue(itm, id);

                if (structureSchema.HasTimeStamp)
                {
                    structureSchema.TimeStampAccessor.SetValue(itm, timeStamp);
                }

                structures[i] = new Structure(
                    structureSchema.Name,
                    id,
                    IndexesFactory.CreateIndexes(structureSchema, itm, id),
                    StructureSerializer.Serialize(itm, structureSchema));
            });

            return(structures);
        }
コード例 #13
0
        public virtual int RowCountByQuery(IStructureSchema structureSchema, IDbQuery query)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();
            Ensure.That(query, "query").IsNotNull();

            return(ExecuteScalar <int>(query.Sql, query.Parameters));
        }
コード例 #14
0
		public void Synchronize(IStructureSchema structureSchema, IDbClient dbClient)
        {
            var keyNamesToDrop = GetDbKeyNamesToDrop(structureSchema, dbClient);

            if (keyNamesToDrop.Any())
                DeleteRecordsMatchingKeyNames(structureSchema, keyNamesToDrop, dbClient);
        }
コード例 #15
0
        protected override IStructure[] CreateStructuresInSerial <T>(T[] items, IStructureSchema structureSchema)
        {
            var structures = new IStructure[items.Length];
            var timeStamp  = SysDateTime.Now;

            for (var i = 0; i < structures.Length; i++)
            {
                var itm         = items[i];
                var structureId = structureSchema.IdAccessor.GetValue(itm);
                if (structureId.IsEmpty)
                {
                    structureId = StructureIdGenerator.Generate(structureSchema);
                    structureSchema.IdAccessor.SetValue(itm, structureId);
                }

                if (structureSchema.HasTimeStamp)
                {
                    structureSchema.TimeStampAccessor.SetValue(itm, timeStamp);
                }

                structures[i] = new Structure(
                    structureSchema.Name,
                    structureId,
                    IndexesFactory.CreateIndexes(structureSchema, itm, structureId),
                    StructureSerializer.Serialize(itm, structureSchema));
            }

            return(structures);
        }
コード例 #16
0
 public virtual void NotifyOnUpdated(ISession session, IStructureSchema schema, IStructure structure, object item)
 {
     foreach (var handler in OnUpdatedHandlers)
     {
         handler.Invoke(session, schema, structure, item);
     }
 }
コード例 #17
0
        public virtual void Insert(IStructureSchema structureSchema, IStructure[] structures)
        {
            var groupedIndexInsertActions = new IndexInsertAction[0];

            Task task = null;
            try
            {
                task = Task.Factory.StartNew(
                    () => groupedIndexInsertActions = CreateGroupedIndexInsertActions(structureSchema, structures));

                InsertStructures(structureSchema, structures);
                InsertUniques(structureSchema, structures);

                Task.WaitAll(task);
            }
            finally
            {
                if (task != null && task.Status == TaskStatus.RanToCompletion)
                    task.Dispose();
            }

            if (!groupedIndexInsertActions.Any())
                return;

            InsertIndexes(groupedIndexInsertActions);
        }
コード例 #18
0
        public Query(IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            StructureSchema = structureSchema;
            IsCacheable     = false;
        }
コード例 #19
0
        protected virtual void BulkInsertUniques(IStructureSchema structureSchema, IStructureIndex[] uniques)
        {
            if (!uniques.Any())
            {
                return;
            }

            var uniquesStorageSchema = new UniqueStorageSchema(structureSchema, structureSchema.GetUniquesTableName());

            using (var uniquesReader = new UniquesReader(uniquesStorageSchema, uniques))
            {
                using (var bulkInserter = MainDbClient.GetBulkCopy())
                {
                    bulkInserter.DestinationTableName = uniquesReader.StorageSchema.Name;
                    bulkInserter.BatchSize            = uniques.Length;

                    var fields = uniquesReader.StorageSchema.GetFieldsOrderedByIndex().Where(f => !f.Equals(StructureStorageSchema.Fields.RowId)).ToArray();
                    foreach (var field in fields)
                    {
                        bulkInserter.AddColumnMapping(field.Name, field.Name);
                    }

                    bulkInserter.Write(uniquesReader);
                }
            }
        }
コード例 #20
0
        private bool SchemaIsAllreadyUpserted(IStructureSchema structureSchema, IDbClient dbClient)
        {
            if (UpsertedSchemas.Contains(structureSchema.Name) || TransientSchemas.Contains(structureSchema.Name))
                return true;

            return (UpsertedSchemasByDbClient.ContainsKey(dbClient.Id) && UpsertedSchemasByDbClient[dbClient.Id].Contains(structureSchema.Name));
        }
コード例 #21
0
        public virtual void Drop(IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var names = new ModelTableNames(structureSchema);

            EnsureValidNames(names);

            var sql = SqlStatements.GetSql("DropStructureTables").Inject(
                names.IndexesTableNames.IntegersTableName,
                names.IndexesTableNames.FractalsTableName,
                names.IndexesTableNames.BooleansTableName,
                names.IndexesTableNames.DatesTableName,
                names.IndexesTableNames.GuidsTableName,
                names.IndexesTableNames.StringsTableName,
                names.IndexesTableNames.TextsTableName,
                names.SpatialTableName,
                names.UniquesTableName,
                names.StructureTableName);

            using (var cmd = CreateCommand(sql, new DacParameter(DbSchemaInfo.Parameters.EntityNameParamPrefix, structureSchema.Name)))
            {
                cmd.ExecuteNonQuery();
            }
        }
コード例 #22
0
 public virtual void NotifyOnDeleted(ISession session, IStructureSchema schema, IStructureId[] ids)
 {
     foreach (var id in ids)
     {
         NotifyOnDeleted(session, schema, id);
     }
 }
コード例 #23
0
 public virtual void NotifyOnDeleted(ISession session, IStructureSchema schema, IStructureId id)
 {
     foreach (var handler in OnDeletedHandlers)
     {
         handler.Invoke(session, schema, id);
     }
 }
コード例 #24
0
        private IList<string> GetKeyNamesToDrop(IStructureSchema structureSchema)
        {
            var structureFields = new HashSet<string>(structureSchema.IndexAccessors.Select(iac => iac.Name));
            var keyNames = GetKeyNames(structureSchema);

            return keyNames.Where(kn => !structureFields.Contains(kn)).ToList();
        }
コード例 #25
0
		private IStructureBuilder CreateForInserts(IStructureSchema structureSchema, IIdentityStructureIdGenerator identityStructureIdGenerator)
		{
			Ensure.That(structureSchema, "structureSchema").IsNotNull();
			Ensure.That(identityStructureIdGenerator, "identityStructureIdGenerator").IsNotNull();

            var idType = structureSchema.IdAccessor.IdType;

            if (idType == StructureIdTypes.Guid)
                return new StructureBuilder
                {
                    StructureIdGenerator = new SequentialGuidStructureIdGenerator(),
                    StructureSerializer = new SerializerForStructureBuilder()
                };

            if (idType.IsIdentity())
                return new StructureBuilder
                {
					StructureIdGenerator = identityStructureIdGenerator,
                    StructureSerializer = new SerializerForStructureBuilder()
                };

            if (idType == StructureIdTypes.String)
                return new StructureBuilderPreservingId
                {
                    StructureIdGenerator = new EmptyStructureIdGenerator(),
                    StructureSerializer = new SerializerForStructureBuilder()
                };

            throw new SisoDbException(ExceptionMessages.StructureBuilders_CreateForInsert.Inject(idType, structureSchema.Name));
        }
コード例 #26
0
        public virtual bool UniquesTableHasMember <T>(IStructureSchema structureSchema, object id, Expression <Func <T, object> > member) where T : class
        {
            var memberPath = GetMemberPath(member);
            var sql        = "[{0}] = @pStructureId and [{1}] = @pPath".Inject(UniqueStorageSchema.Fields.StructureId.Name, UniqueStorageSchema.Fields.UqMemberPath.Name);

            return(RowCount(structureSchema.GetUniquesTableName(), sql, new DacParameter("pStructureId", id), new DacParameter("pPath", memberPath)) > 0);
        }
コード例 #27
0
        public virtual void RemoveFromCache(IStructureSchema structureSchema)
		{
			lock (_upsertedSchemas)
			{
				_upsertedSchemas.Remove(structureSchema.Name);
			}
		}
コード例 #28
0
		public string[] GenerateSql(IStructureSchema structureSchema, IndexesTableNames names, IndexesTableStatuses statuses)
		{
			if(statuses.AllExists)
				return new string[0];

			var structureTableName = structureSchema.GetStructureTableName();
			var sqlTemplateNameSuffix = GetSqlTemplateNameSuffix(structureSchema.IdAccessor.IdType);
			var generators = new Func<string>[]
			{
				() => !statuses.IntegersTableExists 
					? GenerateSqlFor("CreateIntegersIndexes", sqlTemplateNameSuffix, structureTableName, names.IntegersTableName) 
					: string.Empty,
				() => !statuses.FractalsTableExists 
					? GenerateSqlFor("CreateFractalsIndexes", sqlTemplateNameSuffix, structureTableName, names.FractalsTableName) 
					: string.Empty,
				() => !statuses.BooleansTableExists 
					? GenerateSqlFor("CreateBooleansIndexes", sqlTemplateNameSuffix, structureTableName, names.BooleansTableName) 
					: string.Empty,
				() => !statuses.DatesTableExists 
					? GenerateSqlFor("CreateDatesIndexes", sqlTemplateNameSuffix, structureTableName, names.DatesTableName) 
					: string.Empty,
				() => !statuses.GuidsTableExists 
					? GenerateSqlFor("CreateGuidsIndexes", sqlTemplateNameSuffix, structureTableName, names.GuidsTableName) 
					: string.Empty,
				() => !statuses.StringsTableExists 
					? GenerateSqlFor("CreateStringsIndexes", sqlTemplateNameSuffix, structureTableName, names.StringsTableName) 
					: string.Empty,
				() => !statuses.TextsTableExists 
					? GenerateSqlFor("CreateTextsIndexes", sqlTemplateNameSuffix, structureTableName, names.TextsTableName) 
					: string.Empty
			};

			return generators.Select(generator => generator()).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
		}
コード例 #29
0
		private string[] GetDbKeyNamesToDrop(IStructureSchema structureSchema, IDbClient dbClient)
        {
            var structureFields = new HashSet<string>(structureSchema.IndexAccessors.Select(iac => iac.Path));
            var keyNames = GetExistingDbKeyNames(structureSchema, dbClient);

            return keyNames.Where(kn => !structureFields.Contains(kn)).ToArray();
        }
コード例 #30
0
        public IStructureId[] Generate(IStructureSchema structureSchema, int numOfIds)
        {
            if (structureSchema.IdAccessor.IdType == StructureIdTypes.Identity)
                return GenerateIdentityStructureId(structureSchema, numOfIds);

            return GenerateBigIdentityStructureId(structureSchema, numOfIds);
        }
コード例 #31
0
        private string[] GetDbKeyNamesToDrop(IStructureSchema structureSchema, IDbClient dbClient)
        {
            var structureFields = new HashSet <string>(structureSchema.IndexAccessors.Select(iac => iac.Path));
            var keyNames        = GetExistingDbKeyNames(structureSchema, dbClient);

            return(keyNames.Where(kn => !structureFields.Contains(kn)).ToArray());
        }
コード例 #32
0
        protected virtual IndexInsertAction[] CreateGroupedIndexInsertActions(IStructureSchema structureSchema, IStructure[] structures)
        {
            var indexesTableNames = structureSchema.GetIndexesTableNames();
            var insertActions     = new Dictionary <DataTypeCode, IndexInsertAction>(indexesTableNames.All.Length);

            foreach (var group in structures.SelectMany(s => s.Indexes).GroupBy(i => i.DataTypeCode))
            {
                var insertAction = CreateIndexInsertActionGroup(structureSchema, indexesTableNames, group.Key, group.ToArray());
                if (insertAction.HasData)
                {
                    insertActions.Add(group.Key, insertAction);
                }
            }

            var mergeStringsAndEnums = insertActions.ContainsKey(DataTypeCode.String) && insertActions.ContainsKey(DataTypeCode.Enum);

            if (mergeStringsAndEnums)
            {
                var strings = insertActions[DataTypeCode.String];
                var enums   = insertActions[DataTypeCode.Enum];
                insertActions.Remove(DataTypeCode.Enum);

                insertActions[DataTypeCode.String] = CreateIndexInsertActionGroup(structureSchema, indexesTableNames, DataTypeCode.String, strings.Data.MergeWith(enums.Data).ToArray());
            }

            return(insertActions.Values.ToArray());
        }
コード例 #33
0
        public virtual void InsertIndexesOnly(IStructureSchema structureSchema, IStructure[] structures)
        {
            var groupedIndexInsertActions = CreateGroupedIndexInsertActions(structureSchema, structures);
            if (!groupedIndexInsertActions.Any())
                return;

            InsertIndexes(groupedIndexInsertActions);
        }
コード例 #34
0
 private static IStructureBuilder CreateForUpdates(IStructureSchema structureSchema)
 {
     return new StructureBuilderPreservingId
     {
         StructureIdGenerator = new EmptyStructureIdGenerator(),
         StructureSerializer = new SerializerForStructureBuilder()
     };
 }
コード例 #35
0
		public Query(IStructureSchema structureSchema)
		{
			Ensure.That(structureSchema, "structureSchema").IsNotNull();

			StructureSchema = structureSchema;

			Includes = new List<IParsedLambda>();
		}
コード例 #36
0
 protected virtual IStructureBuilder GetDefaultBuilderForUpdates(IStructureSchema structureSchema)
 {
     return(new StructureBuilderPreservingId
     {
         StructureIdGenerator = new EmptyStructureIdGenerator(),
         StructureSerializer = StructureSerializerFn()
     });
 }
コード例 #37
0
        public virtual int RowCount(IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var sql = SqlStatements.GetSql("RowCount").Inject(structureSchema.GetStructureTableName());

            return(ExecuteScalar <int>(sql));
        }
コード例 #38
0
        public virtual void DeleteById(IStructureId structureId, IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var sql = SqlStatements.GetSql("DeleteById").Inject(structureSchema.GetStructureTableName());

            ExecuteNonQuery(sql, new DacParameter("id", structureId.Value));
        }
コード例 #39
0
        private void DeleteRecordsMatchingKeyNames(IStructureSchema structureSchema, IEnumerable <string> names, IDbClient dbClient)
        {
            var inString = string.Join(",", names.Select(n => "'" + n + "'"));
            var sql      = _sqlStatements.GetSql("UniquesSchemaSynchronizer_DeleteRecordsMatchingKeyNames")
                           .Inject(structureSchema.GetUniquesTableName(), UniqueStorageSchema.Fields.UqMemberPath.Name, inString);

            dbClient.ExecuteNonQuery(sql);
        }
コード例 #40
0
		private void DeleteRecordsMatchingKeyNames(IStructureSchema structureSchema, IEnumerable<string> names, IDbClient dbClient)
        {
            var inString = string.Join(",", names.Select(n => "'" + n + "'"));
            var sql = _sqlStatements.GetSql("UniquesSchemaSynchronizer_DeleteRecordsMatchingKeyNames")
                .Inject(structureSchema.GetUniquesTableName(), UniqueStorageSchema.Fields.UqMemberPath.Name, inString);

            dbClient.ExecuteNonQuery(sql);
        }
コード例 #41
0
        public virtual void DeleteAll(IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var sql = SqlStatements.GetSql("DeleteAll").Inject(structureSchema.GetStructureTableName());

            ExecuteNonQuery(sql);
        }
コード例 #42
0
 protected virtual IStructureBuilder GetDefaultBuilderForUpdates(IStructureSchema structureSchema)
 {
     return new StructureBuilderPreservingId
     {
         StructureIdGenerator = new EmptyStructureIdGenerator(),
         StructureSerializer = StructureSerializerFn()
     };
 }
コード例 #43
0
        public virtual ModelTablesInfo GetModelTablesInfo(IStructureSchema structureSchema)
        {
            var names = new ModelTableNames(structureSchema);

            EnsureValidNames(names);

            return(new ModelTablesInfo(names, GetModelTableStatuses(names)));
        }
コード例 #44
0
 public virtual void RemoveFromCache(IStructureSchema structureSchema)
 {
     lock (Lock)
     {
         UpsertedSchemas.Remove(structureSchema.Name);
         TransientSchemas.Remove(structureSchema.Name);
     }
 }
コード例 #45
0
        private void DeleteRecordsMatchingKeyNames(IStructureSchema structureSchema, IEnumerable<string> names)
        {
            var inString = string.Join(",", names.Select(n => "'" + n + "'"));
            var sql = _sqlStrings.GetSql("UniquesSchemaSynchronizer_DeleteRecordsMatchingKeyNames")
                .Inject(structureSchema.GetUniquesTableName(), UniqueStorageSchema.Fields.Name.Name, inString);

            _dbClient.ExecuteNonQuery(CommandType.Text, sql);
        }
コード例 #46
0
        protected StorageSchemaBase(IStructureSchema structureSchema, string storageSchemaName)
        {
            FieldsByIndex = new Dictionary<int, SchemaField>();
            FieldsByName = new Dictionary<string, SchemaField>();
            Name = storageSchemaName;

            InitializeFields(structureSchema);
        }
コード例 #47
0
 public virtual void RemoveFromCache(IStructureSchema structureSchema)
 {
     lock (Lock)
     {
         UpsertedSchemas.Remove(structureSchema.Name);
         TransientSchemas.Remove(structureSchema.Name);
     }
 }
コード例 #48
0
        public virtual IEnumerable <string> GetJsonOrderedByStructureId(IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var sql = SqlStatements.GetSql("GetAllJson").Inject(structureSchema.GetStructureTableName());

            return(YieldJson(sql));
        }
コード例 #49
0
        public virtual string GetJsonByIdWithLock(IStructureId structureId, IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var sql = SqlStatements.GetSql("GetJsonByIdWithLock").Inject(structureSchema.GetStructureTableName());

            return(ExecuteScalar <string>(sql, new DacParameter("id", structureId.Value)));
        }
コード例 #50
0
        public virtual void DropStructureSet(IStructureSchema structureSchema, IDbClient dbClient)
        {
            lock (_upsertedSchemas)
            {
                _upsertedSchemas.Remove(structureSchema.Name);

                dbClient.Drop(structureSchema);
            }
        }
コード例 #51
0
        public virtual IStructureId[] Generate(IStructureSchema structureSchema, int numOfIds)
        {
            var structureIds = new IStructureId[numOfIds];

            for (var c = 0; c < structureIds.Length; c++)
                structureIds[c] = StructureId.Create(SequentialGuid.New());

            return structureIds;
        }
コード例 #52
0
        public static bool Any(this ICacheProvider cacheProvider, IStructureSchema structureSchema, Func <IStructureSchema, bool> nonCacheQuery)
        {
            if (!cacheProvider.IsEnabledFor(structureSchema))
            {
                return(nonCacheQuery.Invoke(structureSchema));
            }

            return(cacheProvider[structureSchema.Type.Type].Count() > 0 || nonCacheQuery.Invoke(structureSchema));
        }
コード例 #53
0
        public static bool Exists(this ICacheProvider cacheProvider, IStructureSchema structureSchema, IStructureId structureId, Func <IStructureId, bool> nonCacheQuery)
        {
            if (!cacheProvider.IsEnabledFor(structureSchema))
            {
                return(nonCacheQuery.Invoke(structureId));
            }

            return(cacheProvider[structureSchema.Type.Type].Exists(structureId) || nonCacheQuery.Invoke(structureId));
        }
コード例 #54
0
        protected override SchemaField[] GetSchemaFields(IStructureSchema structureSchema)
        {
            var staticFields = Fields.GetOrderedFields();
            var dynamicIndex = staticFields.Count();
            var dynamicFields = structureSchema.IndexAccessors.Select(iac => new SchemaField(dynamicIndex++, iac.Name));
            var fields = staticFields.Union(dynamicFields).ToArray();

            return fields;
        }
コード例 #55
0
    	public IStructureId Generate(IStructureSchema structureSchema)
    	{
    		var nextId = DbClient.CheckOutAndGetNextIdentity(structureSchema.Name, 1);

            if (structureSchema.IdAccessor.IdType == StructureIdTypes.Identity)
                return StructureId.Create((int)nextId);

            return StructureId.Create(nextId);
        }
コード例 #56
0
 public virtual void Drop(IStructureSchema structureSchema, IDbClient dbClient)
 {
     lock (Lock)
     {
         UpsertedSchemas.Remove(structureSchema.Name);
         TransientSchemas.Remove(structureSchema.Name);
         dbClient.Drop(structureSchema);
     }
 }
コード例 #57
0
        public virtual bool Exists(IStructureSchema structureSchema, IStructureId structureId)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();
            Ensure.That(structureId, "structureId").IsNotNull();

            var sql = SqlStatements.GetSql("ExistsById").Inject(structureSchema.GetStructureTableName());

            return(ExecuteScalar <int>(sql, new DacParameter("id", structureId.Value)) > 0);
        }
コード例 #58
0
        public IStructureId[] Generate(IStructureSchema structureSchema, int numOfIds)
        {
            var structureIds = new IStructureId[numOfIds];

            for (var c = 0; c < structureIds.Length; c++)
                structureIds[c] = StructureId.Create(Guid.NewGuid());

            return structureIds;
        }
コード例 #59
0
        protected void InitializeFields(IStructureSchema structureSchema)
        {
            var fields = GetSchemaFields(structureSchema);

            foreach (var field in fields)
            {
                FieldsByIndex.Add(field.Ordinal, field);
                FieldsByName.Add(field.Name, field);
            }
        }
コード例 #60
0
        private void InitializeFields(IStructureSchema structureSchema)
        {
            var fields = GetSchemaFields(structureSchema);

            foreach (var field in fields.OrderBy(f => f.Ordinal))
            {
                _fieldsByIndex.Add(field.Ordinal, field);
                _fieldsByName.Add(field.Name, field);
            }
        }