public void CacheSingleTask(ICacheableTask cacheableTask, ExternalDatabaseServer queryCachingServer) { //if it is already cached don't inception cache var sql = Tasks[cacheableTask].CountSQL; if (sql.Trim().StartsWith(CachedAggregateConfigurationResultsManager.CachingPrefix)) { return; } var manager = new CachedAggregateConfigurationResultsManager(queryCachingServer); var explicitTypes = new List <DatabaseColumnRequest>(); AggregateConfiguration configuration = cacheableTask.GetAggregateConfiguration(); try { //the identifier column that we read from ColumnInfo identifierColumnInfo = configuration.AggregateDimensions.Single(c => c.IsExtractionIdentifier).ColumnInfo; var destinationDataType = GetDestinationType(identifierColumnInfo.Data_type, cacheableTask, queryCachingServer); explicitTypes.Add(new DatabaseColumnRequest(identifierColumnInfo.GetRuntimeName(), destinationDataType)); } catch (Exception e) { throw new Exception("Error occurred trying to find the data type of the identifier column when attempting to submit the result data table to the cache", e); } CacheCommitArguments args = cacheableTask.GetCacheArguments(sql, Tasks[cacheableTask].Identifiers, explicitTypes.ToArray()); manager.CommitResults(args); }
public void CacheSingleTask(ICacheableTask cacheableTask, ExternalDatabaseServer queryCachingServer) { //if it is already cached don't inception cache var sql = Tasks[cacheableTask].CountSQL; if (sql.Trim().StartsWith(CachedAggregateConfigurationResultsManager.CachingPrefix)) { return; } var manager = new CachedAggregateConfigurationResultsManager(queryCachingServer); var explicitTypes = new List <DatabaseColumnRequest>(); AggregateConfiguration configuration = cacheableTask.GetAggregateConfiguration(); try { //the identifier column that we read from var identifiers = configuration.AggregateDimensions.Where(c => c.IsExtractionIdentifier).ToArray(); if (identifiers.Length != 1) { throw new Exception(string.Format( "There were {0} columns in the configuration marked IsExtractionIdentifier:{1}", identifiers.Length, string.Join(",", identifiers.Select(i => i.GetRuntimeName())))); } var identifierDimension = identifiers[0]; ColumnInfo identifierColumnInfo = identifierDimension.ColumnInfo; var destinationDataType = GetDestinationType(identifierColumnInfo.Data_type, cacheableTask, queryCachingServer); explicitTypes.Add(new DatabaseColumnRequest(identifierDimension.GetRuntimeName(), destinationDataType)); //make other non transform Types have explicit values foreach (AggregateDimension d in configuration.AggregateDimensions) { if (d != identifierDimension) { //if the user has not changed the SelectSQL and the SelectSQL of the original column is not a transform if (d.ExtractionInformation.SelectSQL.Equals(d.SelectSQL) && !d.ExtractionInformation.IsProperTransform()) { //then use the origin datatype explicitTypes.Add(new DatabaseColumnRequest(d.GetRuntimeName(), GetDestinationType(d.ExtractionInformation.ColumnInfo.Data_type, cacheableTask, queryCachingServer))); } } } } catch (Exception e) { throw new Exception("Error occurred trying to find the data type of the identifier column when attempting to submit the result data table to the cache", e); } CacheCommitArguments args = cacheableTask.GetCacheArguments(sql, Tasks[cacheableTask].Identifiers, explicitTypes.ToArray()); manager.CommitResults(args); }
public void CommitResults(CacheCommitArguments arguments) { var configuration = arguments.Configuration; var operation = arguments.Operation; DeleteCacheEntryIfAny(configuration, operation); //Do not change Types of source columns unless there is an explicit override arguments.Results.SetDoNotReType(true); using (var con = _server.GetConnection()) { con.Open(); string nameWeWillGiveTableInCache = operation + "_AggregateConfiguration" + configuration.ID; //either it has no name or it already has name we want so its ok arguments.Results.TableName = nameWeWillGiveTableInCache; //add explicit types var tbl = _database.ExpectTable(nameWeWillGiveTableInCache); if (tbl.Exists()) { tbl.Drop(); } tbl = _database.CreateTable(nameWeWillGiveTableInCache, arguments.Results, arguments.ExplicitColumns); if (!tbl.Exists()) { throw new Exception("Cache table did not exist even after CreateTable completed without error!"); } var cmdCreateNew = DatabaseCommandHelper.GetCommand( "INSERT INTO CachedAggregateConfigurationResults (Committer,AggregateConfiguration_ID,SqlExecuted,Operation,TableName) Values (@Committer,@AggregateConfiguration_ID,@SqlExecuted,@Operation,@TableName)", con); cmdCreateNew.Parameters.Add(DatabaseCommandHelper.GetParameter("@Committer", cmdCreateNew)); cmdCreateNew.Parameters["@Committer"].Value = Environment.UserName; cmdCreateNew.Parameters.Add(DatabaseCommandHelper.GetParameter("@AggregateConfiguration_ID", cmdCreateNew)); cmdCreateNew.Parameters["@AggregateConfiguration_ID"].Value = configuration.ID; cmdCreateNew.Parameters.Add(DatabaseCommandHelper.GetParameter("@SqlExecuted", cmdCreateNew)); cmdCreateNew.Parameters["@SqlExecuted"].Value = arguments.SQL.Trim(); cmdCreateNew.Parameters.Add(DatabaseCommandHelper.GetParameter("@Operation", cmdCreateNew)); cmdCreateNew.Parameters["@Operation"].Value = operation.ToString(); cmdCreateNew.Parameters.Add(DatabaseCommandHelper.GetParameter("@TableName", cmdCreateNew)); cmdCreateNew.Parameters["@TableName"].Value = tbl.GetRuntimeName(); cmdCreateNew.ExecuteNonQuery(); arguments.CommitTableDataCompleted(tbl); } }
public void CommitResults(CacheCommitArguments arguments) { var configuration = arguments.Configuration; var operation = arguments.Operation; DeleteCacheEntryIfAny(configuration, operation); //Do not change Types of source columns unless there is an explicit override arguments.Results.SetDoNotReType(true); using (var con = _server.GetConnection()) { con.Open(); string nameWeWillGiveTableInCache = operation + "_AggregateConfiguration" + configuration.ID; //either it has no name or it already has name we want so its ok arguments.Results.TableName = nameWeWillGiveTableInCache; //add explicit types var tbl = _database.ExpectTable(nameWeWillGiveTableInCache); if (tbl.Exists()) { tbl.Drop(); } tbl = _database.CreateTable(nameWeWillGiveTableInCache, arguments.Results, arguments.ExplicitColumns); if (!tbl.Exists()) { throw new Exception("Cache table did not exist even after CreateTable completed without error!"); } var mgrTable = _database.ExpectTable(ResultsManagerTable); mgrTable.Insert(new Dictionary <string, object>() { { "Committer", Environment.UserName }, { "AggregateConfiguration_ID", configuration.ID }, { "SqlExecuted", arguments.SQL.Trim() }, { "Operation", operation.ToString() }, { "TableName", tbl.GetRuntimeName() }, }); arguments.CommitTableDataCompleted(tbl); } }