public void RefreshTableCache <T>() where T : DataEntity { TableCache.Remove(typeof(T)); var table = _context.GetTable <T>(); TableCache.Add(typeof(T), table); }
public void TestContext() { // It is a known bug that this test currently fails due to an AOT-compilation // issue, on iOS using mono2x. foreach (var conversion in new DynamoDBEntryConversion [] { DynamoDBEntryConversion.V1, DynamoDBEntryConversion.V2 }) { TableCache.Clear(); // Cleanup existing data CleanupTables(); // Recreate context CreateContext(conversion); TestEnumHashKeyObjects(); TestEmptyCollections(conversion); TestContextConversions(); TestUnsupportedTypes(); TestEnums(conversion); TestHashObjects(); TestHashRangeObjects(); TestOtherContextOperations(); TestBatchOperations(); } }
internal ProjectionIndexCreator(TableCache parent, string indexKey, string indexKeyInCache, SearchConditions searchConditions) { this._parent = parent; this._index = new TableProjectionIndex(searchConditions); this._indexKey = indexKey; this._indexKeyInCache = indexKeyInCache; }
public Context( Expression sqlExpr, Expression parametersExpr, Expression orderExpr, Expression queryExpr, Type modelType, Type queryType) { this.SqlExpression = sqlExpr; this.ParametersExpression = parametersExpr; this.OrderExpression = orderExpr; this.QueryExpression = queryExpr; this.ModelType = modelType; this.QueryType = queryType; this.ModelProperties = modelType.GetProperties() .Where(this.IsValidProperty) .ToArray(); this.QueryProperties = queryType.GetProperties(); this.Statements = new List <Expression>(); this.Analyzer = TableCache.GetDialect(this.ModelType); }
// [Statistics Table 0] // Char Classifications : 6 // Char Ranges : 15 // States : 5 // Terminal : 1 // Transition Table : 23/30 (76.67%) // Offsets : 5 // Actions : 18 // Memory Footprint : 116 bytes // Boundries : 30 bytes // Classifications : 30 bytes // Transitions : 46 bytes // Token Types : 10 bytes // Assembly Footprint : 116 bytes (100.00%) // [Statistics Table 1] // Char Classifications : 19 // Char Ranges : 33 // States : 20 // Terminal : 7 // Transition Table : 156/380 (41.05%) // Offsets : 20 // Actions : 136 // Memory Footprint : 484 bytes // Boundries : 66 bytes // Classifications : 66 bytes // Transitions : 312 bytes // Token Types : 40 bytes // Assembly Footprint : 362 bytes (74.79%) protected AutoScanner(string expressionString) { _cache = TableCache.Get(); _expressionString = expressionString; _currentState = ScannerState.INITIAL; SetForState(ScannerState.INITIAL); }
private void GetOrCreateTable <T>() where T : DataEntity { _context.CreateTableIfNotExists(new CreateTableArgs <T>(g => g.HashKey, g => g.Id)); Stopwatch timer = Stopwatch.StartNew(); try { _context.SubmitChanges(); Logger.Trace($"{nameof(DynamoStore)}.{nameof(GetCachedTable)}<{typeof(T).Name}>", new LogItem("Action", "Getting or Creating table"), new LogItem("Type", typeof(T).ToString), new LogItem("DurationMilliseconds", timer.Elapsed.TotalMilliseconds)); } catch (Exception ex) { Logger.Error($"{nameof(DynamoStore)}.{nameof(GetCachedTable)}<{typeof(T).Name}>", new LogItem("Action", "Failed to create table"), new LogItem("Type", typeof(T).ToString), new LogItem("Exception Message", ex.Message), new LogItem("Stack Trace", ex.StackTrace), new LogItem("DurationMilliseconds", timer.Elapsed.TotalMilliseconds)); throw; } var table = _context.GetTable <T>(); TableCache.Add(typeof(T), table); }
private static IAnalyzer[] CreateAnalyzer(Type typeOfModel) { var tableAttribute = TableCache.GetTable(typeOfModel); var analyzer = tableAttribute.Analyzer; return(AnalyzerFactory.GetAnalyzer(analyzer)); }
public void TableCache_Performance() { // this should run in about 250ms. int MaxItems = 1000000; TableCache tableCache = new TableCache(MaxItems); for (int i = 0; i < MaxItems; i++) { object[] testRow = new object[] { i, "test1" + i.ToString() }; } //test the items loaded successfully int count = 0; foreach (object[] row in tableCache) { Assert.Equal("test" + count.ToString(), (string)row[1]); } //add the items again. these should replace previous values. for (int i = 0; i < MaxItems; i++) { object[] testRow = new object[] { i, "test2" + i.ToString() }; } //test the items loaded successfully count = 0; foreach (object[] row in tableCache) { Assert.Equal("test2" + count.ToString(), (string)row[1]); } }
internal IndexCreator(TableCache parent, string indexKeyInCache, SearchConditions searchConditions) { _parent = parent; _index = new TableIndex(searchConditions); _indexKey = searchConditions.Key; _indexKeyInCache = indexKeyInCache; }
private static void Add(IEntitySchema es) { _schemaIdDict[es.EntityId] = es; _schemaNameDict[es.EntityName] = es; _schemaTypeDict[es.EntityType] = es; TableCache.AppendTableType(es.EntityName, es.EntityType); }
public T GetAndLock <T>(int?wait, params object[] keys) where T : class { Column column; Table tableOrCreate = TableCache.GetTableOrCreate(typeof(T)); if (tableOrCreate.KeyColumns.Count != keys.Length) { throw new ApplicationException("主键值的数量不正确"); } T local = Activator.CreateInstance <T>(); if (tableOrCreate.KeyColumns.Count == 1) { column = tableOrCreate.KeyColumns[0]; column.SetAction(local, column.TypeHelper.ConvertFrom(keys[0], column.DataType)); } else { for (int i = 0; i < tableOrCreate.KeyColumns.Count; i++) { column = tableOrCreate.KeyColumns[i]; column.SetAction(local, column.TypeHelper.ConvertFrom(keys[i], column.DataType)); } } if (this._dataAccess.FillAndLock(this._connection, local, wait)) { return(local); } return(default(T)); }
private async Task DoUpdate() { //update must wait for any inserts to complete (to avoid updates on records that haven't been inserted yet) if (_createRecordsTask != null) { var result = await _createRecordsTask; WriteDataTicks += result; } if (_updateRecordsTask != null) { var result = await _updateRecordsTask; WriteDataTicks += result; } var updateQueries = new List <UpdateQuery>(); foreach (var row in _updateRows) { var updateQuery = new UpdateQuery( _targetTable.Name, _targetTable.Columns.Where(c => c.DeltaType != TableColumn.EDeltaType.SurrogateKey).Select(c => new QueryColumn(c, row[_targetTable.GetOrdinal(c.Name)])).ToList(), _targetTable.Columns.Where(c => c.DeltaType == TableColumn.EDeltaType.SurrogateKey).Select(c => new Filter(c, Filter.ECompare.IsEqual, row[_targetTable.GetOrdinal(c.Name)])).ToList() ); updateQueries.Add(updateQuery); } _updateRecordsTask = TaskTimer.Start(() => _targetConnection.ExecuteUpdate(_targetTable, updateQueries, _cancellationToken)); //this has no await to ensure processing continues. _updateRows = new TableCache(); }
public object FindById(Type type, params object[] keys) { Table tableOrCreate = TableCache.GetTableOrCreate(type); if (tableOrCreate.KeyColumns.Count != keys.Length) { throw new ApplicationException("主键值的数量不正确"); } object obj2 = Activator.CreateInstance(type); if (tableOrCreate.KeyColumns.Count == 1) { tableOrCreate.KeyColumns[0].PropertyInfo.SetValue(obj2, keys[0], null); } else { for (int i = 0; i < tableOrCreate.KeyColumns.Count; i++) { tableOrCreate.KeyColumns[i].PropertyInfo.SetValue(obj2, keys[i], null); } } if (this._dataAccess.Fill(this._connection, obj2)) { return(obj2); } return(null); }
public void TestContext() { Client.BeforeRequestEvent += ClientBeforeRequestEvent; try { foreach (var conversion in new DynamoDBEntryConversion[] { DynamoDBEntryConversion.V1, DynamoDBEntryConversion.V2 }) { TableCache.Clear(); // Cleanup existing data CleanupTables(); // Recreate context CreateContext(conversion); TestEmptyCollections(conversion); TestContextConversions(); TestUnsupportedTypes(); TestHashObjects(); TestHashRangeObjects(); TestOtherContextOperations(); TestBatchOperations(); } } finally { Client.BeforeRequestEvent -= ClientBeforeRequestEvent; } }
public override bool ExistTable(DbConnection conn, Type type) { Table tableOrCreate = TableCache.GetTableOrCreate(type); string sql = string.Format("select count(*) from user_tables where table_name = '{0}'", tableOrCreate.TableName.ToUpper()); return(Convert.ToInt32(base.ExecuteScalar(conn, null, sql, new DbParameter[0])) > 0); }
public void TestContext() { foreach (var conversion in new DynamoDBEntryConversion [] { DynamoDBEntryConversion.V1, DynamoDBEntryConversion.V2 }) { TableCache.Clear(); // Cleanup existing data CleanupTables(); // Recreate context CreateContext(conversion); TestEnumHashKeyObjects(); TestEmptyCollections(conversion); TestContextConversions(); TestUnsupportedTypes(); TestEnums(conversion); TestHashObjects(); TestHashRangeObjects(); TestOtherContextOperations(); TestBatchOperations(); } }
private string GetTable <T>() { if (!TableCache.ContainsKey(typeof(T))) { throw new Exception("Table not found"); } return(TableCache[typeof(T)]); }
public ActionResult CategoryTreeJson() { List <EasyUITree> list = GetTreeJson(TableCache.Where(o => o.ParentId == null).ToList()); list.Insert(0, new EasyUITree { }); return(Json(list, JsonRequestBehavior.AllowGet)); }
// [Statistics] // Char Classifications : 17 // Char Ranges : 29 // States : 18 // Terminal : 6 // Transition Table : 138/306 (45.10%) // Offsets : 18 // Actions : 120 // Memory Footprint : 428 bytes // Boundries : 58 bytes // Classifications : 58 bytes // Transitions : 276 bytes // Token Types : 36 bytes // Assembly Footprint : 330 bytes (77.10%) protected AutoScanner(string expressionString) { _cache = TableCache.Get(); _charClassificationBoundries = _cache._charClassificationBoundries; _charClassification = _cache._charClassification; _transitionTable = _cache._transitionTable; _tokenTypes = _cache._tokenTypes; _expressionString = expressionString; }
internal TableModelCache GetTableModel(Type mType) { var key = GetModelKey(mType.FullName); return(TableCache.GetOrAdd(key, k => { var tm = new TableModelCache(); tm.MType = mType; var ta = DC.AH.GetAttribute <XTableAttribute>(mType) as XTableAttribute; if (ta == null) { throw XConfig.EC.Exception(XConfig.EC._004, $"类 [[{mType.FullName}]] 必须是与 DB Table 对应的实体类,并且要由 [XTable] 标记指定类对应的表名!!!"); } tm.MProps = DC.GH.GetPropertyInfos(mType); tm.TbCols = DC.SqlProvider.GetColumnsInfos(ta.Name); if (tm.TbCols == null || tm.TbCols.Count <= 0) { throw XConfig.EC.Exception(XConfig.EC._028, $"表 [[{DC.XConn.Conn.Database}.{ta.Name}]] 中不存在任何列!!!"); } tm.TbAttr = new XTableAttribute { Name = tm.TbCols.First().TableName }; var list = new List <TmPropColAttrInfo>(); foreach (var p in tm.MProps) { var pca = new TmPropColAttrInfo(); pca.Prop = p; var ca = DC.AH.GetAttribute <XColumnAttribute>(mType, p) as XColumnAttribute; if (ca == null || ca.Name.IsNullStr()) { pca.Col = tm.TbCols.FirstOrDefault(it => it.ColumnName.Equals(p.Name, StringComparison.OrdinalIgnoreCase)); if (pca.Col == null) { throw XConfig.EC.Exception(XConfig.EC._034, $"属性 [[{mType.Name}.{p.Name}]] 在表 [[{DC.XConn.Conn.Database}.{tm.TbName}]] 中无对应的列!!!"); } } else { pca.Col = tm.TbCols.FirstOrDefault(it => it.ColumnName.Equals(ca.Name, StringComparison.OrdinalIgnoreCase)); if (pca.Col == null) { throw XConfig.EC.Exception(XConfig.EC._035, $"属性 [[{mType.Name}.{p.Name}]] 上 [XColumn] 标注的字段名 [[{ca.Name}]] 有误!!!"); } } pca.ColAttr = new XColumnAttribute { Name = pca.ColName }; pca.TbAttr = tm.TbAttr; list.Add(pca); } tm.PCA = list; return tm; })); }
internal static object EntityDataToObject(EntityData data) { Type tableType = TableCache.GetTableType(data.EntityName); object obj2 = Activator.CreateInstance(tableType); foreach (Column column in TableCache.GetTableOrCreate(tableType).Columns) { column.SetAction(obj2, data[column.ColumnName]); } return(obj2); }
// [Statistics] // Char Classifications : 20 // Char Ranges : 35 // States : 23 // Terminal : 8 // Transition Table : 193/460 (41.96%) // Offsets : 23 // Actions : 170 // Memory Footprint : 572 bytes // Boundries : 70 bytes // Classifications : 70 bytes // Transitions : 386 bytes // Token Types : 46 bytes // Assembly Footprint : 422 bytes (73.78%) protected AutoScanner(string expressionString) { _cache = TableCache.Get(); _charClassificationBoundries = _cache._charClassificationBoundries; _charClassification = _cache._charClassification; _transitionTable = _cache._transitionTable; _tokenTypes = _cache._tokenTypes; _expressionString = expressionString; _currentState = ScannerState.INITIAL; SetForState(ScannerState.INITIAL); }
public void Add(string tableName, string value, int id) { var cache = _caches.SingleOrDefault(c => c.TableName == tableName); if (cache == null) { cache = new TableCache(tableName); _caches.Add(cache); } cache.ValueId.Add(value, id); }
private bool AlterTable(TableInfo tableInfo) { try { return(base.AlterObject(tableInfo)); } finally { if (TableCache != null) { TableCache.Remove(tableInfo.TableName.FullName); } } }
public ActionResult Index(Guid id) { Menu menu = TableCache.FirstOrDefault(o => o.Id == id); ViewBag.MenuId = id; ViewBag.SeName = menu.GetSeName(); ViewBag.MenuName = menu.Name; ViewBag.Categorys = CategoryList; ViewBag.Sites = SiteList; return(View()); }
internal EntityData LoadWithEntity(SysEntity entity, int object_id) { EntityData data = null; Type tableType = TableCache.GetTableType(entity.EntityName); object obj2 = this.context.FindById(tableType, new object[] { object_id }); if (obj2 != null) { data = ObjectToEntityData(obj2, entity); } return(data); }
public bool LoadCollection <C>() where C : UnifiedIMObject <C> { string collection = UnifiedCollectionAttribute.GetCollection <C>(); if (string.IsNullOrEmpty(collection)) { throw new Exception($"Missing UnifiedCollectionAttribute on type {typeof(C).Name}"); } TableCache.Add(typeof(C), collection); ColumnCache.Add(typeof(C), ColumnProperty.GetCollumns <C>(MSSQLHelper.Instance, true, "ObjectID").Values.ToList()); return(true); }
public static AzureTableContext <T> GetContext <T>(string tableName) where T : ITableEntity, new() { lock (TableCache) { if (!TableCache.ContainsKey(tableName)) { var context = new AzureTableContext <T>(GetAccount(), tableName); TableCache.Add(tableName, context); context.Create(); } return(TableCache[tableName] as AzureTableContext <T>); } }
// public override ECacheMethod CacheMethod // { // get => ECacheMethod.NoCache; // protected set => // throw new Exception("Cache method is always PreLoadCache in the DataTable adapater and cannot be set."); // } #region Constructors public ReaderMemory(Table dataTable, List <Sort> sortFields = null) { CacheTable = new Table(dataTable.Name, dataTable.Columns, new TableCache()) { OutputSortFields = sortFields }; _data = dataTable.Data; Reset(); SortFields = sortFields; }
private void LoadTables(DynamoDBEntryConversion conversion, out Table hashTable, out Table hashRangeTable, out Table numericHashRangeTable) { TableCache.Clear(); using (var counter = CountServiceResponses(Client)) { // Load table using TryLoadTable API hashTable = null; Assert.IsFalse(Table.TryLoadTable(Client, "FakeHashTableThatShouldNotExist", conversion, out hashTable)); Assert.AreEqual(0, counter.ResponseCount); Assert.IsTrue(Table.TryLoadTable(Client, hashTableName, conversion, out hashTable)); Assert.AreEqual(1, counter.ResponseCount); Assert.IsNotNull(hashTable); Assert.AreEqual(hashTableName, hashTable.TableName); Assert.AreEqual(3, hashTable.Attributes.Count); Assert.AreEqual(1, hashTable.GlobalSecondaryIndexes.Count); Assert.AreEqual(1, hashTable.GlobalSecondaryIndexes["GlobalIndex"].ProvisionedThroughput.ReadCapacityUnits); Assert.AreEqual(1, hashTable.GlobalSecondaryIndexNames.Count); Assert.AreEqual(1, hashTable.HashKeys.Count); Assert.AreEqual(0, hashTable.RangeKeys.Count); Assert.AreEqual(1, hashTable.Keys.Count); Assert.AreEqual(0, hashTable.LocalSecondaryIndexes.Count); Assert.AreEqual(0, hashTable.LocalSecondaryIndexNames.Count); // Load table using LoadTable API (may throw an exception) AssertExtensions.ExpectException(() => Table.LoadTable(Client, "FakeHashRangeTableThatShouldNotExist", conversion)); Assert.AreEqual(1, counter.ResponseCount); hashRangeTable = Table.LoadTable(Client, hashRangeTableName, conversion); Assert.AreEqual(2, counter.ResponseCount); Assert.IsNotNull(hashRangeTable); Assert.AreEqual(hashRangeTableName, hashRangeTable.TableName); Assert.AreEqual(5, hashRangeTable.Attributes.Count); Assert.AreEqual(1, hashRangeTable.GlobalSecondaryIndexes.Count); Assert.AreEqual(1, hashRangeTable.GlobalSecondaryIndexes["GlobalIndex"].ProvisionedThroughput.ReadCapacityUnits); Assert.AreEqual(1, hashRangeTable.GlobalSecondaryIndexNames.Count); Assert.AreEqual(1, hashRangeTable.HashKeys.Count); Assert.AreEqual(1, hashRangeTable.RangeKeys.Count); Assert.AreEqual(2, hashRangeTable.Keys.Count); Assert.AreEqual(1, hashRangeTable.LocalSecondaryIndexes.Count); Assert.AreEqual(2, hashRangeTable.LocalSecondaryIndexes["LocalIndex"].KeySchema.Count); Assert.AreEqual(1, hashRangeTable.LocalSecondaryIndexNames.Count); numericHashRangeTable = Table.LoadTable(Client, numericHashRangeTableName, conversion); Assert.AreEqual(1, numericHashRangeTable.HashKeys.Count); Assert.AreEqual(1, numericHashRangeTable.RangeKeys.Count); Assert.AreEqual(2, numericHashRangeTable.Keys.Count); Assert.IsTrue(numericHashRangeTable.Keys.ContainsKey("CreationTime")); Assert.IsTrue(numericHashRangeTable.Keys.ContainsKey("Name")); } }
public static TableCache Get() { TableCache result; lock (_weakRef) { if ((result = (TableCache)_weakRef.Target) == null) { _weakRef.Target = result = new TableCache(); } } return(result); }
private DataTable <T> GetCachedTable <T>() where T : DataEntity { lock (TableCache) { if (!TableCache.ContainsKey(typeof(T))) { Logger.Trace($"{nameof(DynamoStore)}.{nameof(GetCachedTable)}<{typeof(T).Name}>", new LogItem("Action", "Not cached, call GetOrCreateTable")); GetOrCreateTable <T>(); } return((DataTable <T>)TableCache[typeof(T)]); } }
internal TableLock(TableCache repository, string lockKey, TimeSpan lockTimeout) { this._cache = repository; this._lockKey = lockKey; this._cache.LockTable(lockKey, lockTimeout); }