Package nexj.core.meta.persistence.sql

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


      PersistenceMapping mapping = versionClass.getPersistenceMapping();
      DataSource ds = mapping.getDataSource();

      if (ds instanceof RelationalDatabase) // SysVersion persisted in RDBMS
      {
         Table table = ((RelationalMapping)mapping).getPrimaryTable();
         RelationalSchemaUpgrade version = new RelationalSchemaUpgrade(sName);
         ExecStep step = new ExecStep();
         SQLScript script = new SQLScript();
         SQLStatement stmt = new SQLStatement();

         stmt.setSQL("update ${table:"+ table.getName() +"} set " +
                     table.getColumn("loaded").getQuotedName() + "=0");
         script.addStatement(stmt);
         step.getScriptHolder().addScript(script);
         version.setDataSource(ds);
         version.addStep(step);
View Full Code Here


    * @see nexj.core.meta.persistence.sql.upgrade.RelationalSchemaUpgradeStep#apply(nexj.core.meta.persistence.sql.upgrade.RelationalSchemaUpgradeState)
    */
   public void apply(RelationalSchemaUpgradeState state)
   {
      RelationalSchema schema = state.getSchema();
      Table table = schema.getTable(m_sTableName);

      m_column = table.getColumn(m_sOldName);
      m_column.setName(m_sNewName);

      if (table.isAspect())
      {
         for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
         {
            Table pointcut = (Table)itr.next();

            if (pointcut.hasAspect(table))
            {
               pointcut.getColumn(m_sOldName).setName(m_sNewName);
            }
         }
      }
   }
View Full Code Here

   {
      if (!state.renameColumn(m_sTableName, m_sNewName, m_sOldName) &&
         !state.containsTable(m_sTableName))
      {
         RelationalSchema schema = state.getSchema();
         Table table = schema.getTable(m_sTableName);

         table.getColumn(m_sNewName).setName(m_sOldName);

         if (table.isAspect())
         {
            for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
            {
               Table pointcut = (Table)itr.next();

               if (pointcut.hasAspect(table) && !state.renameColumn(pointcut.getName(), m_sNewName, m_sOldName))
               {
                  pointcut.getColumn(m_sNewName).setName(m_sOldName);
               }
            }
         }
      }
   }
View Full Code Here

    * @see nexj.core.meta.persistence.sql.upgrade.RelationalSchemaUpgradeStep#apply(nexj.core.meta.persistence.sql.upgrade.RelationalSchemaUpgradeState)
    */
   public void apply(RelationalSchemaUpgradeState state)
   {
      RelationalSchema schema = state.getSchema();
      Table table = schema.getTable(m_sTableName);

      m_column = new Column(m_outline.getName(), table);
      m_outline.copyTo(m_column);
      table.addColumn(m_column);

      m_holder.validate(schema, table, state.getAdapters());

      if (table.isAspect())
      {
         for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
         {
            Table pointcut = (Table)itr.next();

            if (pointcut.hasAspect(table))
            {
               Column column = new Column(m_outline.getName(), table);
               m_outline.copyTo(column);
               pointcut.addColumn(column);
            }
         }
      }
   }
View Full Code Here

     
      if (!state.removeColumn(m_sTableName, sColumnName) &&
         !state.containsTable(m_sTableName))
      {
         RelationalSchema schema = state.getSchema();
         Table table = schema.getTable(m_sTableName);

         table.removeColumn(table.getColumn(sColumnName));

         if (table.isAspect())
         {
            for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
            {
               Table pointcut = (Table)itr.next();

               if (pointcut.hasAspect(table) && !state.removeColumn(pointcut.getName(), sColumnName))
               {
                  pointcut.removeColumn(pointcut.getColumn(sColumnName));
               }
            }
         }
      }
   }
View Full Code Here

      if (!m_index.isAspect() && m_index.getTable().isAspect())
      {
         for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
         {
            Table pointcut = (Table)itr.next();

            if (pointcut.hasAspect(m_index.getTable()))
            {
               schema.removeIndex(pointcut.getIndex(m_index.getName(pointcut)));
            }
         }
      }
   }
