Package nexj.core.meta.persistence.sql

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


   protected RelationalSchema upgrade(
      RelationalSchemaUpgradeStep step, RelationalSchema schema, Writer writer)
   {
      if (schema == null)
      {
         RelationalSchema templateSchema = (RelationalSchema)m_database.getSchema();

         schema = new RelationalSchema();
         schema.setDataSource(templateSchema.getDataSource());
         schema.setIndexFill(templateSchema.getIndexFill());
         schema.setIndexspaceName(templateSchema.getIndexspaceName());
         schema.setLongspaceName(templateSchema.getLongspaceName());
         schema.setPrefix(templateSchema.getPrefix());
         schema.setRoleName(templateSchema.getRoleName());
         schema.setTablespaceName(templateSchema.getTablespaceName());

         // hints declared/used by core/test/nexj/base/upgrades/Main.upgrade, need for validation
         RelationalSchemaTest.addHint(schema, "test1");
         RelationalSchemaTest.addHint(schema, "test2");
         RelationalSchemaTest.addHint(schema, "test3");
View Full Code Here


      {
         m_doubleColTableStep.getColumnOutline("value").setPrecision(100);
         m_doubleColTableStep.getColumnOutline("value").setCaseInsensitive(Boolean.FALSE);
      }

      RelationalSchema schema = upgrade(m_doubleColTableStep, null, null);
      Table table = schema.getTable(m_doubleColTableStep.getName());

      assertNotNull(table);
      assertEquals(2, table.getColumnCount());
      table.setType(Table.MANAGED); // comes in as Table.EXTERNAL from DB

      Column column0 = table.getColumn(0);
      Column column1 = table.getColumn(1);

      assertType(Primitive.INTEGER, column0.getType());
      assertFalse(column0.isNullable());
      assertType(from, column1.getType());
      assertFalse(column1.isNullable());
      column1.setType(from); // reset to proper type since this will be required further in test

      StringBuffer buf = new StringBuffer(128);
      ExecStep exec = new ExecStep();
      SQLScript script = new SQLScript();
      SQLStatement insert = new SQLStatement();

      buf.append("insert into ");
      buf.append(table.getFullName(null));
      buf.append(" (");
      buf.append(column0.getName());
      buf.append(", ");
      buf.append(column1.getName());
      buf.append(") values (1, ");
      m_adapter.appendLiteral(buf, column1, seed);
      buf.append(")");
      insert.setSQL(buf.toString()); // ensure at least one row in table
      script.addStatement(insert);
      exec.getScriptHolder().addScript(script);
      upgrade(exec, null, null); // insert a record into the table to test altering an actual value

      AlterColumnStep step = new AlterColumnStep();
      ColumnOutline outline = new ColumnOutline("value");

      outline.setType(to);

      if (bToLOB)
      {
         outline.setAllocation(Column.LOCATOR);
      }
      else
      {
         outline.setAllocation( // set Column.FIXED/Column.VARYING as per original column
            (column1.getAllocation() == Column.LOCATOR) ? Column.VARYING : column1.getAllocation());
      }

      outline.setNullable(Boolean.FALSE);

      if (to == Primitive.BINARY || to == Primitive.STRING)
      {
         outline.setPrecision(100);
         outline.setCaseInsensitive(Boolean.FALSE);
      }

      step.setOutline(outline);
      step.setTableName(m_doubleColTableStep.getName());

      try
      {
         schema = upgrade(step, schema, null);
      }
      catch (RuntimeException e)
      {
         throw new RuntimeException("Error: alter column from: " + from + " to: " + to, e);
      }

      table = schema.getTable(m_doubleColTableStep.getName());
      assertNotNull(table);
      assertEquals(2, table.getColumnCount());
      column1 = table.getColumn(1);
      assertType(to, column1.getType());
      assertFalse(column1.isNullable());
View Full Code Here

    * @param template The schema to get configuration from (not modified).
    * @return The new schema state as read from RDBMS.
    */
   protected RelationalSchema readSchema(RelationalSchema template)
   {
      RelationalSchema schema = new RelationalSchema(); // need empty schema for readSchema()
      String sSchema = template.getPrefix(); // determine schema to avoid random tables

      if (sSchema != null)
      {
         int nSchemaSep = sSchema.indexOf('.');
         sSchema = (nSchemaSep < 0) ? null : sSchema.substring(0, nSchemaSep);
      }

      schema.setDataSource(template.getDataSource());
      schema.setIndexFill(template.getIndexFill());
      schema.setIndexspaceName(template.getIndexspaceName());
      schema.setLongspaceName(template.getLongspaceName());
      schema.setPrefix(template.getPrefix());
      schema.setRoleName(template.getRoleName());
      schema.setTablespaceName(template.getTablespaceName());
      m_manager.readSchema(schema, null, sSchema, "_", null, null); //limit to single char table

      return schema;
   }
View Full Code Here

      return schema;
   }

   public void testAlterColumnStep()
   {
      RelationalSchema schema = upgrade(m_singleColTableStep, null, null);
      Table table = schema.getTable(m_singleColTableStep.getName());

      assertNotNull(table);
      assertEquals(1, table.getColumnCount());
      table.setType(Table.MANAGED); // comes in as Table.EXTERNAL from DB

      Column column = table.getColumn(0);

      assertEquals(Primitive.INTEGER, column.getType());
      assertFalse(column.isNullable());

      AlterColumnStep step = new AlterColumnStep();
      ColumnOutline outline = new ColumnOutline("id");

      outline.setType(Primitive.STRING);
      outline.setNullable(Boolean.TRUE);
      step.setOutline(outline);
      step.setTableName(m_singleColTableStep.getName());
      schema = upgrade(step, schema, null);
      table = schema.getTable(m_singleColTableStep.getName());
      assertNotNull(table);
      assertEquals(1, table.getColumnCount());
      column = table.getColumn(0);
      assertEquals(Primitive.STRING, column.getType());
      assertTrue(column.isNullable());
View Full Code Here

      assertTrue(column.isNullable());
   }

   public void testAlterTableStep()
   {
      RelationalSchema schema = upgrade(m_singleIdxColTableStep, null, null);
      Table table = schema.getTable(m_singleIdxColTableStep.getName());

      assertNotNull(table);
      assertNull(table.getPrimaryKey());
      table.setType(Table.MANAGED); // comes in as Table.EXTERNAL from DB

      AlterTableStep step = new AlterTableStep();

      step.setName(m_singleIdxColTableStep.getName());
      step.setPrimaryKeyName(table.getIndex(0).getName());
      schema = upgrade(step, schema, null);
      table = schema.getTable(m_singleIdxColTableStep.getName());

      assertNotNull(table);

      Index index = table.getPrimaryKey();
View Full Code Here

      outline.setName("ind0");
      outline.addColumn("id", true);
      m_doubleColTableStep.addIndexOutline(outline);

      RelationalSchema schema = upgrade(m_doubleColTableStep, null, null);
      Table table = schema.getTable(m_doubleColTableStep.getName());

      assertNotNull(table);
      assertEquals(1, table.getIndexCount());
      assertEquals(1, table.getIndex(0).getIndexColumnCount());
      table.setType(Table.MANAGED); // comes in as Table.EXTERNAL from DB

      Index aspect = new Index("aspect", Index.ASPECT, null);

      aspect.addIndexColumn(new IndexColumn(table.getColumn(1), true));
      schema.addIndex(aspect);

      ApplyIndexAspectStep step = new ApplyIndexAspectStep();

      step.setAspectName(aspect.getName());
      step.addPointcutPattern(table.getIndex(0).getName(), true);
      schema = upgrade(step, schema, null);
      table = schema.getTable(m_doubleColTableStep.getName());
      assertNotNull(table);
      assertEquals(1, table.getIndexCount());

      Index index = table.getIndex(0);
View Full Code Here

      assertEquals("value", index.getIndexColumn(0).getColumn().getName());
   }

   public void testApplyTableAspectStep()
   {
      RelationalSchema schema = upgrade(m_singleColTableStep, null, null);
      Table table = schema.getTable(m_singleColTableStep.getName());

      assertNotNull(table);
      assertEquals(1, table.getColumnCount());
      table.setType(Table.MANAGED); // comes in as Table.EXTERNAL from DB

      Table aspect = new Table(schema);
      Column column = new Column("value", aspect);

      aspect.setName(m_manager.getFullTableName(null, "aspect"));
      aspect.setType(Table.ASPECT);
      column.setType(Primitive.STRING);
      aspect.addColumn(column);

      ApplyTableAspectStep step = new ApplyTableAspectStep();

      step.setAspectName(aspect.getName());
      step.addPointcutPattern(table.getName(), true);
      schema.addTable(aspect);
      schema = upgrade(step, schema, null);
      table = schema.getTable(m_singleColTableStep.getName());
      assertNotNull(table);
      assertEquals(2, table.getColumnCount());
      assertEquals("id", table.getColumn(0).getName());
      assertEquals("value", table.getColumn(1).getName());
   }
View Full Code Here

      }
   }

   public void testCreateColumnStep()
   {
      RelationalSchema schema = upgrade(m_singleColTableStep, null, null);
      Table table = schema.getTable(m_singleColTableStep.getName());

      assertNotNull(table);
      assertEquals(1, table.getColumnCount());
      table.setType(Table.MANAGED); // comes in as Table.EXTERNAL from DB

      CreateColumnStep step = new CreateColumnStep();
      ColumnOutline column = new ColumnOutline("value");

      column.setType(Primitive.STRING);
      step.setTableName(m_singleColTableStep.getName());
      step.setOutline(column);
      schema = upgrade(step, schema, null);
      table = schema.getTable(m_singleColTableStep.getName());
      assertNotNull(table);
      assertEquals(2, table.getColumnCount());
      assertEquals("value", table.getColumn(1).getName());
   }
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))
            {
View Full Code Here

   public void undo(RelationalSchemaUpgradeState state)
   {
      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))
               {
View Full Code Here

TOP

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

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.