} // toStringNoAlias()

        private void appendJoinOnItem(StringBuilder sb, String sideAlias, SelectItem onItem)
        {
            FromItem fromItem = onItem.getFromItem();

            if (fromItem != null && fromItem.getSubQuery() != null && fromItem.getAlias() != null)
            {
                // there's a corner case scenario where an ON item references a
                // subquery being joined. In that case the getSuperQueryAlias()
                // method will include the subquery alias.
                string super_query_alias = onItem.getSuperQueryAlias();
                sb.Append(super_query_alias);
                return;
            }

            if (_join != JoinType.None && _leftSide.getJoin() != JoinType.None)
            {
                sb.Append(onItem.toSql());
                return;
            }

            if (sideAlias != null)
            {
                sb.Append(sideAlias);
                sb.Append('.');
            }
            String superQueryAlias = onItem.getSuperQueryAlias();

            sb.Append(superQueryAlias);
        } // appendJoinOnItem()
        } // selectAll()

        public Query selectAll(FromItem fromItem)
        {
            if (fromItem.getTable() != null)
            {
                Column[] columns = fromItem.getTable().getColumns();
                foreach (Column column in columns)
                {
                    select(column, fromItem);
                }
            }
            else if (fromItem.getJoin() != JoinType.None)
            {
                selectAll(fromItem.getLeftSide());
                selectAll(fromItem.getRightSide());
            }
            else if (fromItem.getSubQuery() != null)
            {
                List <SelectItem> items = fromItem.getSubQuery().getSelectClause().getItems();
                foreach (SelectItem subQuerySelectItem in items)
                {
                    select(new SelectItem(subQuerySelectItem, fromItem));
                }
            }
            else
            {
                throw new MetaModelException("All select items ('*') not determinable with from item: " + fromItem);
            }
            return(this);
        } // selectAll()
Пример #3
0
        } // constructor

        /**
         * Creates a SelectItem that uses a function on a column from a particular
         * {@link FromItem}, for example SUM(a.price) or MAX(p.age)
         *
         * @param function
         * @param column
         * @param fromItem
         */
        public SelectItem(FunctionType function_type, Column column, FromItem fromItem) :
            this(column, fromItem, function_type, null, null, null, null, false)
        {
            if (column == null)
            {
                throw new ArgumentException("column=null");
            }
        } // constructor
 /**
  * Constructor for advanced join types with custom relationships
  *
  * @param join
  *            the join type to use
  * @param leftSide
  *            the left side of the join
  * @param rightSide
  *            the right side of the join
  * @param leftOn
  *            what left-side select items to use for the ON clause
  * @param rightOn
  *            what right-side select items to use for the ON clause
  */
 public FromItem(JoinType join, FromItem leftSide, FromItem rightSide, SelectItem[] leftOn, SelectItem[] rightOn)
 {
     _join      = join;
     _leftSide  = leftSide;
     _rightSide = rightSide;
     _leftOn    = leftOn;
     _rightOn   = rightOn;
 }
        } // from()

        public Query from(Table leftTable, Table rightTable, JoinType joinType, Column leftOnColumn, Column rightOnColumn)
        {
            SelectItem[] leftOn   = new SelectItem[] { new SelectItem(leftOnColumn) };
            SelectItem[] rightOn  = new SelectItem[] { new SelectItem(rightOnColumn) };
            FromItem     fromItem = new FromItem(joinType, new FromItem(leftTable), new FromItem(rightTable), leftOn, rightOn);

            return(from(fromItem));
        } // from()
Пример #6
0
 /**
  * All-arguments constructor
  *
  * @param column
  * @param fromItem
  * @param function
  * @param functionParameters
  * @param expression
  * @param subQuerySelectItem
  * @param alias
  * @param functionApproximationAllowed
  */
 private SelectItem(Column column, FromItem fromItem, FunctionType function, object[] functionParameters,
                    string expression, SelectItem subQuerySelectItem,
                    string alias, bool functionApproximationAllowed) : base()
 {
     _column             = column;
     _fromItem           = fromItem;
     _function           = function;
     _functionParameters = functionParameters;
     _expression         = expression;
     _subQuerySelectItem = subQuerySelectItem;
     _alias = alias;
     _functionApproximationAllowed = functionApproximationAllowed;
 } // constructor
Пример #7
0
        } // constructor

        /**
         * Creates a SelectItem that references another select item in a subquery
         *
         * @param subQuerySelectItem
         * @param subQueryFromItem
         *            the FromItem that holds the sub-query
         */
        public SelectItem(SelectItem subQuerySelectItem, FromItem subQueryFromItem) :
            this(null, subQueryFromItem, null, null, null, subQuerySelectItem, null, false)
        {
            if (subQueryFromItem.getSubQuery() == null)
            {
                throw new ArgumentException("Only sub-query based FromItems allowed.");
            }
            if (subQuerySelectItem.getQuery() != null &&
                !subQuerySelectItem.getQuery().Equals(subQueryFromItem.getSubQuery()))
            {
                throw new ArgumentException("The SelectItem must exist in the sub-query");
            }
        } // constructor
Пример #8
0
        } // constructor

        /**
         * Creates a SelectItem that references a column from a particular
         * {@link FromItem}, for example a.price or p.age
         *
         * @param column
         * @param fromItem
         */
        public SelectItem(Column column, FromItem fromItem) :
            this(null, column, fromItem)
        {
            if (fromItem != null)
            {
                Table fromItemTable = fromItem.getTable();
                if (fromItemTable != null)
                {
                    Table columnTable = column.getTable();
                    if (columnTable != null && !columnTable.Equals(fromItemTable))
                    {
                        throw new InvalidOperationException("Column's table '" + columnTable.getName()
                                                            + "' is not equal to referenced table: " + fromItemTable);
                    }
                }
            }
        } // constructor
 /**
  * Constructor for join FROM clauses that join two tables using their
  * relationship. The primary table of the relationship will be the left side
  * of the join and the foreign table of the relationship will be the right
  * side of the join.
  *
  * @param join
  *            the join type to use
  * @param relationship
  *            the relationship to use for joining the tables
  */
 public FromItem(JoinType join, Relationship relationship)
 {
     _join     = join;
     _leftSide = new FromItem(relationship.getPrimaryTable());
     Column[] columns = relationship.getPrimaryColumns();
     _leftOn = new SelectItem[columns.Length];
     for (int i = 0; i < columns.Length; i++)
     {
         _leftOn[i] = new SelectItem(columns[i]);
     }
     _rightSide = new FromItem(relationship.getForeignTable());
     columns    = relationship.getForeignColumns();
     _rightOn   = new SelectItem[columns.Length];
     for (int i = 0; i < columns.Length; i++)
     {
         _rightOn[i] = new SelectItem(columns[i]);
     }
 }
        public FromItem clone()
        {
            FromItem f = new FromItem();

            f._alias      = _alias;
            f._join       = _join;
            f._table      = _table;
            f._expression = _expression;
            if (_subQuery != null)
            {
                f._subQuery = _subQuery.clone();
            }
            if (_leftOn != null && _leftSide != null && _rightOn != null && _rightSide != null)
            {
                f._leftSide  = _leftSide.clone();
                f._leftOn    = (SelectItem[])_leftOn.Clone();
                f._rightSide = _rightSide.clone();
                f._rightOn   = (SelectItem[])_rightOn.Clone();
            }
            return(f);
        } // clone()
        } // having()

        public Query select(Column column, FromItem fromItem)
        {
            SelectItem selectItem = new SelectItem(column, fromItem);

            return(select(selectItem));
        } // select()