private List <ColumnProperty> GetColumns <T>() { if (!ColumnCache.ContainsKey(typeof(T))) { throw new Exception("Table not found"); } return(ColumnCache[typeof(T)]); }
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); }
private static int[] ExecuteIntegerArrayQueryImpl(SQLiteConnection connection, string query, int queryIndex, object[] keys) { try { if (CacheManager.Connection != connection.GetDbPointer()) // don't cache this { return ExecuteIntegerArrayQuerySots(connection, query, keys); } if (!_queryCaches.ContainsKey(queryIndex)) { _queryCaches[queryIndex] = new ColumnCache<int[]>(query); } ColumnCache<int[]> cache = (ColumnCache<int[]>)_queryCaches[queryIndex]; if (cache.Ignore) { return ExecuteIntegerArrayQuerySots(connection, query, keys); } var ts = cache.GetTS(keys); var key = BuildKey(keys); if (CacheManager.Invalidations.IsInvalidated(ts, cache.Tables)) { cache.Clear(); } int[] foundItem = new int[0]; var found = cache.TryGetItem(key, out foundItem); if (!found) { foundItem = ExecuteIntegerArrayQuerySots(connection, query, keys); cache.SetItem(key, foundItem); } return foundItem; } catch (Exception ex) { Sotsos_DebugHelper.SotsosLog("Error in ExecuteIntegerArrayQuery while trying to run query {0}, idx {1}", query, queryIndex); throw; } }
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>(MySQLHelper.Instance, true, "ObjectID").Values.ToList()); ColumnProperty objidcol = GetColumns <C>().FirstOrDefault(X => X.Name == "ObjectID"); foreach (ColumnProperty prop in GetColumns <C>()) { if (prop.Name == "ObjectID") { prop.OverrideSqlType("char(32)"); } else { prop.OverrideSqlType(MySQLHelper.Instance.GetSqlType(prop.Type, prop.Column)); } } if (!MySQLTable.GetTables(SQL).Contains(collection)) { try { MySQLTable.CreateTable(SQL, collection, GetColumns <C>()); } catch (Exception ex) { throw new Exception($"Failed to create table {collection}"); } } else { MySQLTable table = MySQLTable.GetTable(SQL, collection); List <ColumnProperty> todo = table.Columns.ToList(); foreach (ColumnProperty col in GetColumns <C>()) { ColumnProperty existing = table.Columns.FirstOrDefault(X => X.Name == col.Name); if (existing == null) { System.Console.WriteLine($"SQL missing Column {col.Name}... Adding"); try { MySQLTable.AddColumn(SQL, collection, col.Name, col.SqlType); } catch (Exception ex) { throw new Exception($"Failed to add collumn {col.Name}\n{ex.Message}"); } } else if (!existing.SqlType.StartsWith(col.SqlType)) { System.Console.WriteLine($"SQL incorrect Column Type for {col.Name}... Converting"); try { MySQLTable.ConvertColumn(SQL, collection, col.Name, col.SqlType); } catch (Exception ex) { throw new Exception($"Failed to convert collumn {col.Name}\n{ex.Message}"); } } if (existing != null) { todo.Remove(existing); } } foreach (ColumnProperty prop in todo) { System.Console.WriteLine($"Excess collumn {prop.Name}... Removing"); try { MySQLTable.RemoveColumn(SQL, collection, prop.Name); } catch (Exception ex) { throw new Exception($"Failed to remove collumn {prop.Name}\n{ex.Message}"); } } } return(true); }