Package nexj.core.meta.persistence.sql

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


    * @param step The create column step.
    */
   protected void createColumn(CreateColumnStep step)
   {
      RelationalSchema schema = m_state.getSchema();
      Table table = schema.getTable(step.getTableName()); // table in the column is fully updated
      SQLScriptHolder holder = step.getScriptHolder();

      if (table.isAspect())
      {
         int nEnd = 0;
         Table[] tableArray = getSortedTables(schema);

         for (int i = 0, nCount = tableArray.length; i < nCount; ++i)
         {
            if (tableArray[i].hasAspect(table))
            {
               tableArray[nEnd++] = tableArray[i].cloneTemporary();
            }
         }

         step.apply(m_state);

         for (int i = 0; i < nEnd; ++i)
         {
            Table current = tableArray[i];
            Table target = schema.getTable(current.getName());

            createColumns(target, current, false); // create nullable columns
            execSQL(holder, current); // execute any defined scripts
            alterColumns(target, current); // set null constraint
         }
      }
      else
      {
         Table current = table.cloneTemporary();

         step.apply(m_state);
         table = schema.getTable(step.getTableName()); // refresh table from schema, required!
         createColumns(table, current, false); // create nullable columns
         execSQL(holder, current); // execute any defined scripts
View Full Code Here


    * @param step The alter column step.
    */
   protected void alterColumn(AlterColumnStep step)
   {
      RelationalSchema schema = m_state.getSchema();
      Table table = schema.getTable(step.getTableName());

      if (table.isAspect())
      {
         int nEnd = 0;
         Table[] tableArray = getSortedTables(schema);

         for (int i = 0, nCount = tableArray.length; i < nCount; ++i)
         {
            if (tableArray[i].hasAspect(table))
            {
               tableArray[nEnd++] = tableArray[i].cloneTemporary();
            }
         }

         step.apply(m_state);

         for (int i = 0; i < nEnd; ++i)
         {
            Table current = tableArray[i];

            alterColumns(schema.getTable(current.getName()), current);
         }
      }
      else
      {
         Table current = table.cloneTemporary();

         step.apply(m_state);
         alterColumns(table, current);
      }
   }
View Full Code Here

    * @param step The rename column step.
    */
   protected void renameColumn(RenameColumnStep step)
   {
      RelationalSchema schema = m_state.getSchema();
      Table table = schema.getTable(step.getTableName());

      if (table.isAspect())
      {
         List oldColumnList = new ArrayList();
         Table[] tableArray = getSortedTables(schema);

         for (int i = 0, nCount = tableArray.length; i < nCount; ++i)
         {
            Table pointcut = tableArray[i];

            if (pointcut.hasAspect(table))
            {
               oldColumnList.add(pointcut.cloneTemporary().getColumn(step.getOldName()));
            }
         }

         step.apply(m_state);

View Full Code Here

    * @param step The drop column step.
    */
   protected void dropColumn(DropColumnStep step)
   {
      RelationalSchema schema = m_state.getSchema();
      Table table = schema.getTable(step.getTableName());

      if (table.isAspect())
      {
         int nEnd = 0;
         Table[] tableArray = getSortedTables(schema);

         for (int i = 0, nCount = tableArray.length; i < nCount; ++i)
         {
            if (tableArray[i].hasAspect(table))
            {
               tableArray[nEnd++] = tableArray[i].cloneTemporary();
            }
         }

         step.apply(m_state);

         for (int i = 0; i < nEnd; ++i)
         {
            Table current = tableArray[i];

            dropColumns(schema.getTable(current.getName()), current);
         }
      }
      else
      {
         Table current = table.cloneTemporary();

         step.apply(m_state);
         dropColumns(table, current);
      }
   }
View Full Code Here

         default:
            return;
      }

      Table table;

      if (bSuccessor)
      {
         table = ((Index)dstKey).getTable();
      }
      else
      {
         table = ((RelationalMapping)instance.getPersistenceMapping()).getPrimaryTable();
      }

      SQLWork sqlWork = findWork(uow, instance, table);

      if (sqlWork == null)
      {
         sqlWork = addWork(uow, nType, instance, table);

         if (bSuccessor)
         {
            Table primaryTable = ((RelationalMapping)instance.getPersistenceMapping()).getPrimaryTable();

            // Add a secondary table as successor to the primary one
            if (table != primaryTable)
            {
               if (instance.getOID() != null)
               {
                  sqlWork.setOID();
               }
               else
               {
                  getWork(uow, nType, instance, primaryTable).addSuccessor(sqlWork, table.getPrimaryKey(), primaryTable.getPrimaryKey());
               }
            }
         }
      }
View Full Code Here

    * @param instance The instance for which to add the work items.
    */
   protected void addInsert(UnitOfWork uow, Instance instance)
   {
      RelationalMapping relMapping = (RelationalMapping)instance.getPersistenceMapping();
      Table primaryTable = relMapping.getPrimaryTable();
      SQLWork primaryWork = getWork(uow, SQLWork.INSERT, instance, primaryTable);
      OID oid = instance.getOID();

      if (oid != null)
      {
         primaryWork.setOID();
      }
      else
      {
         Component component = relMapping.getKeyGenerator();

         if (component == RelationalMapping.KEY_GEN_IDENTITY)
         {
            primaryWork.setIdentity(true);
         }
         else if (component != null)
         {
            oid = ((OIDGenerator)component.getInstance(uow.getInvocationContext())).generateOID(instance, this);

            Object[] values = oid.getValueArray();
            Index pk = primaryTable.getPrimaryKey();
            int nCount = pk.getIndexColumnCount();

            if (nCount != values.length)
            {
               throw new PersistenceException("err.persistence.oidValueCount",
                  new Object[]{component.getName(), Primitive.createInteger(nCount),
                     Primitive.createInteger(values.length)});
            }

            for (int i = 0; i < nCount; ++i)
            {
               values[i] = pk.getIndexColumn(i).getColumn().getValueType().convert(values[i]);
            }

            instance.setOID(oid);
            primaryWork.setOID();
         }
         else
         {
            Metaclass metaclass = instance.getMetaclass();

            for (int i = 0, n = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; ++i)
            {
               Attribute attribute = metaclass.getInstanceAttribute(i);
               AttributeMapping mapping = relMapping.getAttributeMapping(attribute);
               int nPrimaryColCount = primaryTable.getPrimaryKey().getIndexColumnCount();

               if (mapping instanceof RelationalPrimitiveMapping)
               {
                  Column column = ((RelationalPrimitiveMapping)mapping).getColumn();

View Full Code Here

    * @param instance The instance for which to add the work items.
    */
   protected void addUpdate(UnitOfWork uow, Instance instance)
   {
      RelationalMapping relMapping = (RelationalMapping)instance.getPersistenceMapping();
      Table primaryTable = relMapping.getPrimaryTable();
      SQLUpdate work = (SQLUpdate)getWork(uow, SQLWork.UPDATE, instance, primaryTable);

      work.setupLocking();

      addUpdateDependencies(uow, instance, work);
View Full Code Here

            tableSet.add(((Column)itr.next()).getTable());
         }

         for (Iterator itr = tableSet.iterator(); itr.hasNext();)
         {
            Table table = (Table)itr.next();

         loop:
            for (int nIndex = 0, nIndexCount = table.getIndexCount(); nIndex < nIndexCount; ++nIndex)
            {
               Index index = table.getIndex(nIndex);

               if (index.isUnique() &&
                  (index.getType() == Index.BTREE || index.getType() == Index.CLUSTER))
               {
                  for (int i = 0, n = index.getIndexColumnCount(); i < n; ++i)
View Full Code Here

      {
         return null;
      }

      RelationalDatabase db = (RelationalDatabase)schema.getDataSource();
      Table table = ((RelationalSchema)schema).getVersionTable();
      Metadata metadata = m_context.getMetadata();

      if (metadata.getNamespace() == null || table == null)
      {
         return null;
      }

      Column namespaceColumn = table.getColumn("namespace");
      Column versionColumn = table.getColumn("version");
      Column stepColumn = table.getColumn("step");
      Column upgradableColumn = table.getColumn("upgradable");
      Column testColumn = table.getColumn("test");
      StringBuffer buf = new StringBuffer(128);

      buf.append("select ");
      buf.append(namespaceColumn.getQuotedName());
      buf.append(", ");
      buf.append(versionColumn.getQuotedName());
      buf.append(", ");
      buf.append(stepColumn.getQuotedName());
      buf.append(", ");
      buf.append(upgradableColumn.getQuotedName());
      buf.append(", ");
      buf.append(testColumn.getQuotedName());
      buf.append(" from ");
      buf.append(table.getQuotedName());

      String sSQL = buf.toString();
      SQLConnection connection = null;
      PreparedStatement stmt = null;
View Full Code Here

      if (schema == null)
      {
         return;
      }

      Table table = ((RelationalSchema)schema).getVersionTable();

      if (table == null)
      {
         return;
      }

      Column namespaceColumn = table.getColumn("namespace");
      Column versionColumn = table.getColumn("version");
      Column stepColumn = table.getColumn("step");
      StringBuffer buf = new StringBuffer(128);

      buf.append("update ");
      buf.append(table.getQuotedName());
      buf.append(" set ");
      buf.append(versionColumn.getQuotedName());
      buf.append(" = ");
      appendBind(buf, 0);
      buf.append(", ");
View Full Code Here

TOP

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

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.