Package nexj.core.persistence

Examples of nexj.core.persistence.Operator


      AggregateOperator parent = (AggregateOperator)m_parent;

      parent.setUnique(true);

      Operator op = getOperand();

      op.setParent(parent);

      return op;
   }
View Full Code Here


   public Operator normalize(int nFlags)
   {
      verifyNesting();
      normalizeOperand(nFlags);

      Operator op = getOperand();
      Type type = op.getType();

      if (type == null || op.isConstant() && op.getValue() == null)
      {
         setConstantValue(Primitive.ZERO_LONG);
      }
      else if (!type.isPrimitive() && (nFlags & NORMALIZE_PERSISTENCE) != 0 && m_source != null)
      {
         Field[] fieldArray = m_source.getAdapter().getFields(op.getSource());

         if (fieldArray != null)
         {
            if (m_bUnique && fieldArray.length > 1)
            {
               // TODO: Support multi-part keys
               throw new TypeMismatchException(getSymbol());
            }

            op = new AttributeOperator(fieldArray[0]);
            setOperand(op);
            op = op.normalize(nFlags | NORMALIZE_NORECUR);
            setOperand(op);
         }
      }

      return this;
View Full Code Here

      boolean bMixed = false;

      for (int i = 0; i < m_nOperandCount; ++i)
      {
         Operator op = m_operandArray[i];

         if (op.getType() == null)
         {
            setConstantValue(Boolean.TRUE);

            return this;
         }

         if (op.getType() != Primitive.BOOLEAN)
         {
            throw new TypeMismatchException(getSymbol());
         }

         if (op.isConstant())
         {
            if (!Boolean.FALSE.equals(op.getValue()))
            {
               setConstantValue(Boolean.TRUE);

               return this;
            }

            removeOperand(i--);
         }
         else
         {
            m_bConstant = false;
            bMixed = addSource(op, bMixed);

            if (op.getOrdinal() == ORDINAL)
            {
               int nCount = mergeOperand(i);

               if (nCount != 0)
               {
                  i += nCount - 1;
               }
            }
         }
      }

      if (m_nOperandCount == 0)
      {
         setConstantValue(Boolean.FALSE);
      }
      else if (m_nOperandCount == 1)
      {
         Operator op = m_operandArray[0];

         op.setParent(m_parent);

         return op;
      }

      setSource(m_source, nFlags);
View Full Code Here

    */
   public Operator normalize(int nFlags)
   {
      if (m_operand.getOrdinal() == ORDINAL)
      {
         Operator op = ((NotOperator)m_operand).getOperand();

         if (op instanceof Logical || op.getType() == Primitive.BOOLEAN)
         {
            op.setParent(m_parent);

            if ((nFlags & NORMALIZE_NORECUR) == 0)
            {
               return op.normalize(nFlags);
            }

            return op;
         }
      }
      else if (m_operand instanceof ComparisonOperator)
      {
         ComparisonOperator op = ((ComparisonOperator)m_operand).createInverse();

         if (op != null)
         {
            op.copy(m_operand);
            op.setParent(m_parent);

            return op.normalize(nFlags);
         }
      }

      if ((nFlags & NORMALIZE_NORECUR) == 0)
      {
         m_operand = m_operand.normalize(nFlags);
      }

      if (m_operand.getOrdinal() == ORDINAL)
      {
         Operator op = ((NotOperator)m_operand).getOperand();

         op.setParent(m_parent);

         return op;
      }

      return super.normalize(nFlags | NORMALIZE_NORECUR);
View Full Code Here

    * @param nOrdinal the operand ordinal number.
    * @return The number of merged operands (0 if no merge has taken place).
    */
   protected int mergeOperand(int nOrdinal)
   {
      Operator op = getOperand(nOrdinal);
      MultiArgOperator mop = (MultiArgOperator)op;
      int nCount = mop.getOperandCount();

      if (nCount != 0)
      {
View Full Code Here

         }
      }

      for (int i = 0; i < m_nOperandCount; ++i)
      {
         Operator op = m_operandArray[i];

         if (visitor.isEligible(op))
         {
            if (!op.visit(visitor, nFlags))
            {
               return false;
            }
         }
      }
View Full Code Here

    */
   protected void dissociate()
   {
      for (int i = 0; i < m_nOperandCount; ++i)
      {
         Operator op = m_operandArray[i];

         if (op.getOrdinal() == getOrdinal())
         {
            MultiArgOperator mop = (MultiArgOperator)op;
            int nCount = mop.getOperandCount();

            if (nCount == 0)
            {
               removeOperand(i);
            }
            else
            {
               reserve(nCount - 1);
               System.arraycopy(m_operandArray, i + 1, m_operandArray,
                  i + nCount, m_nOperandCount - i - 1);

               for (int k = 0; k < nCount; ++k)
               {
                  Operator operand = mop.getOperand(k);

                  operand.setParent(this);
                  m_operandArray[i++] = operand;
               }

               m_nOperandCount += nCount - 1;
            }
View Full Code Here

   {
      Pair orderBy = null;

      for (int i = query.getOrderByCount() - 1; i >= 0; i--)
      {
         Operator op = query.getOrderByOperator(i);
         boolean bAscending = query.isOrderByAscending(i);

         orderBy = new Pair(
            new Pair(op.getExpression(query), Boolean.valueOf(bAscending)),
            orderBy
         );
      }

      return orderBy;
View Full Code Here

                  if (!field.isPersistent())
                  {
                     continue;
                  }

                  Operator op = field.getOperator();

                  if (op != null)
                  {
                     if (op.getType() instanceof Primitive)
                     {
                        field.setBind(m_adapter.getBind((Primitive)op.getType()));
                     }
                  }
                  else
                  {
                     Column column = ((RelationalPrimitiveMapping)field.getAttributeMapping()).getColumn();
                     SQLJoin join = addTable(query, column.getTable());

                     join.isEnabled = true;
                     field.setMapping(join);
                     field.setItem(column);
                     field.setConverter(m_adapter.getConverter((Primitive)field.getAttribute().getType(), column));
                     field.setBind(m_adapter.getBind(column));
                  }

                  // Add the output columns to the join
                  if (field.isOutput() && field.getBind() != null)
                  {
                     addOutputField(field);
                  }
               }

               assert query.getMapping() != null;
            }

            return true;
         }

         public boolean postVisit(final Query query)
         {
            if (query.isMatch()) // only postprocess operators if any require it
            {
               opVisit(query);
            }

            // Determine if a subquery should be generated
            Operator where = query.getWhere();

            if (where != null && !query.isRoot() && !query.isQuantorRoot())
            {
               for (Iterator itr = query.getAssocIterator(Query.ASSOC_WHERE); itr.hasNext();)
               {
                  Query assoc = (Query)itr.next();

                  if (assoc.isSameRoot(query))
                  {
                     SQLJoin join = (SQLJoin)assoc.getMapping();

                     do
                     {
                        if (join.isEnabled)
                        {
                           query.setSubquery(true);

                           break;
                        }

                        join = join.parent;
                     }
                     while (join != query.getMapping());
                  }
               }

               if (!query.isSubquery())
               {
                  where.visit(new Operator.Visitor()
                  {
                     public boolean visit(Operator op)
                     {
                        if (!m_adapter.isJoinSupported(query, op))
                        {
                           query.setSubquery(true);

                           return false;
                        }

                        return true;
                     }

                     public boolean isEligible(Operator op)
                     {
                        return !op.isConstant();
                     }
                  }, Operator.VISIT_POSTORDER);
               }
            }

            return true;
         }

         /**
          * Visit all operators of a query.
          * @param query The query which operators to visit.
          */
         private void opVisit(final Query query)
         {
            // list of seen objects to corresponding SQLJoins, of max possible size,
            // seenObjectList{MatchOperator1, SQLJoin1, MatchOperator2, SQLJoin2, ...}
            // cannot do lazy init because Visitor requires object to be final
            final List seenObjectList = new ArrayList(query.getFieldCount());

            Operator.Visitor visitor = new Operator.Visitor()
            {
               public boolean isEligible(Operator op)
               {
                  return true; // visit all operators as they might contain MatchOperator in branch
               }

               public boolean visit(Operator op)
               {
                  if (!(op instanceof MatchOperator))
                  {
                     return true; // visit other branches and look for MatchOperators
                  }

                  MatchOperator matchOp = (MatchOperator)op;
                  SQLJoin join = null;

                  for (int i = 0, nCount = seenObjectList.size();
                       i < nCount && join == null;
                       i += 2)
                  {
                     MatchOperator seenOp = (MatchOperator)seenObjectList.get(i);

                     if (seenOp.getAttribute().getSource() == matchOp.getAttribute().getSource() &&
                         seenOp.getExpression().equals(matchOp.getExpression()))
                     {
                        join = (SQLJoin)seenObjectList.get(i + 1);
                     }
                  }

                  // optimize for the case where same join table is used multiple times
                  // by reusing it in any other operators of the same query
                  if (join != null)
                  {
                     matchOp.setMapping(join);
                  }
                  else // if null then not seen before or no join table created
                  {
                     Source source = matchOp.getAttribute().getSource();
                     Table table = m_adapter.getMatchJoin(
                        ((RelationalPrimitiveMapping)source.getAttributeMapping()).getColumn(),
                        matchOp.getExpression());

                     if (table != null) // if adapter needs a table join
                     {
                        join = addTable(source.getQuery(), table);
                        join.isEnabled = true; // enable and set operator value to join alias
                        matchOp.setMapping(join); // for s_appenderArray...appendOperator()
                        seenObjectList.add(matchOp); // store join to reuse later
                        seenObjectList.add(join);   // store join to reuse later
                     }
                  }

                  return true; // visit all branches on this level
               }
            };

            Operator whereOp = query.getWhere();

            if (whereOp != null) // only dereference if there is a "where" condition
            {
               whereOp.visit(visitor, Operator.VISIT_PREORDER);
            }

            for (int i = 0, nCount = query.getOrderByCount(); i < nCount; ++i)
            {
               query.getOrderByOperator(i).visit(visitor, Operator.VISIT_PREORDER);
View Full Code Here

               buf.append(", ");
            }

            nOffset = buf.length();

            Operator op = query.getGroupBy(i);
            String sSuffix = m_adapter.appendGroupPrefix(buf, op);

            appendOperator(buf, op);
            m_adapter.appendSuffix(buf, sSuffix);
            addSubstring(buf, nOffset, buf.length());
View Full Code Here

TOP

Related Classes of nexj.core.persistence.Operator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.