internal CSList(CSSchema schema) { _schema = schema; if (!string.IsNullOrEmpty(_schema.DefaultSortExpression)) OrderBy = _schema.DefaultSortExpression; }
internal CSList(CSSchema schema) { _schema = schema; if (!string.IsNullOrEmpty(_schema.DefaultSortExpression)) { OrderBy = _schema.DefaultSortExpression; } }
private void BeforeDeserializing(StreamingContext context) { Schema = CSSchema.Get(typeof(TObjectType)); if (!string.IsNullOrEmpty(Schema.DefaultSortExpression)) { OrderBy = Schema.DefaultSortExpression; } }
private void Initialize() { if (_schema == null) { _schema = CSSchema.Get(GetType()); } _dataState = CSObjectDataState.New; _fieldData = new CSFieldValueCollection(this); }
private static object GetScalar(string fieldName, string tableAlias, CSAggregate aggregate, CSFilter queryFilter, string orderBy) { CSSchema schema = CSSchema.Get(typeof(T)); if (tableAlias == null) { tableAlias = CSNameGenerator.NextTableAlias; } if (orderBy == null) { orderBy = ""; } string aggregateExpr = null; int maxRows = 0; switch (aggregate) { case CSAggregate.None: aggregateExpr = "{0}"; maxRows = 1; break; case CSAggregate.Sum: aggregateExpr = "sum({0})"; break; case CSAggregate.SumDistinct: aggregateExpr = "sum(distinct {0})"; break; case CSAggregate.Count: aggregateExpr = "count(*)"; break; case CSAggregate.CountDistinct: aggregateExpr = "count(distinct {0})"; break; case CSAggregate.Avg: aggregateExpr = "avg({0})"; break; case CSAggregate.AvgDistinct: aggregateExpr = "avg(distinct {0})"; break; case CSAggregate.Max: aggregateExpr = "max({0})"; break; case CSAggregate.Min: aggregateExpr = "min({0})"; break; } CSJoinList joins = new CSJoinList(); if (fieldName != "*") { fieldName = CSExpressionParser.ParseFilter(fieldName, schema, tableAlias, joins); } string whereFilter = CSExpressionParser.ParseFilter(queryFilter.Expression, schema, tableAlias, joins); orderBy = CSExpressionParser.ParseOrderBy(orderBy, schema, tableAlias, joins); string sqlQuery = schema.DB.BuildSelectSQL(schema.TableName, tableAlias, new[] { String.Format(aggregateExpr, fieldName) }, null, joins.BuildJoinExpressions(), whereFilter, orderBy, 1, maxRows, false, false); return(schema.DB.GetScalar(sqlQuery, queryFilter.Parameters)); }
public CSJoin(CSRelation relation, string sourceAlias) { Type = CSJoinType.Left; _leftSchema = relation.Schema; _rightSchema = relation.ForeignSchema; _leftAlias = sourceAlias; _rightAlias = CSNameGenerator.NextTableAlias; LeftColumn = relation.LocalKey; RightColumn = relation.ForeignKey; }
internal CSSchemaField(CSSchemaColumn schemaColumn, CSSchema schema) { _schema = schema; _mappedColumn = schemaColumn; //if (schemaColumn.DataType == typeof(byte[])) // _lazy = true; schemaColumn.MappedField = this; _fieldType = MappedColumn.DataType; _realType = _fieldType.Inspector().RealType; }
internal CSSchemaField(CSSchemaColumn schemaColumn , CSSchema schema) { _schema = schema; _mappedColumn = schemaColumn; //if (schemaColumn.DataType == typeof(byte[])) // _lazy = true; schemaColumn.MappedField = this; _fieldType = MappedColumn.DataType; _realType = _fieldType.Inspector().RealType; }
internal static string ParseOrderBy(string expression, CSSchema schema, string tableAlias, CSJoinList joinList) { //joinList = new CSJoinList(); if (expression.Trim().Length < 1) { return(expression); } string parsedExpression = ""; string[] terms = expression.Split(','); foreach (string term in terms) { if (term.Length < 1) { continue; } bool ascending = true; string fieldName = term; if (term.EndsWith("-")) { ascending = false; } if (term.EndsWith("+") || term.EndsWith("-")) { fieldName = term.Substring(0, term.Length - 1); } if (parsedExpression.Length > 1) { parsedExpression += ","; } parsedExpression += ParseFilter(fieldName, schema, tableAlias, joinList); if (!ascending) { parsedExpression += " DESC"; } } return(parsedExpression); }
internal static string Parse(CSSchema schema, string input, string tableAlias, CSJoinList joins) { if (input == "") { return(input); } List <Token> tokens = PreParse(input); QueryExpression rootQuery = new QueryExpression(schema, tableAlias); rootQuery.Joins = joins; QueryExpression finalQuery = Parse(rootQuery, tokens, 0, tokens.Count); return(finalQuery.Expression); }
internal static CSSchema Get(Type objectType) { if (!objectType.GetTypeInfo().IsSubclassOf(typeof(CSObject))) { throw new CSException("CSSchema.Get() called with type not derived from CSObject"); } lock (_staticLock) { CSSchema schema; if (!_schemaMap.TryGetValue(objectType, out schema)) { schema = new CSSchema(objectType); _schemaMap[objectType] = schema; schema.CreateRelations(); } return(schema); } }
public QueryExpression(CSSchema schema, string tableAlias) { Table = new CSTable(schema, tableAlias); }
public QueryExpression(CSSchema schema) { Table = new CSTable(schema); }
public static void ChangeTableMapping(Type type, string tableName, string contextName) { CSSchema.ChangeMapTo(type, tableName, contextName); }
internal CSRelation(CSSchema schema, RelationAttribute att) { _schema = schema; Attribute = att; }
internal CSSchemaField(PropertyInfo propInfo , CSSchema schema) { _propertyInfo = propInfo; _schema = schema; _fieldType = _propertyInfo.PropertyType; _realType = _fieldType.Inspector().RealType; RelationAttribute attRelation = (RelationAttribute) Attribute.GetCustomAttribute(propInfo,typeof(RelationAttribute),true); _prefetch = propInfo.IsDefined(typeof(PrefetchAttribute), true); if (attRelation != null) { _relation = new CSRelation(schema,attRelation); return; } _lazy = propInfo.IsDefined(typeof(LazyAttribute) , true); _noCreate = propInfo.IsDefined(typeof(NoCreateAttribute) , true); _trim = propInfo.IsDefined(typeof(TrimAttribute), true); _optimisticLock = propInfo.IsDefined(typeof(OptimisticLockAttribute), true); _clientGenerated = propInfo.IsDefined(typeof(ClientGeneratedAttribute), true); _serverGenerated = propInfo.IsDefined(typeof(ServerGeneratedAttribute), true); _notMapped = propInfo.IsDefined(typeof (NotMappedAttribute), true); MapToAttribute attMapTo = (MapToAttribute) Attribute.GetCustomAttribute(propInfo,typeof(MapToAttribute),true); NullValueAttribute attNull = (NullValueAttribute) Attribute.GetCustomAttribute(propInfo,typeof(NullValueAttribute),true); IdentityAttribute attIdentity = (IdentityAttribute)Attribute.GetCustomAttribute(propInfo, typeof(IdentityAttribute), true); if (!_notMapped) { if (CSConfig.ColumnMappingOverrideMap.ContainsValue(propInfo.DeclaringType.Name + ":" + propInfo.Name)) _mappedColumn = schema.Columns[ CSConfig.ColumnMappingOverrideMap[propInfo.DeclaringType.Name + ":" + propInfo.Name]]; else if (attMapTo != null) _mappedColumn = schema.Columns[attMapTo.Name]; else _mappedColumn = schema.Columns[propInfo.Name]; if (_mappedColumn != null) _mappedColumn.MappedField = this; } SequenceAttribute sequenceAttribute = (SequenceAttribute) Attribute.GetCustomAttribute(propInfo,typeof(SequenceAttribute), true); if (sequenceAttribute != null && _schema.DB.SupportsSequences) { _sequenceName = sequenceAttribute.SequenceName; if (_mappedColumn != null && sequenceAttribute.Identity) { _mappedColumn.Identity = true; _schema.IdentityColumn = _mappedColumn; } } if (attIdentity != null) { if (_mappedColumn != null) { _mappedColumn.Identity = true; _schema.IdentityColumn = _mappedColumn; } } if (attNull != null) { _nullValue = attNull.NullValue; } else { Type fieldType = FieldType; if (fieldType == typeof(string)) _nullValue = String.Empty; else if (fieldType.IsValueType) _nullValue = Activator.CreateInstance(fieldType); } if (_mappedColumn != null && _mappedColumn.ReadOnly) { if (_propertyInfo.CanWrite) throw new CSException("Property [" + Name + "] for class [" + _schema.ClassType.Name + "] should be read-only"); } }
internal CSTable(CSSchema schema, string tableAlias) { Schema = schema; TableAlias = tableAlias; }
internal static string ParseFilter(string expressionText, CSSchema schema, string tableAlias, CSJoinList joins) { return(Parse(schema, expressionText, tableAlias, joins)); }
internal CSTable(CSSchema schema) { Schema = schema; TableName = schema.TableName; TableAlias = CSNameGenerator.NextTableAlias; }
internal CSTransaction(CSSchema schema, IsolationLevel isolationLevel) { _database = schema.DB; _database.BeginTransaction(isolationLevel); }
internal static string ParseOrderBy(string expression, CSSchema schema, string tableAlias, CSJoinList joinList) { //joinList = new CSJoinList(); if (expression.Trim().Length < 1) return expression; string parsedExpression = ""; string[] terms = expression.Split(','); foreach (string term in terms) { if (term.Length < 1) continue; bool ascending = true; string fieldName = term; if (term.EndsWith("-")) ascending = false; if (term.EndsWith("+") || term.EndsWith("-")) fieldName = term.Substring(0, term.Length - 1); if (parsedExpression.Length > 1) parsedExpression += ","; parsedExpression += ParseFilter(fieldName, schema, tableAlias, joinList); if (!ascending) parsedExpression += " DESC"; } return parsedExpression; }
public CSList() : base(CSSchema.Get(typeof(TObjectType))) { }
internal CSSchemaField(PropertyInfo propInfo, CSSchema schema) { _propertyInfo = propInfo; _schema = schema; _fieldType = _propertyInfo.PropertyType; _realType = _fieldType.Inspector().RealType; RelationAttribute attRelation = propInfo.GetCustomAttribute <RelationAttribute>(true); _prefetch = propInfo.IsDefined(typeof(PrefetchAttribute), true); if (attRelation != null) { _relation = new CSRelation(schema, attRelation); return; } _lazy = propInfo.IsDefined(typeof(LazyAttribute), true); _noCreate = propInfo.IsDefined(typeof(NoCreateAttribute), true); _trim = propInfo.IsDefined(typeof(TrimAttribute), true); _optimisticLock = propInfo.IsDefined(typeof(OptimisticLockAttribute), true); _clientGenerated = propInfo.IsDefined(typeof(ClientGeneratedAttribute), true); _serverGenerated = propInfo.IsDefined(typeof(ServerGeneratedAttribute), true); _notMapped = propInfo.IsDefined(typeof(NotMappedAttribute), true); var mapToAttribute = propInfo.GetCustomAttribute <MapToAttribute>(true); var nullValueAttribute = propInfo.GetCustomAttribute <NullValueAttribute>(true); var identityAttribute = propInfo.GetCustomAttribute <IdentityAttribute>(true); if (!_notMapped) { if (CSConfig.ColumnMappingOverrideMap.ContainsValue(propInfo.DeclaringType.Name + ":" + propInfo.Name)) { _mappedColumn = schema.Columns[ CSConfig.ColumnMappingOverrideMap[propInfo.DeclaringType.Name + ":" + propInfo.Name]]; } else if (mapToAttribute != null) { _mappedColumn = schema.Columns[mapToAttribute.Name]; } else { _mappedColumn = schema.Columns[propInfo.Name]; } if (_mappedColumn != null) { _mappedColumn.MappedField = this; } } var sequenceAttribute = propInfo.GetCustomAttribute <SequenceAttribute>(true); if (sequenceAttribute != null && _schema.DB.SupportsSequences) { _sequenceName = sequenceAttribute.SequenceName; if (_mappedColumn != null && sequenceAttribute.Identity) { _mappedColumn.Identity = true; _schema.IdentityColumn = _mappedColumn; } } if (identityAttribute != null) { if (_mappedColumn != null) { _mappedColumn.Identity = true; _schema.IdentityColumn = _mappedColumn; } } if (nullValueAttribute != null) { _nullValue = nullValueAttribute.NullValue; } else { Type fieldType = FieldType; if (fieldType == typeof(string)) { _nullValue = String.Empty; } else if (fieldType.GetTypeInfo().IsValueType) { _nullValue = Activator.CreateInstance(fieldType); } } if (_mappedColumn != null && _mappedColumn.ReadOnly) { if (_propertyInfo.CanWrite) { throw new CSException("Property [" + Name + "] for class [" + _schema.ClassType.Name + "] should be read-only"); } } }
internal static CSSchema Get(Type objectType) { if (!objectType.IsSubclassOf(typeof(CSObject))) throw new CSException("CSSchema.Get() called with type not derived from CSObject"); lock (_staticLock) { CSSchema schema; if (objectType.Namespace.Equals("Vici.CoolStorage.Generated", StringComparison.CurrentCultureIgnoreCase)) { objectType = objectType.BaseType; } if (!_schemaMap.TryGetValue(objectType, out schema)) { schema = new CSSchema(objectType); _schemaMap[objectType] = schema; //TODO: DAE 2010-09-30 - Modificar para soportar claves compuestas schema.CreateRelations(); } return schema; } }
internal static string Parse(CSSchema schema, string input, string tableAlias, CSJoinList joins) { if (input == "") return input; List<Token> tokens = PreParse(input); QueryExpression rootQuery = new QueryExpression(schema,tableAlias); rootQuery.Joins = joins; QueryExpression finalQuery = Parse(rootQuery, tokens, 0, tokens.Count); return finalQuery.Expression; }
internal CSTransaction(CSSchema schema) { _database = schema.DB; _database.BeginTransaction(); }
internal static CSSchema Get(Type objectType) { if (!objectType.IsSubclassOf(typeof(CSObject))) throw new CSException("CSSchema.Get() called with type not derived from CSObject"); lock (_staticLock) { CSSchema schema; if (!_schemaMap.TryGetValue(objectType, out schema)) { schema = new CSSchema(objectType); _schemaMap[objectType] = schema; schema.CreateRelations(); } return schema; } }
internal static string ParseFilter(string expressionText, CSSchema schema, string tableAlias, CSJoinList joins) { return Parse(schema, expressionText, tableAlias, joins); }