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); }
/// <summary> /// Translates the <paramref name="data_type"/> which was read from <paramref name="cacheableTask"/> into an appropriate type /// that can be written into the tables referenced by <paramref name="queryCachingServer"/>. /// </summary> /// <param name="data_type">The datatype you want translated e.g. varchar2(10) (oracle syntax)</param> /// <param name="cacheableTask">Where the datatype was read from e.g. Oracle</param> /// <param name="queryCachingServer">Where the datatype is going to be stored e.g. Sql Server</param> /// <returns></returns> private string GetDestinationType(string data_type, ICacheableTask cacheableTask, ExternalDatabaseServer queryCachingServer) { var sourceSyntax = cacheableTask.GetDataAccessPoints().Single().GetQuerySyntaxHelper(); var destinationSyntax = queryCachingServer.GetQuerySyntaxHelper(); //if we have a change in syntax e.g. read from Oracle write to Sql Server if (sourceSyntax.DatabaseType != destinationSyntax.DatabaseType) { return(sourceSyntax.TypeTranslater.TranslateSQLDBType(data_type, destinationSyntax.TypeTranslater)); } return(data_type); }
/// <summary> /// Translates the <paramref name="data_type"/> which was read from <paramref name="cacheableTask"/> into an appropriate type /// that can be written into the tables referenced by <paramref name="queryCachingServer"/>. /// </summary> /// <param name="data_type">The datatype you want translated e.g. varchar2(10) (oracle syntax)</param> /// <param name="cacheableTask">Where the datatype was read from e.g. Oracle</param> /// <param name="queryCachingServer">Where the datatype is going to be stored e.g. Sql Server</param> /// <returns></returns> private string GetDestinationType(string data_type, ICacheableTask cacheableTask, ExternalDatabaseServer queryCachingServer) { var accessPoints = cacheableTask.GetDataAccessPoints(); var server = DataAccessPortal.GetInstance().ExpectDistinctServer(accessPoints, DataAccessContext.DataExport, false); var sourceSyntax = server.GetQuerySyntaxHelper(); var destinationSyntax = queryCachingServer.GetQuerySyntaxHelper(); //if we have a change in syntax e.g. read from Oracle write to Sql Server if (sourceSyntax.DatabaseType != destinationSyntax.DatabaseType) { return(sourceSyntax.TypeTranslater.TranslateSQLDBType(data_type, destinationSyntax.TypeTranslater)); } return(data_type); }