internal IEnumerable <dynamic> Get( bool IsGeneric, PluginBase Plugin, DbProviderFactory Factory, DbConnection connection, string BareTableName, string TableOwner, DataContract DataContract, dynamic Mighty ) { string connectionString = connection == null ? Mighty.ConnectionString : connection.ConnectionString; if (connectionString == null) { throw new Exception($"No {nameof(DbConnection)} and no local or global connection string available when fetching table metadata"); } // !IsGeneric does not need to be in the key, because it determines how the data is // fetched (do we need to create a new, dynamic instance?), but not what is fetched. TableMetaDataKey key = new TableMetaDataKey( Plugin, Factory, connectionString, BareTableName, TableOwner, DataContract ); CacheHits++; SyncCacheHits++; return(store.GetOrAdd(key, k => { CacheHits--; CacheMisses++; SyncCacheHits--; SyncCacheMisses++; return LoadTableMetaData(IsGeneric, k, Mighty, connection); })); }
internal IEnumerable <dynamic> Get( bool IsGeneric, PluginBase Plugin, DbProviderFactory Factory, string ConnectionString, string BareTableName, string TableOwner, DataContract DataContract, object Mighty ) { // !IsGeneric does not need to be in the key, because it determines how the data is // fetched (do we need to create a new, dynamic instance?), but not what is fetched. TableMetaDataKey key = new TableMetaDataKey( Plugin, Factory, ConnectionString, BareTableName, TableOwner, DataContract ); IEnumerable <dynamic> value; if (store.TryGetValue(key, out value)) { CacheHits++; } else { CacheMisses++; value = LoadTableMetaData(IsGeneric, key, Mighty); store.Add(key, value); } return(value); }
/// <summary> /// We drive creating new objects by the table meta-data list, but we only want to add columns which are actually /// specified for this instance of Mighty /// </summary> /// <param name="key">The info needed to create the meta-data</param> /// <param name="tableMetaData">The table meta-data</param> /// <returns></returns> private IEnumerable <dynamic> FilterTableMetaData(TableMetaDataKey key, IEnumerable <dynamic> tableMetaData) { foreach (var columnInfo in tableMetaData) { columnInfo.IS_MIGHTY_COLUMN = key.DataContract.IsMightyColumn(columnInfo.COLUMN_NAME); } return(tableMetaData); }
private IEnumerable <dynamic> LoadTableMetaData(bool isGeneric, TableMetaDataKey key, object Mighty) { var sql = key.Plugin.BuildTableMetaDataQuery(key.BareTableName, key.TableOwner); IEnumerable <dynamic> unprocessedMetaData; dynamic db = Mighty; if (isGeneric) { // we need a dynamic query, so on the generic version we create a new dynamic DB object with the same connection info db = new MightyOrm(connectionProvider: new PresetsConnectionProvider(key.ConnectionString, key.Factory, key.Plugin.GetType())); } unprocessedMetaData = (IEnumerable <dynamic>)db.Query(sql, key.BareTableName, key.TableOwner); var postProcessedMetaData = key.Plugin.PostProcessTableMetaData(unprocessedMetaData); return(FilterTableMetaData(key, postProcessedMetaData)); }
private IEnumerable <dynamic> LoadTableMetaData(bool isGeneric, TableMetaDataKey key, dynamic Mighty, DbConnection connection) { var sql = key.Plugin.BuildTableMetaDataQuery(key.BareTableName, key.TableOwner); IEnumerable <dynamic> unprocessedMetaData; dynamic db = Mighty; if (isGeneric) { // we need a dynamic query, so on the generic version we create a new dynamic DB object with the same connection info db = new MightyOrm(connectionProvider: new PresetsConnectionProvider(connection == null ? key.ConnectionString : null, key.Factory, key.Plugin.GetType())); } unprocessedMetaData = (IEnumerable <dynamic>)db.Query(sql, connection, key.BareTableName, key.TableOwner); var postProcessedMetaData = key.Plugin.PostProcessTableMetaData(unprocessedMetaData); if (postProcessedMetaData.Count == 0) { throw new InvalidOperationException($"Cannot find any meta-data for table {(key.TableOwner == null ? "" : $"{key.TableOwner }.")}{key.BareTableName} in database");
internal IEnumerable <dynamic> Get( bool IsGeneric, PluginBase Plugin, DbProviderFactory Factory, string ConnectionString, string BareTableName, string TableOwner, DataContract DataContract, object Mighty ) { // !IsGeneric does not need to be in the key, because it determines how the data is // fetched (do we need to create a new, dynamic instance?), but not what is fetched. TableMetaDataKey key = new TableMetaDataKey( Plugin, Factory, ConnectionString, BareTableName, TableOwner, DataContract ); CacheHits++; return(store.GetOrAdd(key, k => { CacheHits--; CacheMisses++; return LoadTableMetaData(IsGeneric, k, Mighty); })); }