Package nexj.core.persistence

Examples of nexj.core.persistence.Operator$Visitor


            if (i > 0)
            {
               buf.append(", ");
            }

            Operator op;
            boolean bAscending;

            if (i >= nPrefixColumnCount)
            {
               op = query.getOrderByOperator(i - nPrefixColumnCount);
View Full Code Here


    * @param buf The buffer where to append the column.
    * @param field The field specifying the mapped column.
    */
   protected void appendField(StringBuffer buf, Field field)
   {
      Operator op = field.getOperator();

      if (op != null)
      {
         String sSuffix = (op.getType() == Primitive.BOOLEAN &&
            !(op instanceof AttributeOperator) &&
            !(op instanceof IfOperator)) ?
            m_adapter.appendBooleanPrefix(buf, op) : null;

         appendOperator(buf, op);
View Full Code Here

    */
   protected void appendOperator(StringBuffer buf, Operator op)
   {
      if (op.isConstant())
      {
         Operator parent = op.getParent();
         Object value = op.getValue();
         Column column = null;
         Operator left = null;

         if (parent instanceof ComparisonOperator)
         {
            left = ((ComparisonOperator)op.getParent()).getLeft();

            if (parent.getOrdinal() == LikeOperator.ORDINAL && value != null)
            {
               value = m_adapter.getLikePattern((String)value);
            }
         }
         else if (parent instanceof InOperator)
         {
            left = ((InOperator)op.getParent()).getOperand(0);
         }

         if (left instanceof AttributeOperator)
         {
            AttributeOperator aop = (AttributeOperator)left;

            if (aop.getConverter() == null)
            {
               column = (Column)((Field)aop.getSource()).getItem();
            }
         }

         if (column != null)
         {
            if ((column.isLiteral() || m_adapter.isLiteral()) &&
               m_adapter.isLiteral(column.getType(), value) ||
               getBindCount() == m_adapter.getMaxBindCount())
            {
               if (column.isTimeZoned() && value != null)
               {
                  Timestamp ts = ((Timestamp)value);
                  long lTime = ts.getTime();

                  Timestamp tsLocal = new Timestamp(lTime + ((CalendarFactory)column.getConverter().getInstance(null))
                        .createCalendar().getTimeZone().getOffset(lTime));

                  tsLocal.setNanos(ts.getNanos());
                  value = tsLocal;
               }

               m_adapter.appendLiteral(buf, column.getType(), value);
            }
            else
            {
               m_adapter.appendBind(buf, getBindCount());
               addBind(m_adapter.getBind(column), m_adapter.toBind(column, value));
            }
         }
         else
         {
            if (value == null)
            {
               buf.append("null");
            }
            else
            {
               Primitive type = (Primitive)op.getType();

               if (m_adapter.isLiteral() && m_adapter.isLiteral(type, value) ||
                  getBindCount() == m_adapter.getMaxBindCount())
               {
                  m_adapter.appendLiteral(buf, type, value);
               }
               else
               {
                  m_adapter.appendBind(buf, getBindCount(), type, value);
                  addBind(m_adapter.getBind(type), m_adapter.getInternal(type, value));
               }
            }
         }
      }
      else
      {
         OperatorAppender appender = m_adapter.findOperatorAppender(op);

         if (appender == null)
         {
            appender = s_appenderArray[op.getOrdinal()];
         }

         if (appender == null)
         {
            throw new PersistenceException("err.persistence.unsupportedOperator",
               new Object[]{op.getSymbol()});
         }

         Operator parent = op.getParent();
         String sSuffix = null;

         if (op.getType() == Primitive.BOOLEAN)
         {
            if (op instanceof IfOperator)
            {
               if (parent instanceof Logical ||
                  parent instanceof IfOperator && op == ((IfOperator)parent).getCondition() ||
                  parent == null && (m_nGenMode == GEN_JOIN || m_nGenMode == GEN_WHERE || m_nGenMode == GEN_HAVING))
               {
                  buf.append('(');

                  int i = buf.length();

                  buf.append(" <> ");
                  m_adapter.appendLiteral(buf, Primitive.BOOLEAN, Boolean.FALSE);
                  buf.append(')');
                  sSuffix = buf.substring(i);
                  buf.setLength(i);
               }
            }
            else if (!(op instanceof AttributeOperator) &&
               parent instanceof IfOperator &&
               op != ((IfOperator)parent).getCondition())
            {
               sSuffix = m_adapter.appendBooleanPrefix(buf, op);
            }
         }

         if (sSuffix == null && parent != null)
         {
            int nPriority = op.getPriority();
            int nParentPriority = parent.getPriority();
            boolean bReprioritize = false;

            if (nPriority <= nParentPriority)
            {
               if (nPriority == nParentPriority)
View Full Code Here

         m_else = m_else.normalize(nFlags);
      }

      if (m_condition.isConstant())
      {
         Operator op = (Boolean.FALSE.equals(m_condition.getValue())) ? m_else : m_then;

         op.setParent(m_parent);

         return op;
      }

      Type thenType = m_then.getType();
      Type elseType = m_else.getType();

      m_source = null;

      if (thenType == null)
      {
         m_type = elseType;
      }
      else if (elseType == null)
      {
         m_type = thenType;
      }
      else if (!thenType.isPrimitive() || !elseType.isPrimitive())
      {
         if (thenType.isPrimitive() == elseType.isPrimitive())
         {
            m_type = thenType;

            while (!m_type.isUpcast(elseType))
            {
               m_type = m_type.getBaseType();
            }
         }
         else
         {
            m_type = Primitive.ANY;
         }
      }
      else
      {
         m_source = null;
         addSource(m_condition, addSource(m_then, addSource(m_else, false)));
         setSource(m_source, nFlags);

         ConversionMapper mapper = null;
         BinaryDescriptor descriptor = null;

         if (m_source != null)
         {
            mapper = m_source.getAdapter().getConversionMapper();
            descriptor = mapper.getIfDescriptor(this);
         }

         if (descriptor == null)
         {
            m_source = null;
            mapper = getConversionMapper();
            descriptor = mapper.getIfDescriptor(this);
         }

         if (descriptor == null)
         {
            m_type = Primitive.ANY;
         }
         else
         {
            if (mapper.getType((Primitive)thenType) != mapper.getType(descriptor.getLeftType()))
            {
               setThen(new TypeConversionOperator(descriptor.getLeftType(), m_then));
               m_then = m_then.normalize(nFlags | NORMALIZE_NORECUR);
            }

            if (mapper.getType((Primitive)elseType) != mapper.getType(descriptor.getRightType()))
            {
               setElse(new TypeConversionOperator(descriptor.getRightType(), m_else));
               m_else = m_else.normalize(nFlags | NORMALIZE_NORECUR);
            }

            m_type = descriptor.getResultType();
         }
      }

      // Truth table optimization
      if (m_type == Primitive.BOOLEAN)
      {
         MultiArgOperator op = null;
         NotOperator not = null;
         Operator right = null;

         if (m_then.isConstant())
         {
            if (Boolean.FALSE.equals(m_then.getValue()))
            {
View Full Code Here

   /**
    * @see nexj.core.persistence.operator.AggregateOperator#foldConstant()
    */
   protected void foldConstant()
   {
      Operator op = getOperand();

      if (op.isConstant() && op.getValue() == null)
      {
         setConstantValue(null);
      }
   }
View Full Code Here

       * @see nexj.core.persistence.sql.SQLGenerator.OperatorAppender#appendOperator(java.lang.StringBuffer, nexj.core.persistence.Operator, nexj.core.persistence.sql.SQLGenerator)
       */
      public void appendOperator(StringBuffer buf, Operator op, SQLGenerator gen)
      {
         ComparisonOperator compOp = (ComparisonOperator)op;
         Operator right = compOp.getRight();

         gen.appendComparisonOperand(buf, compOp.getLeft());

         if (right.isConstant() && right.getValue() == null)
         {
            buf.append(m_sNullComparison);
         }
         else
         {
View Full Code Here

TOP

Related Classes of nexj.core.persistence.Operator$Visitor

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.