Ejemplo n.º 1
0
        protected override ITableSource VisitEntitySource(ITableSource node)
        {
            if (_repo == null)
            {
                //如果 _repo 传入 null,查找最左边的实体数据源。
                _resultMatched = true;
                _result = node;
            }
            else if (node.EntityRepository == _repo)
            {
                //如果还没有匹配的实体源,则设置结果为第一个匹配的实体源。
                if (_result == null)
                {
                    _result = node;
                }

                //如果同时还匹配了别名,那么整个搜索结束。
                if (node.Alias == _alias)
                {
                    _resultMatched = true;

                    //不论 node 是不是第一个匹配的实体源,都需要设置为结果。
                    _result = node;
                }
            }

            return node;
        }
Ejemplo n.º 2
0
        public override Node Interpret()
        {
            var ts = FindDescendant<SimpleTableSource>();
            if (ts != null)
            {
                this.specificTableSource = ts;
                return base.Interpret();
            }

            var fts = FindDescendant<FunctionTableSource>();
            if (fts != null)
            {
                this.specificTableSource = fts;
                return base.Interpret();
            }

            var vts = FindDescendant<VariableTableSource>();
            if (vts != null)
            {
                this.specificTableSource = vts;
                return base.Interpret();
            }

            var sts = FindDescendant<SubqueryTableSource>();
            if (sts != null)
            {
                this.specificTableSource = sts;
                return base.Interpret();
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 3
0
        public ITableSource Find(IRepository repo, string alias)
        {
            _repo = repo;
            _alias = alias;
            _result = null;
            _resultMatched = false;

            base.Visit(_source);

            return _result;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 为查询添加一个对应的约束条件,并以 And 与原条件进行连接。
        /// </summary>
        /// <param name="query">查询.</param>
        /// <param name="property">要约束的属性.</param>
        /// <param name="op">约束条件操作符.</param>
        /// <param name="value">对比的值。</param>
        /// <param name="propertySource">指定该属性所属的实体数据源。</param>
        /// <returns></returns>
        public static IQuery AddConstraint(this IQuery query, IManagedProperty property, PropertyOperator op, object value, ITableSource propertySource)
        {
            var f = QueryFactory.Instance;

            var propertyNode = propertySource.Column(property);

            var where = f.Constraint(propertyNode, op, value);
            if (query.Where == null)
            {
                query.Where = where;
            }
            else
            {
                query.Where = f.And(query.Where, where);
            }

            return query;
        }
Ejemplo n.º 5
0
        public void Parse(string filter, IQuery query)
        {
            _query = query;
            _mainTable = query.MainTable;
            _column = null;
            _comparison = null;
            _concat = null;
            _current = null;
            _f = QueryFactory.Instance;
            _bracketStack = new Stack<StackItem>();

            using (_reader = new StringReader(filter))
            {
                while (true)
                {
                    var part = this.ReadPart();
                    if (part == string.Empty) break;
                    this.DealPart(part);
                }
            }

            query.Where = _current;
        }
Ejemplo n.º 6
0
        protected override Expression VisitMember(MemberExpression m)
        {
            //只能访问属性
            var clrProperty = m.Member as PropertyInfo;

            if (clrProperty == null)
            {
                throw OperationNotSupported(m.Member);
            }
            var ownerExp = m.Expression;

            if (ownerExp == null)
            {
                throw OperationNotSupported(m.Member);
            }

            //exp 如果是: A 或者 A.B.C,都可以作为属性查询。
            var nodeType = ownerExp.NodeType;

            if (nodeType != ExpressionType.Parameter && nodeType != ExpressionType.MemberAccess)
            {
                throw OperationNotSupported(m.Member);
            }

            //如果是 A.B.C.Name,则先读取 A.B.C,记录最后一个引用实体类型 C;剩下 .Name 给本行后面的代码读取。
            VisitRefEntity(ownerExp);

            //属性的拥有类型对应的仓库。
            //获取当前正在查询的实体对应的仓库对象。如果是级联引用表达式,则使用最后一个实体即可。
            var ownerTable = _query.MainTable;
            var ownerRepo  = _repo;

            if (_lastJoinRefResult != null)
            {
                //如果已经有引用属性在列表中,说明上层使用了 A.B.C.Name 这样的语法。
                //这时,Name 应该是 C 这个实体的值属性。
                ownerRepo          = RepositoryFactoryHost.Factory.FindByEntity(_lastJoinRefResult.RefEntityType);
                ownerTable         = _lastJoinTable;
                _lastJoinRefResult = null;
                _lastJoinTable     = null;
            }

            //查询托管属性
            var mp = FindProperty(ownerRepo, clrProperty);

            if (mp == null)
            {
                throw OperationNotSupported("Linq 查询的属性必须是一个托管属性。");
            }
            if (mp is IListProperty)
            {
                throw OperationNotSupported("暂时不支持面向组合子对象的查询。");
            }
            if (mp is IRefEntityProperty)
            {
                //如果是引用属性,说明需要使用关联查询。
                var refProperty = mp as IRefEntityProperty;
                var refTable    = f.FindOrCreateJoinTable(_query, ownerTable, refProperty);

                //存储到字段中,最后的值属性会使用这个引用属性对应的引用实体类型来查找对应仓库。
                _lastJoinRefResult = refProperty;
                _lastJoinTable     = refTable;
                return(m);
            }

            //访问值属性
            VisitValueProperty(mp, ownerTable);

            return(m);
        }
Ejemplo n.º 7
0
        private static string CGetStructureKey(ITableSource table)
        {
            string key = String.Format("{0}#{1}#CGetStructure", table.Database.DatabaseName, table.FullName.ToString());

            return(key);
        }
 ITableSource ITableSourceComposite.CopySourceTable(ITableSource tableSource, IIndexSet indexSet)
 {
     return(CopySourceTable((TableSource)tableSource, indexSet));
 }
Ejemplo n.º 9
0
 public static void DropTable(this ITableSource table)
 {
     table.Database.DropObject(new TableStructure {
         FullName = table.FullName
     });
 }
Ejemplo n.º 10
0
 public static void ChangeSchema(this ITableSource table, string newschema)
 {
     table.Database.ChangeObjectSchema(new TableStructure {
         FullName = table.FullName
     }, newschema);
 }
Ejemplo n.º 11
0
        private void SetIndexSetForTable(ITableSource source, IIndexSet indexSet)
        {
            int sz = tableIndices.Count;
            for (int i = 0; i < sz; ++i) {
                if (visibleTables[i].TableId == source.TableId) {
                    tableIndices[i] = indexSet;
                    return;
                }
            }

            throw new Exception("Table source not found in this transaction.");
        }
Ejemplo n.º 12
0
        protected override Expression VisitMember(MemberExpression m)
        {
            //只能访问属性
            var clrProperty = m.Member as PropertyInfo;
            if (clrProperty == null) throw EntityQueryBuilder.OperationNotSupported(m.Member);
            var ownerExp = m.Expression;
            if (ownerExp == null) throw EntityQueryBuilder.OperationNotSupported(m.Member);

            //exp 如果是: A 或者 A.B.C,都可以作为属性查询。
            var nodeType = ownerExp.NodeType;
            if (nodeType != ExpressionType.Parameter && nodeType != ExpressionType.MemberAccess) throw EntityQueryBuilder.OperationNotSupported(m.Member);

            //如果是 A.B.C.Name,则先读取 A.B.C,记录最后一个引用实体类型 C;剩下 .Name 给本行后面的代码读取。
            VisitRefEntity(ownerExp);

            //属性的拥有类型对应的仓库。
            //获取当前正在查询的实体对应的仓库对象。如果是级联引用表达式,则使用最后一个实体即可。
            var ownerTable = _query.MainTable;
            var ownerRepo = _repo;
            if (_lastJoinRefResult != null)
            {
                //如果已经有引用属性在列表中,说明上层使用了 A.B.C.Name 这样的语法。
                //这时,Name 应该是 C 这个实体的值属性。
                ownerRepo = RepositoryFactoryHost.Factory.FindByEntity(_lastJoinRefResult.RefEntityType);
                ownerTable = _lastJoinTable;
                _lastJoinRefResult = null;
                _lastJoinTable = null;
            }

            //查询托管属性
            var mp = EntityQueryBuilder.FindProperty(ownerRepo, clrProperty);
            if (mp == null) throw EntityQueryBuilder.OperationNotSupported("Linq 查询的属性必须是一个托管属性。");
            if (mp is IRefEntityProperty)
            {
                //如果是引用属性,说明需要使用关联查询。
                var refProperty = mp as IRefEntityProperty;
                var refTable = f.FindOrCreateJoinTable(_query, ownerTable, refProperty);

                if (refProperty.Nullable)
                {
                    var column = ownerTable.Column(refProperty.RefIdProperty);
                    NullableRefConstraint = _reverseConstraint ?
                        f.Or(NullableRefConstraint, column.Equal(null as object)) :
                        f.And(NullableRefConstraint, column.NotEqual(null as object));
                }

                //存储到字段中,最后的值属性会使用这个引用属性对应的引用实体类型来查找对应仓库。
                _lastJoinRefResult = refProperty;
                _lastJoinTable = refTable;
                return m;
            }

            if (_visitRefProperties)
            {
                throw EntityQueryBuilder.OperationNotSupported(string.Format("不支持使用属性:{0}。这是因为它的拥有者是一个值属性,值属性只支持直接对比。", mp.Name));
            }

            //访问值属性
            PropertyOwnerTable = ownerTable;
            Property = mp;

            return m;
        }
Ejemplo n.º 13
0
 public static ISelectAll Star(this ITableSource table)
 {
     return(QueryFactory.Instance.SelectAll(table));
 }
Ejemplo n.º 14
0
        /// <summary>
        /// 如果提供的值是不可空的,则为查询添加一个对应的约束条件,并以 And 与原条件进行连接。
        /// </summary>
        /// <param name="query">查询.</param>
        /// <param name="property">要约束的属性.</param>
        /// <param name="op">约束条件操作符.</param>
        /// <param name="value">当 value 不可空时,才添加这个对比约束条件。</param>
        /// <param name="propertySource">指定该属性所属的实体数据源。</param>
        /// <returns></returns>
        public static IQuery AddConstraintIf(this IQuery query, IManagedProperty property, PropertyOperator op, object value, ITableSource propertySource)
        {
            if (DomainHelper.IsNotEmpty(value))
            {
                return AddConstraint(query, property, op, value, propertySource);
            }

            return query;
        }
Ejemplo n.º 15
0
 public static IJoin Join(this ISource left, ITableSource right, IConstraint condition, JoinType joinType = JoinType.Inner)
 {
     return(QueryFactory.Instance.Join(left, right, condition, joinType));
 }
Ejemplo n.º 16
0
 public TableAssignment(TKey key, ITableSource <TKey, TValue> source)
 {
     _key    = key;
     _source = source;
 }
Ejemplo n.º 17
0
        private SqlTableSource AddJoinTable(ITableSource fkTable, IRefProperty parentRef, ITableSource pkTable, ITableSource joinTo)
        {
            var f = QueryFactory.Instance;

            var joinType = parentRef.Nullable ? JoinType.LeftOuter : JoinType.Inner;
            var query = this as IQuery;
            query.From = f.Join(query.From, joinTo, f.Constraint(
                fkTable.Column(parentRef.RefIdProperty),
                pkTable.IdColumn
                ), joinType);

            var refTableSource = new SqlTableSource
            {
                ForeignKeyTable = fkTable,
                RefProperty = parentRef,
                PrimaryKeyTable = pkTable,
            };
            _allJoinTables.Add(refTableSource);

            return refTableSource;
        }
Ejemplo n.º 18
0
        //暂时去除
        ///// <summary>
        ///// 在查询对象中查找或者创建指定引用属性对应的连接表对象。
        ///// </summary>
        ///// <param name="propertyOwner">聚合子属性所在的实体对应的表。也是外键关系中主键表所在的表。</param>
        ///// <param name="childrenProperty">指定的聚合子属性。</param>
        ///// <returns></returns>
        //internal ITableSource FindOrCreateJoinTable(ITableSource propertyOwner, IListProperty childrenProperty)
        //{
        //    if (childrenProperty.HasManyType != HasManyType.Composition) throw new InvalidProgramException("只能对聚合子属性使用此方法。");
        //    //先找到这个关系对应的引用属性。
        //    var refEntityType = childrenProperty.ListEntityType;
        //    var refRepo = RepositoryFactoryHost.Factory.FindByEntity(refEntityType);
        //    var parentProperty = refRepo.FindParentPropertyInfo(true);
        //    var parentRef = (parentProperty.ManagedProperty as IRefProperty).RefIdProperty;
        //    var refTableSource = _allJoinTables.FirstOrDefault(
        //        ts => ts.RefProperty == parentRef && ts.PrimaryKeyTable == propertyOwner
        //        );
        //    if (refTableSource == null)
        //    {
        //        var f = QueryFactory.Instance;
        //        var fkTable = f.Table(refRepo, QueryGenerationContext.Get(this).NextTableAlias());
        //        refTableSource = AddJoinTable(fkTable, parentRef, propertyOwner, fkTable);
        //    }
        //    return refTableSource.ForeignKeyTable;
        //}
        /// <summary>
        /// 在查询对象中查找或者创建指定引用属性对应的连接表对象。
        /// </summary>
        /// <param name="propertyOwner">引用属性所在的实体对应的表。也是外键关系中外键列所在的表。</param>
        /// <param name="refProperty">指定的引用属性。</param>
        /// <returns></returns>
        internal ITableSource FindOrCreateJoinTable(ITableSource propertyOwner, IRefEntityProperty refProperty)
        {
            var refTableSource = _allJoinTables.FirstOrDefault(
                ts => ts.ForeignKeyTable == propertyOwner && ts.RefProperty == refProperty
                );
            if (refTableSource == null)
            {
                var f = QueryFactory.Instance;

                var refEntityType = refProperty.RefEntityType;
                var refRepo = RepositoryFactoryHost.Factory.FindByEntity(refEntityType);
                var pkTable = f.Table(refRepo, QueryGenerationContext.Get(this).NextTableAlias());

                refTableSource = AddJoinTable(propertyOwner, refProperty, pkTable, pkTable);
            }

            return refTableSource.PrimaryKeyTable;
        }
Ejemplo n.º 19
0
 public static IJoin Join(this ITableSource left, ITableSource right)
 {
     return QueryFactory.Instance.Join(left, right);
 }
Ejemplo n.º 20
0
 public static IJoin Join(this ISource left, ITableSource right, IRefProperty leftToRight)
 {
     return QueryFactory.Instance.Join(left, right, leftToRight);
 }
Ejemplo n.º 21
0
 public static IJoin Join(this ISource left, ITableSource right, IConstraint condition, JoinType joinType = JoinType.Inner)
 {
     return QueryFactory.Instance.Join(left, right, condition, joinType);
 }
Ejemplo n.º 22
0
 public Store(ITableSource <string, object> store, IParameterizedSource <string, IMember> members)
     : this(store, members, TypeDefaults.Default)
 {
 }
Ejemplo n.º 23
0
        internal IIndexSet GetIndexSetForTable(ITableSource tableSource)
        {
            var tableName = tableSource.TableInfo.TableName;
            IIndexSet indexSet;
            if (!tableIndices.TryGetValue(tableName, out indexSet))
                throw new Exception("Table source not found in this transaction.");

            return indexSet;
        }
Ejemplo n.º 24
0
        protected override Expression VisitMember(MemberExpression m)
        {
            //只能访问属性
            var clrProperty = m.Member as PropertyInfo;

            if (clrProperty == null)
            {
                throw EntityQueryBuilder.OperationNotSupported(m.Member);
            }
            var ownerExp = m.Expression;

            if (ownerExp == null)
            {
                throw EntityQueryBuilder.OperationNotSupported(m.Member);
            }

            //exp 如果是: A 或者 A.B.C,都可以作为属性查询。
            var nodeType = ownerExp.NodeType;

            if (nodeType != ExpressionType.Parameter && nodeType != ExpressionType.MemberAccess)
            {
                throw EntityQueryBuilder.OperationNotSupported(m.Member);
            }

            //如果是 A.B.C.Name,则先读取 A.B.C,记录最后一个引用实体类型 C;剩下 .Name 给本行后面的代码读取。
            VisitRefEntity(ownerExp);

            //属性的拥有类型对应的仓库。
            //获取当前正在查询的实体对应的仓库对象。如果是级联引用表达式,则使用最后一个实体即可。
            var ownerTable = _query.MainTable;
            var ownerRepo  = _repo;

            if (_lastJoinRefResult != null)
            {
                //如果已经有引用属性在列表中,说明上层使用了 A.B.C.Name 这样的语法。
                //这时,Name 应该是 C 这个实体的值属性。
                ownerRepo          = RepositoryFactoryHost.Factory.FindByEntity(_lastJoinRefResult.RefEntityType);
                ownerTable         = _lastJoinTable;
                _lastJoinRefResult = null;
                _lastJoinTable     = null;
            }

            //查询托管属性
            var mp = EntityQueryBuilder.FindProperty(ownerRepo, clrProperty);

            if (mp == null)
            {
                throw EntityQueryBuilder.OperationNotSupported("Linq 查询的属性必须是一个托管属性。");
            }
            if (mp is IRefEntityProperty)
            {
                //如果是引用属性,说明需要使用关联查询。
                var refProperty = mp as IRefEntityProperty;
                var refTable    = f.FindOrCreateJoinTable(_query, ownerTable, refProperty);

                if (refProperty.Nullable)
                {
                    var column = ownerTable.Column(refProperty.RefIdProperty);
                    NullableRefConstraint = _reverseConstraint ?
                                            f.Or(NullableRefConstraint, column.Equal(null as object)) :
                                            f.And(NullableRefConstraint, column.NotEqual(null as object));
                }

                //存储到字段中,最后的值属性会使用这个引用属性对应的引用实体类型来查找对应仓库。
                _lastJoinRefResult = refProperty;
                _lastJoinTable     = refTable;
                return(m);
            }

            if (_visitRefProperties)
            {
                throw EntityQueryBuilder.OperationNotSupported(string.Format("不支持使用属性:{0}。这是因为它的拥有者是一个值属性,值属性只支持直接对比。", mp.Name));
            }

            //访问值属性
            PropertyOwnerTable = ownerTable;
            Property           = mp;

            return(m);
        }
Ejemplo n.º 25
0
        internal void RemoveVisibleTable(ITableSource table)
        {
            if (Transaction.ReadOnly())
                throw new Exception("Transaction is Read-only.");

            var tableName = table.TableInfo.TableName;
            if (visibleTables.Remove(tableName)) {
                IIndexSet indexSet;
                if (!tableIndices.TryGetValue(tableName, out indexSet))
                    throw new InvalidOperationException("No index set was defined for table.");

                tableIndices.Remove(tableName);

                if (cleanupQueue == null)
                    cleanupQueue = new List<object>();

                cleanupQueue.Add(table);
                cleanupQueue.Add(indexSet);

                // Remove from the table cache
                tableCache.Remove(tableName);
            }
        }
Ejemplo n.º 26
0
 public static IJoin Join(this ISource left, ITableSource right, IRefProperty leftToRight)
 {
     return(QueryFactory.Instance.Join(left, right, leftToRight));
 }
Ejemplo n.º 27
0
        private void CopyTable(ITableSource tableSource, IIndexSet indexSet)
        {
            var tableInfo = tableSource.TableInfo;
            var tableName = tableInfo.TableName;

            if (visibleTables.ContainsKey(tableName))
                throw new ObjectNotFoundException(tableName);

            // Copy the table and add to the list of visible tables.
            var source = Composite.CopySourceTable(tableSource, indexSet);

            AddVisibleTable(source, source.CreateIndexSet());

            // Log in the journal that this transaction touched the table_id.
            int tableId = source.TableId;
            Transaction.OnTableCreated(tableId, tableName);

            Transaction.CreateNativeSequence(tableName);
        }
Ejemplo n.º 28
0
        private IMutableTable CreateTableAtCommit(ITableSource source)
        {
            // Create the table for this transaction.
            var table = source.CreateTableAtCommit(Transaction);

            accessedTables.Add(table);

            Transaction.Registry.RegisterEvent(new TableAccessEvent(source.TableId, source.TableInfo.TableName));

            return table;
        }
Ejemplo n.º 29
0
        private void SetIndexSetForTable(ITableSource source, IIndexSet indexSet)
        {
            var tableName = source.TableInfo.TableName;

            if (!visibleTables.ContainsKey(tableName))
                throw new Exception("Table source not found in this transaction.");

            tableIndices[tableName] = indexSet;
        }
Ejemplo n.º 30
0
 public Context(ITableSource <XmlReader, object> table, XmlReader key)
 {
     _table = table;
     _key   = key;
 }
 public Contents(ITableSource <TypeInfo, ContentAlteration> registrations, IContents contents)
 {
     _registrations = registrations;
     _contents      = contents;
 }
Ejemplo n.º 32
0
 public ActivationContext(ITableSource <string, object> source, Func <object> activator, IList list)
 {
     _source    = source;
     _activator = activator;
     _list      = list;
 }
 public MemberContents(ITableSource <MemberInfo, ContentAlteration> registrations, IMemberContents contents)
 {
     _registrations = registrations;
     _contents      = contents;
 }
Ejemplo n.º 34
0
 public static void RenameTable(this ITableSource table, string newname)
 {
     table.Database.RenameObject(new TableStructure {
         FullName = table.FullName
     }, newname);
 }
Ejemplo n.º 35
0
 internal bool TryGetVisibleTable(ObjectName tableName, out ITableSource source)
 => visibleTables.TryGetValue(tableName, out source);
Ejemplo n.º 36
0
 public static ITableStructure CGetStructure(this ITableSource table, Action guiCallback)
 {
     return(table.CGetStructure(PriorityLevel.Normal, false, guiCallback));
 }
Ejemplo n.º 37
0
 internal void SelectTable(ITableSource source)
 {
     lock (selectedTables) {
         selectedTables.Add(source);
     }
 }
Ejemplo n.º 38
0
        public static DataTable CGetListData(this ITableSource table, int maxrows, Action guiCallback)
        {
            string key = (table.Database.DatabaseName ?? "") + "#" + table.FullName.ToString() + "#CGetListData";

            return((DataTable)table.Connection.CacheGet(PriorityLevel.Low, true, key, () => DoGetListData(table.Connection, table.Database.DatabaseName, table.FullName, maxrows), guiCallback));
        }
Ejemplo n.º 39
0
 public GenericTabularDataView(IPhysicalConnection conn, string dbname, string query, string countQuery, string deleteQuery, object title, bool supportsFilteringAndSorting, bool isFullTableSelect, ITableSource tableSource, string preferedPer)
     : base(conn)
 {
     m_conn        = conn;
     m_query       = query;
     m_title       = title;
     m_dbname      = dbname;
     m_countQuery  = countQuery;
     m_deleteQuery = deleteQuery;
     m_supportsFilteringAndSorting = supportsFilteringAndSorting;
     m_isFullTableSelect           = isFullTableSelect;
     m_tableSource         = tableSource;
     m_preferedPerspective = preferedPer;
 }
 /// <summary>
 /// 构建过滤约束条件
 /// </summary>
 /// <param name="mainTable"></param>
 /// <param name="query"></param>
 /// <returns></returns>
 public IConstraint BuildConstraint(ITableSource mainTable, IQuery query)
 {
     return(this.BuildConstraintCore(mainTable, query));
 }
 /// <summary>
 /// 构建过滤约束条件
 /// </summary>
 /// <param name="mainTable"></param>
 /// <param name="query"></param>
 /// <returns></returns>
 protected abstract IConstraint BuildConstraintCore(ITableSource mainTable, IQuery query);
Ejemplo n.º 42
0
        private void DealConstraintWord(string part)
        {
            //part 表示列名
            if (_column == null)
            {
                //可能使用了引用属性,例如表达式:User.Name eq 'huqf'
                var properties = part.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                if (properties.Length > 1)
                {
                    ITableSource lastTable = _mainTable;
                    for (int i = 0; i < properties.Length; i++)
                    {
                        var property = properties[i];
                        var mp       = lastTable.EntityRepository.EntityMeta.ManagedProperties.GetCompiledProperties().Find(property);
                        if (mp == null)
                        {
                            throw new InvalidProgramException(string.Format("查询条件解析出错,没有找到名称为 {0} 的属性。", property));
                        }

                        var refProperty = mp as IRefEntityProperty;
                        if (refProperty != null)
                        {
                            lastTable = _f.FindOrCreateJoinTable(_query, lastTable, refProperty);
                        }
                        else
                        {
                            _column = lastTable.Column(mp);
                        }
                    }
                    if (_column == null)
                    {
                        throw new InvalidProgramException(string.Format("{0} 查询条件出错:属性表达式不能以引用实体属性结尾。", part));
                    }
                }
                else
                {
                    var mp = _properties.Find(part, true);
                    if (mp == null)
                    {
                        throw new InvalidProgramException(string.Format("查询条件解析出错,没有找到名称为 {0} 的属性。", part));
                    }
                    _column = _mainTable.Column(mp);
                }
            }
            //part 表示操作符
            else if (_comparison == null)
            {
                _comparison = part;
            }
            //part 表示值
            else
            {
                var propertyConstraint = CreateColumnConstraint(_comparison, part);
                if (_concat.HasValue && _current != null)
                {
                    _current = _f.Binary(_current, _concat.Value, propertyConstraint);
                    _concat  = null;
                }
                else
                {
                    _current = propertyConstraint;
                }

                _column     = null;
                _comparison = null;
            }
        }
Ejemplo n.º 43
0
 public Delete(ITableSource from, Where @where)
 {
     this.from  = from;
     this.where = where;
 }
Ejemplo n.º 44
0
        /// <summary>
        /// 如果提供的值是不可空的,则为查询添加一个对应的约束条件,并以 And 与原条件进行连接。
        /// </summary>
        /// <param name="query">查询.</param>
        /// <param name="property">要约束的属性.</param>
        /// <param name="op">约束条件操作符.</param>
        /// <param name="value">当 value 不可空时,才添加这个对比约束条件。</param>
        /// <param name="propertySource">指定该属性所属的实体数据源。</param>
        /// <returns></returns>
        public static IQuery AddConstraintIf(this IQuery query, IManagedProperty property, PropertyOperator op, object value, ITableSource propertySource)
        {
            if (ConditionalSql.IsNotEmpty(value))
            {
                return(AddConstraint(query, property, op, value, propertySource));
            }

            return(query);
        }
Ejemplo n.º 45
0
 /// <summary>
 /// 在查询对象中查找或者创建指定引用属性对应的连接表对象。
 /// </summary>
 /// <param name="query">需要在这个查询对象中查找或创建连接表。</param>
 /// <param name="propertyOwner">引用属性对应外键所在的表。</param>
 /// <param name="refProperty">指定的引用属性。</param>
 /// <returns></returns>
 public ITableSource FindOrCreateJoinTable(IQuery query, ITableSource propertyOwner, IRefEntityProperty refProperty)
 {
     return((query as TableQuery).FindOrCreateJoinTable(propertyOwner, refProperty));
 }
Ejemplo n.º 46
0
 private void VisitValueProperty(IManagedProperty mp, ITableSource mpOwnerTable)
 {
     //如果已经记录了条件的属性,那么当前的 mp 就是用于对比的第二个属性。(A.Code = A.Name 中的 Name)
     if (_propertyResult != null)
     {
         _rightPropertyResult = mpOwnerTable.Column(mp);
     }
     //如果还没有记录属性,说明当前条件要比较的属性就是 mp;(A.Code = 1 中的 Code)
     else
     {
         _propertyResult = mpOwnerTable.Column(mp);
     }
 }
Ejemplo n.º 47
0
        internal IIndexSet GetIndexSetForTable(ITableSource tableSource)
        {
            int sz = tableIndices.Count;
            for (int i = 0; i < sz; ++i) {
                if (visibleTables[i].TableId == tableSource.TableId) {
                    return tableIndices[i];
                }
            }

            throw new Exception("Table source not found in this transaction.");
        }
Ejemplo n.º 48
0
            protected override IConstraint GetCondition(ITableSource mainTable, IQuery query)
            {
                var isPhantomColumn = mainTable.FindColumn(EntityPhantomExtension.IsPhantomProperty);

                return(isPhantomColumn.Equal(BooleanBoxes.False));
            }
Ejemplo n.º 49
0
        internal void RemoveVisibleTable(ITableSource table)
        {
            if (Transaction.ReadOnly())
                throw new Exception("Transaction is Read-only.");

            var i = IndexOfTable(visibleTables, table.TableId);
            if (i != -1) {
                visibleTables.RemoveAt(i);
                IIndexSet indexSet = tableIndices[i];
                tableIndices.RemoveAt(i);
                if (cleanupQueue == null)
                    cleanupQueue = new List<object>();

                cleanupQueue.Add(table);
                cleanupQueue.Add(indexSet);

                // Remove from the table cache
                var tableName = table.TableInfo.TableName;
                tableCache.Remove(tableName);
            }
        }
Ejemplo n.º 50
0
        /// <summary>
        /// 为查询添加一个对应的约束条件,并以 And 与原条件进行连接。
        /// </summary>
        /// <param name="query">查询.</param>
        /// <param name="property">要约束的属性.</param>
        /// <param name="op">约束条件操作符.</param>
        /// <param name="value">对比的值。</param>
        /// <param name="propertySource">指定该属性所属的实体数据源。</param>
        /// <returns></returns>
        public static IQuery AddConstraint(this IQuery query, IManagedProperty property, PropertyOperator op, object value, ITableSource propertySource)
        {
            var f = QueryFactory.Instance;

            var propertyNode = propertySource.Column(property);

            var where = f.Constraint(propertyNode, op, value);
            if (query.Where == null)
            {
                query.Where = where;
            }
            else
            {
                query.Where = f.And(query.Where, where);
            }

            return(query);
        }
Ejemplo n.º 51
0
        private void AddVisibleTable(ITableSource table, IIndexSet indexSet)
        {
            if (Transaction.ReadOnly())
                throw new Exception("Transaction is Read-only.");

            visibleTables.Add(table);
            tableIndices.Add(indexSet);
        }
Ejemplo n.º 52
0
 public static IJoin Join(this ITableSource left, ITableSource right)
 {
     return(QueryFactory.Instance.Join(left, right));
 }
Ejemplo n.º 53
0
        private void CopyTable(ITableSource tableSource, IIndexSet indexSet)
        {
            var tableInfo = tableSource.TableInfo;
            var tableName = tableInfo.TableName;
            var source = FindVisibleTable(tableName, false);
            if (source != null)
                throw new ObjectNotFoundException(tableName);

            // Copy the table and add to the list of visible tables.
            source = Composite.CopySourceTable(tableSource, indexSet);

            AddVisibleTable(source, source.CreateIndexSet());

            // Log in the journal that this transaction touched the table_id.
            int tableId = source.TableId;
            Transaction.Registry.RegisterEvent(new TableCreatedEvent(tableId, tableName));

            Transaction.CreateNativeSequence(tableName);
        }
Ejemplo n.º 54
0
 ITableSource ITableSourceComposite.CopySourceTable(ITableSource tableSource, IIndexSet indexSet)
 {
     return CopySourceTable((TableSource) tableSource, indexSet);
 }
Ejemplo n.º 55
0
 protected virtual ITableSource VisitEntitySource(ITableSource node)
 {
     return node;
 }