View Full Code Here

    * @see nexj.core.meta.persistence.sql.upgrade.RelationalSchemaUpgradeStep#apply(nexj.core.meta.persistence.sql.upgrade.RelationalSchemaUpgradeState)
    */
   public void apply(RelationalSchemaUpgradeState state)
   {
      final RelationalSchema schema = state.getSchema();
      final Table table = schema.getTable(m_sTableName);

      m_index = new Index(m_outline.getName(), m_outline.getType(), table);
      m_outline.copyTo(m_index);
      table.addIndex(m_index);

      new RelationalSchemaAspectManager(schema)
      {
         protected Iterator getTableAspectIterator()
         {
            return schema.getTableIterator();
         }

         protected Iterator getTablePointcutIterator()
         {
            return EmptyIterator.getInstance();
         }

         protected Iterator getIndexAspectIterator()
         {
            return schema.getIndexIterator();
         }

         protected Iterator getIndexPointcutIterator()
         {
            return Collections.singletonList(m_index).iterator();
         }
      }.applyAspects(2);

      if (table.isAspect())
      {
         if (!m_index.isAspect())
         {
            for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
            {
               Table pointcut = (Table)itr.next();

               if (pointcut.hasAspect(table))
               {
                  Index index = new Index(m_index.getName(pointcut), m_outline.getType(), table);

                  m_outline.copyTo(index);
                  pointcut.addIndex(index);

                  if (m_outline.getRelatedTableName() != null)
                  {
                     schema.getTable(m_outline.getRelatedTableName()).addRelatedKey(index);
                  }
View Full Code Here

         if (!index.isAspect() && index.getTable().isAspect())
         {
            for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
            {
               Table pointcut = (Table)itr.next();

               if (pointcut.hasAspect(index.getTable()))
               {
                  String sName = index.getName(pointcut);

                  if (!state.removeIndex(sName))
                  {
                     schema.removeIndex(pointcut.getIndex(sName));
                  }
               }
            }
         }
      }
View Full Code Here

    */
   public void apply(RelationalSchemaUpgradeState state)
   {
      final RelationalSchema schema = state.getSchema();

      m_table = new Table(schema);

      m_table.setType(m_nType);
      m_table.setName(m_sName);
      m_table.setQuotedName(m_sAlias);
      m_table.setTablespaceName(m_sTablespaceName);
View Full Code Here

      {
         state.removeIndex((String)itr.next());
      }

      // Apply all table-aspects to the table to get full list of indexes coming from aspects
      final Table pointcut = new Table(new RelationalSchema());
      AspectManager aspectManager = new AspectManager()
      {
         // override to avoid logging
         public void applyAspects(int nPass) throws MetadataException
         {
            if (nPass == 0)
            {
               addAspects();
            }

            for (int i = 0, n = pointcut.getAspectCount(); i < n; ++i)
            {
               Aspect aspect = pointcut.getAspect(i);

               if (m_aspectNameSet.contains(aspect.getName()))
               {
                  aspect.applyTo(pointcut, nPass);
               }
            }
         }

         protected Iterator getAspectIterator()
         {
            return schema.getTableIterator();
         }

         protected Iterator getPointcutIterator()
         {
            return Collections.singletonList(pointcut).iterator();
         }

         protected void setProperties(MetadataMarker e, Pointcut pointcut, Aspect aspect)
         {
         }
      };

      pointcut.setType(Table.EXTERNAL);
      pointcut.setName(getName());
      pointcut.setType(getType());
      addAspects(schema, pointcut);
      aspectManager.applyAspects(0);
      aspectManager.applyAspects(1);

      for (int i = pointcut.getIndexCount() - 1; i >= 0; --i)
      {
         state.removeIndex(pointcut.getIndex(i).getName());
      }
   }
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.