Package nexj.core.persistence

Examples of nexj.core.persistence.Field


                  for (int i = 0; i < nDKColumnCount; ++i)
                  {
                     Column column = destinationKey.getIndexColumn(i).getColumn();

                     addOutputField(dkFieldArray[i] = new Field(query, join, column,
                        column.getValueType(), m_adapter.getConverter(column.getValueType(), column),
                        m_adapter.getBind(column), true));
                  }

                  query.setChildItem(dkFieldArray);
               }
            }
            else
            {
               Index sourceKey = (Index)query.getKey(false);
               SQLJoin parent;

               if (sourceKey.isObjectKey())
               {
                  parent = (SQLJoin)query.getParent().getMapping();
                  sourceKey = parent.table.getPrimaryKey();
               }
               else
               {
                  parent = addTable(query.getParent(), sourceKey.getTable());
               }

               parent.isEnabled = true;

               if (bHomogeneous)
               {
                  Index destinationKey = (Index)query.getKey(true);
                  SQLJoin join = addTable(query, destinationKey.getTable());

                  join.parent = parent;
                  join.sourceKey = sourceKey;
                  join.destinationKey = destinationKey;

                  // Decide whether we can use the left joined table
                  // source key instead of the right joined table primary key
                  // to reduce the number of indirections in the SQL query
                  // TODO: Traverse the parent list up for more potential savings

                  if (query.getWhere() == null &&
                     (destinationKey.isObjectKey() &&
                        (!query.isOutput() ||
                           (!sourceKey.isObjectKey() || query.isRequired()) &&
                           query.getFieldCount() == 0 &&
                           query.getAssocCount(Query.ASSOC_QUERY) == 0) ||
                     destinationKey.isObjectKeyPart() &&
                        !query.isOutput() &&
                        query.getFieldCount() == 0 &&
                        query.getAssocCount(Query.ASSOC_QUERY) == 0))
                  {
                     primarySource = query.getParent();
                     primaryJoin = parent;
                     primaryKey = sourceKey;
                  }
                  else
                  {
                     primaryJoin = join;
                     primaryKey = join.table.getPrimaryKey();

                     if (destinationKey.isObjectKeyPart() &&
                        (!sourceKey.isObjectKey() || query.isRequired()))
                     {
                        fieldSource = query.getParent();
                        fieldJoin = parent;
                        fieldKey = sourceKey;
                     }
                  }

                  if (join.parent.isInner && query.isRequired())
                  {
                     join.isInner = true;
                  }
               }
               else
               {
                  primarySource = query.getParent();
                  primaryJoin = parent;
                  primaryKey = sourceKey;
               }
            }

            primaryJoin.isEnabled = true;

            int nPKColumnCount = primaryKey.getIndexColumnCount();
            Field[] pkFieldArray = new Field[nPKColumnCount];

            for (int i = 0; i < nPKColumnCount; ++i)
            {
               Column column = primaryKey.getIndexColumn(i).getColumn();

               pkFieldArray[i] = new Field(primarySource, primaryJoin, column,
                  column.getValueType(), m_adapter.getConverter(column.getValueType(), column),
                  m_adapter.getBind(column), true);
            }

            if (query.getParent() != null && query.getParentItem() == null)
            {
               query.setParentItem(pkFieldArray);
            }

            if (bHomogeneous || (query.getRestriction() & Query.RESTRICTION_WHERE) != 0)
            {
               // The following conditional relies on the visit order
               // to avoid overwriting the PK in a hetero query
               if (query.getItem() == null)
               {
                  query.setItem(pkFieldArray);

                  if (fieldSource != null)
                  {
                     int nColumnCount = fieldKey.getIndexColumnCount();
                     Field[] fieldArray = new Field[nColumnCount];

                     for (int i = 0; i < nColumnCount; ++i)
                     {
                        Column column = fieldKey.getIndexColumn(i).getColumn();

                        fieldArray[i] = new Field(primarySource, fieldJoin, column,
                           column.getValueType(), m_adapter.getConverter(column.getValueType(), column),
                           m_adapter.getBind(column), true);
                     }

                     query.setFieldItem(fieldArray);
                  }
                  else
                  {
                     query.setFieldItem(pkFieldArray);
                  }
               }
            }

            if (query.isOutput() ||
               !bHomogeneous && (query.getRestriction() & Query.RESTRICTION_WHERE) == 0)
            {
               if (query.isIdentity() || !query.isOutput())
               {
                  // Output the primary key columns
                  for (int i = 0; i < nPKColumnCount; ++i)
                  {
                     addOutputField(pkFieldArray[i]);
                  }
               }

               m_query.addOutputQuery(query);
            }

            if (bHomogeneous)
            {
               // Bind the columns to the attributes
               for (Iterator itr = query.getFieldIterator(); itr.hasNext();)
               {
                  Field field = (Field)itr.next();

                  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);
                  }
               }
