protected IDbCommand CreateRetrievalPreparedStatement(ITypeFieldValueList keyValueList, ITransaction tx) { Type targetType = keyValueList.Type; EntityInfo entityInfo = CacheManager.GetEntityInfo(targetType); string query = entityInfo.GetLoadQuery(DbLayer); IDbCommand cmd; try { cmd = tx.CreateCommand(); cmd.CommandText = query; } catch (Exception ex) { string message = String.Format("SQL Exception while trying create command for sql {0}", query); throw new CommandCreationException(message, ex); } ICollection <IColumn> keys = entityInfo.GetKeys(); StringBuilder logSb = new StringBuilder(); bool showQuery = Config.ShowQueries; if (showQuery) { logSb.Append(query); } int i = 0; foreach (IColumn key in keys) { Object fieldValue = keyValueList.GetFieldValue(key.AttributeName).Value; if (showQuery) { logSb.Append(" ,").Append(key.ColumnName).Append("=").Append(fieldValue); } DbLayer.DataManipulate().SetToPreparedStatement(cmd, fieldValue, ++i, key); } if (showQuery) { Logger.GetLogger(Config.LoggerName).Debug(logSb.ToString()); } if (Config.EnableStatistics) { Statistics.RegisterSelect(targetType); } return(cmd); }
private void ProcessQuery(StringBuilder sb, QuerySegment segment, QueryBuildInfo buildInfo, IDbLayer dbLayer) { buildInfo = dbLayer.DataManipulate().ProcessQuery(buildInfo, segment.Query.Structure); sb.Append(" ( "); sb.Append(buildInfo.ExecInfo.Sql); sb.Append(" ) "); }
public string CreateSql(IDbLayer dbLayer, QueryBuildInfo buildInfo) { String alias = "union_src_" + Guid.NewGuid().ToString().Substring(0, 5); var sqlBuilder = new StringBuilder(); sqlBuilder.Append("("); for (int i = 0, queriesLength = Queries.Length; i < queriesLength; i++) { ISelectionQuery query = Queries[i]; QueryBuildInfo result = dbLayer.DataManipulate().ProcessQuery(buildInfo, query.Structure); if (i > 0) { sqlBuilder.Append(" UNION "); if (All) { sqlBuilder.Append(" ALL "); } } sqlBuilder.Append(result.ExecInfo.Sql + " union_src_" + i); } sqlBuilder.Append(") ").Append(alias); buildInfo.AddUnionAlias(alias); return(sqlBuilder.ToString()); }
public string CreateSql(IDbLayer dbLayer, QueryBuildInfo buildInfo) { QueryBuildInfo result = dbLayer.DataManipulate().ProcessQuery(buildInfo, Query.Structure); string sql = "(" + result.ExecInfo.Sql + ")"; if (!string.IsNullOrEmpty(Alias)) { sql = sql + " as " + Alias; buildInfo.AddQueryAlias(Alias, Query); } return(sql); }
public DbGate(int dbType) { _config = new DbGateConfig(); _statistics = new DbGateStatistics(); InitializeDefaults(); IDbLayer dbLayer = LayerFactory.CreateLayer(dbType, _config); CacheManager.Init(_config); _persistRetrievalLayer = new PersistRetrievalLayer(dbLayer, _statistics, _config); _dataMigrationLayer = new DataMigrationLayer(dbLayer, _statistics, _config); dbLayer.DataManipulate(); }
public string GetRelationObjectLoad(IDbLayer dbLayer, IRelation relation) { string queryId = relation.RelationShipName + "_" + relation.RelatedObjectType.FullName; string query = GetQuery(queryId); if (query == null) { query = dbLayer.DataManipulate().CreateRelatedObjectsLoadQuery(relation); SetQuery(queryId, query); } if (query == null) { throw new QueryBuildingException(String.Format("Child loading Query building failed for table {0} class {1} child object type {2}", TableInfo, EntityType.FullName, relation.RelatedObjectType.FullName)); } return(query); }
public string GetDeleteQuery(IDbLayer dbLayer) { const string queryId = "DELETE"; string query = GetQuery(queryId); if (query == null) { PopulateRelationColumns(); query = dbLayer.DataManipulate().CreateDeleteQuery(TableInfo.TableName, Columns); SetQuery(queryId, query); } if (query == null) { throw new QueryBuildingException(String.Format("Delete Query building failed for table {0} class {1}", TableInfo, EntityType.FullName)); } return(query); }
public string CreateSql(IDbLayer dbLayer, QueryBuildInfo buildInfo) { ISegment rootSegment = Expr.RootSegment; switch (rootSegment.SegmentType) { case SegmentType.Group: return(_processor.GetGroupFunction((GroupFunctionSegment)rootSegment, true, buildInfo)); case SegmentType.Field: return(_processor.GetFieldName((FieldSegment)rootSegment, true, buildInfo)); case SegmentType.Query: var querySegment = (QuerySegment)rootSegment; buildInfo = dbLayer.DataManipulate().ProcessQuery(buildInfo, querySegment.Query.Structure); return("(" + buildInfo.ExecInfo.Sql + ") as " + querySegment.Alias); } return(null); }