Package nexj.core.meta.persistence.sql

Examples of nexj.core.meta.persistence.sql.Column


         return; // NOOP
      }

      for (int i = 0, nCount = target.getColumnCount(); i < nCount; ++i)
      {
         Column targetCol = target.getColumn(i);
         Column currentCol = current.findColumn(targetCol.getName());

         if (currentCol != null)
         {
            continue; // NOOP column already exists
         }

         currentCol = (Column)targetCol.clone();

         if (!bNullability && !currentCol.isNullable())
         {
            currentCol.setRequired(false, true); // otherwise isNullable returns false for required
            currentCol.setNullable(true); // do not set the nullibility flag
         }

         createColumn(currentCol, true); // true so createColumn doesn't have to clone()
         current.addColumn(currentCol);
      }
View Full Code Here


         return; // NOOP
      }

      for (int i = current.getColumnCount() - 1; i >= 0; --i) // backwards due to column removal
      {
         Column currentCol = current.getColumn(i);
         Column targetCol = target.findColumn(currentCol.getName());

         if (targetCol == null)
         {
            dropIndexes(currentCol, true);
            dropColumn(currentCol);
View Full Code Here

      schema.addTable(m_table);

      for (Lookup.Iterator itr = m_columnMap.valueIterator(); itr.hasNext();)
      {
         ColumnOutline outline = (ColumnOutline)itr.next();
         Column column = new Column(outline.getName(), m_table);

         outline.copyTo(column);
         m_table.addColumn(column);
      }
View Full Code Here

            if (nValCount++ > 0)
            {
               buf.append(", ");
            }
           
            Column column = m_table.getColumn(i);

            buf.append(column.getQuotedName());

            if (m_adapter.isCaseConverted(column))
            {
               buf.append(", ");
               m_adapter.appendCaseConvertedColumn(buf, column);
               bCaseConverted = true;
            }
         }
      }

      if (nValCount == 0)
      {
         buf.setLength(buf.length() - 1);
         buf.append(" default values");
      }
      else
      {
         buf.append(") values (");
                       
         if (m_bIdentity && m_adapter.appendIdentityValue(buf, this))
         {
            if (--nValCount > 0)
            {
               buf.append(", ");
            }
         }

         if (bCaseConverted)
         {
            nValCount = 0;

            for (int i = 0; i < nCount; ++i)
            {
               if (getValue(i) != Undefined.VALUE)
               {
                  if (nValCount != 0)
                  {
                     buf.append(", ");
                  }

                  m_adapter.appendBind(buf, nValCount++);

                  Column column = m_table.getColumn(i);

                  if (m_adapter.isCaseConverted(column))
                  {
                     buf.append(", ");
                     m_adapter.appendCaseConvertedBind(buf, nValCount++, column);
View Full Code Here

      {
         Object value = getValue(i);

         if (value != Undefined.VALUE)
         {
            Column column = m_table.getColumn(i);

            value = m_adapter.toBind(column, value);

            Bind bind = m_adapter.getBind(column);
View Full Code Here

   {
      if (m_bIdentity)
      {
         stmt.execute();

         Column column = m_table.getPrimaryKey().getIndexColumn(0).getColumn();

         setInstanceValue(column, m_adapter.toValue(column, m_adapter.getIdentityValue(stmt, column, this)));
         m_instance.setOID(computeOID());
         fixup();
      }
View Full Code Here

               String sName = (String)colItr.next();
               ColumnUpgradeInfo info = (ColumnUpgradeInfo)colItr.getValue();
              
               try
               {
                  Column column = table.getColumn(sName);

                  if (!info.isPhantom())
                  {
                     throw new MetadataException("err.meta.upgrade.sql.missingColumnDef",
                        new Object[]{column.getName(), table.getName(), m_final.getDataSource().getName()});
                  }
               }
               catch (UncheckedException e)
               {
                  eh = info.getStep().addException(eh, e);
View Full Code Here

               }
            }

            for (int i = 0, n = table.getColumnCount(); i < n; ++i)
            {
               Column column = table.getColumn(i);

               if (tableFinal.findColumn(column.getName()) == null)
               {
                  eh = addException(eh, new MetadataException("err.meta.upgrade.sql.extraColumn",
                     new Object[]{column.getName(), tableFinal.getName(), m_final.getDataSource().getName()}));
               }
            }

            for (int i = 0, n = tableFinal.getColumnCount(); i < n; ++i)
            {
               Column columnFinal = tableFinal.getColumn(i);
               Column column = table.findColumn(columnFinal.getName());

               if (column == null)
               {
                  eh = addException(eh, new MetadataException("err.meta.upgrade.sql.missingColumn",
                     new Object[]{columnFinal.getName(), tableFinal.getName(), m_final.getDataSource().getName()}));
               }
               else
               {
                  if (columnFinal.getType() != column.getType())
                  {
                     eh = addException(eh, new MetadataException("err.meta.upgrade.sql.columnTypeMismatch",
                        new Object[]{columnFinal.getType().getName(), column.getType().getName(),
                           columnFinal.getName(), tableFinal.getName(), m_final.getDataSource().getName()}));
                  }

                  if (columnFinal.getPrecision() != column.getPrecision())
                  {
                     eh = addException(eh, new MetadataException("err.meta.upgrade.sql.columnPrecisionMismatch",
                        new Object[]{Primitive.createInteger(columnFinal.getPrecision()),
                           Primitive.createInteger(column.getPrecision()), columnFinal.getName(),
                           tableFinal.getName(), m_final.getDataSource().getName()}));
                  }

                  if (columnFinal.getScale() != column.getScale())
                  {
                     eh = addException(eh, new MetadataException("err.meta.upgrade.sql.columnScaleMismatch",
                        new Object[]{Primitive.createInteger(columnFinal.getScale()),
                           Primitive.createInteger(column.getScale()), columnFinal.getName(),
                           tableFinal.getName(), m_final.getDataSource().getName()}));
                  }

                  if (columnFinal.getAllocation() != column.getAllocation())
                  {
                     eh = addException(eh, new MetadataException("err.meta.upgrade.sql.columnAllocationMismatch",
                        new Object[]{columnFinal.getAllocationString(), column.getAllocationString(),
                           columnFinal.getName(), tableFinal.getName(), m_final.getDataSource().getName()}));
                  }

                  if (columnFinal.isNullable() != column.isNullable())
                  {
                     eh = addException(eh, new MetadataException("err.meta.upgrade.sql.columnNullabilityMismatch",
                        new Object[]{Boolean.valueOf(columnFinal.isNullable()),
                           Boolean.valueOf(column.isNullable()), columnFinal.getName(),
                           tableFinal.getName(), m_final.getDataSource().getName()}));
                  }

                  if (columnFinal.isCaseInsensitive() != column.isCaseInsensitive())
                  {
                     eh = addException(eh, new MetadataException("err.meta.upgrade.sql.columnCaseInsensitivityMismatch",
                        new Object[]{Boolean.valueOf(columnFinal.isCaseInsensitive()),
                           Boolean.valueOf(column.isCaseInsensitive()), columnFinal.getName(),
                           tableFinal.getName(), m_final.getDataSource().getName()}));
                  }

                  String sConverterFinal = "";
                  String sConverter = "";

                  if (columnFinal.getConverter() != null)
                  {
                     sConverterFinal = columnFinal.getConverter().getName();
                  }

                  if (column.getConverter() != null)
                  {
                     sConverter = column.getConverter().getName();
                  }

                  if (!sConverterFinal.equals(sConverter))
                  {
                     eh = addException(eh, new MetadataException("err.meta.upgrade.sql.columnConverterMismatch",
View Full Code Here

                  join.isInner = true;
                  join.isEnabled = true;

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

               bAscending = query.isOrderByAscending(i - nPrefixColumnCount);
            }
            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

TOP

Related Classes of nexj.core.meta.persistence.sql.Column

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.