View Full Code Here


      Field[] pkFieldArray = (Field[])query.getItem();

      for (int i = 0, nCount = pkFieldArray.length; i < nCount; ++i)
      {
         Field field = pkFieldArray[i];
         SQLJoin mapping = (SQLJoin)field.getMapping();

         // Check whether the key is mapped to this
         // subquery or to the parent foreign key.
         // Do not add the key in the latter case.
         if (mapping.query != query)
         {
            break;
         }

         appendSubqueryOutputColumn(buf, mapping, (Column)field.getItem());
      }

      if (join.destinationKey != null)
      {
         appendSubqueryOutputKey(buf, join, join.destinationKey);
      }

      for (Iterator itr = query.getFieldIterator(); itr.hasNext();)
      {
         Field field = (Field)itr.next();
         Object mapping = field.getMapping();

         if (mapping instanceof SQLJoin)
         {
            appendSubqueryOutputColumn(buf, (SQLJoin)mapping, (Column)field.getItem());
         }
      }

      for (Iterator itr = query.getAssocIterator(Query.ASSOC_QUERY); itr.hasNext();)
      {
         Query assoc = (Query)itr.next();

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

            appendSubqueryOutputKey(buf, assocJoin.parent, assocJoin.sourceKey);
         }
         else
         {
            pkFieldArray = (Field[])assoc.getParentItem();

            for (int i = 0, nCount = pkFieldArray.length; i < nCount; ++i)
            {
               Field field = pkFieldArray[i];
               SQLJoin mapping = (SQLJoin)field.getMapping();

               // Check whether the key is mapped to this
               // subquery or to the parent foreign key.
               // Do not add the key in the latter case.
               if (mapping.query != query)
               {
                  break;
               }

               appendSubqueryOutputColumn(buf, mapping, (Column)field.getItem());
            }
         }
      }
   }
View Full Code Here

            }
            else
            {
               IndexColumn indexColumn = index.getIndexColumn(i);
               Column column = indexColumn.getColumn();
               Field field = new Field(query, mapping, column, column.getValueType(),
                  m_adapter.getConverter(column.getValueType(), column),
                  m_adapter.getBind(column), false);

               op = new AttributeOperator(field);
               bAscending = indexColumn.isAscending() ^ bSortDirectionReversed;
View Full Code Here

   {
      if (op.getType() == Primitive.BOOLEAN &&
         (parent == null && (m_nGenMode == GEN_JOIN || m_nGenMode == GEN_WHERE || m_nGenMode == GEN_HAVING) ||
          parent instanceof Logical || parent instanceof IfOperator && op == ((IfOperator)parent).getCondition()))
      {
         Field field = (Field)op.getSource();
         Column column = (Column)field.getItem();
         Boolean value = Boolean.valueOf(bTrue);
         boolean bParen = (parent != null && parent.getPriority() >= EqualsOperator.PRIORITY);

         if (bParen)
         {
View Full Code Here

         return m_result.getOID();
      }

      if (item instanceof Field)
      {
         Field field = (Field)item;

         Object value = m_result.findValue(field.getAttribute().getName());

         if (value == null || value instanceof OID)
         {
            return (OID)value;
         }
View Full Code Here

      }

      // Make the instance non-lazy if possible
      if (instance.isLazy())
      {
         Field field = query.getTypeCodeField();

         if (field != null)
         {
            metaclass = query.getPersistenceMapping().findMetaclassByTypeCode(getValue(field));
         }
View Full Code Here

         {
            AttributeOperator aop = (AttributeOperator)op;

            if (!aop.isNoConversion() && aop.getSource() instanceof Field)
            {
               Field field = (Field)aop.getSource();

               if (field.getAttribute() != null)
               {
                  AttributeMapping mapping = field.getAttributeMapping();

                  if (mapping instanceof RelationalPrimitiveMapping &&
                     ((RelationalPrimitiveMapping)mapping).getColumn().isPostConverted())
                  {
                     return false;
View Full Code Here

TOP

Related Classes of nexj.core.persistence.Field

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.