Package nexj.core.meta.persistence.sql

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


   }

   public void testDropColumnStep()
   {
      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

      DropColumnStep step = new DropColumnStep();

      step.setName("value");
      step.setTableName(table.getName());
      schema = upgrade(step, schema, null);
      table = schema.getTable(m_doubleColTableStep.getName());
      assertNotNull(table);
      assertEquals(1, table.getColumnCount());
      assertEquals("id", table.getColumn(0).getName());
   }
View Full Code Here


   }

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

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

      DropIndexStep step = new DropIndexStep();

      step.setName(table.getIndex(0).getName());
      schema = upgrade(step, schema, null);
      table = schema.getTable(m_singleIdxColTableStep.getName());
      assertNotNull(table);
      assertEquals(0, table.getIndexCount());
   }
View Full Code Here

   }

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

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

      DropTableStep step = new DropTableStep();

      step.setName(m_singlePKColTableStep.getName());
      schema = upgrade(step, schema, null);
View Full Code Here

   public void testDropUpgradeSchema()
   {
      SQLAppender origAppender = m_manager.getSQLAppender();
      RelationalSchema schema = new RelationalSchema(); // schema used for dropTable step
      Table table = new Table(schema);
      StringWriter sql = new StringWriter();
      DropTableStep dropStep = new DropTableStep();
      String sDropSQL;

      table.setName("test.A"); // this table exists in Main.upgrade
      schema.addTable(table);
      schema.setDataSource(m_database);
      dropStep.setName(table.getName());
      m_manager.m_state = new RelationalSchemaUpgradeState(schema, null, null); // required for drop
      m_manager.setSQLAppender(m_manager.new SQLWriterAppender(sql));

      try
      {
View Full Code Here

      stmt.setSQL((nSQLStmt < 0) ? sSQL : sSQL.substring(0, nSQLStmt)); // only first statement
      script.addStatement(stmt);
      step.getScriptHolder().addScript(script);

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

      assertNotNull(table);
      assertEquals(Table.EXTERNAL, table.getType()); // comes in as Table.EXTERNAL from DB

      DataSource ds = schema.getDataSource();

      for (Iterator/*<DataSourceAdapter>*/ itr = ds.getType().getAdapterIterator(); itr.hasNext();)
      {
View Full Code Here

         (RelationalSchemaUpgradeState)Upgrade.getState(Upgrade.getInitialState(version), version);

      assertNull(state.getSchema().findTable("A"));
      version.getStep(0).apply(state); // CreateTable

      Table table = state.getSchema().getTable("A");
      Iterator/*<String>*/ itr = table.getHintIterator();

      itr.next(); // 1st hint
      itr.next(); // 2nd hint
      assertFalse(itr.hasNext());
      assertTrue(table.isHintEnabled("test1"));
      assertTrue(table.isHintEnabled("test2"));
      version.getStep(1).apply(state); // AlterTable

      itr = table.getHintIterator();
      itr.next(); // 1st hint
      itr.next(); // 2nd hint
      assertFalse(itr.hasNext());
      assertTrue(table.isHintEnabled("test1"));
      assertTrue(table.isHintEnabled("test3"));
   }
View Full Code Here

   public void testIndexDiscardState()
   {
      SQLAppender origAppender = m_manager.getSQLAppender();
      RelationalSchema schema = new RelationalSchema();
      Table table = new Table(schema);
      Column column = new Column("col", table);
      Index index = new Index("indx", Index.CLUSTER, table);

      table.setName("test"); // table name required to add table to schema, to add index to schema
      schema.addTable(table);
      column.setType(Primitive.INTEGER);
      table.addColumn(column);
      index.addIndexColumn(new IndexColumn(column, true));
      table.addIndex(index);
      table.setPrimaryKey(index);
      schema.setDataSource(m_database);

      // validate initial schema state
      assertEquals(1, schema.getIndexCount());
      assertEquals(index, schema.findIndex("indx"));

      try
      {
         m_manager.setSQLAppender(m_manager.new SQLWriterAppender(new StringWriter()));
         m_manager.discardIndex(index, true);
      }
      finally
      {
         m_manager.setSQLAppender(origAppender);
      }

      // schema definition is untouched
      assertEquals(1, schema.getIndexCount());
      assertEquals(index, schema.findIndex("indx"));

      // index either removed or renamed
      assertTrue(table.getIndexCount() == 0 || !index.getName().equals("indx"));
   }
View Full Code Here

   public void testLoad()
   {
      Metadata metadata = getMetadata();
      RelationalSchema schema = (RelationalSchema)m_database.getSchema();
      Table origVersionTable = schema.getVersionTable(); // note original
      VersionUpgrade loadUpgrade = LoadUpgrade.create(metadata.getVersion(), metadata, null, null);
      String sSQL;

      try
      {
View Full Code Here

      outline.addColumn("id", true);
      outline.addColumn("value", 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(2, 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("value"), true));
      table.getIndex(0).addAspect(aspect);
      schema.addIndex(aspect);

      RemoveIndexAspectStep step = new RemoveIndexAspectStep();

      step.setAspectName("aspect");
      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);

      assertEquals(1, index.getIndexColumnCount());
      assertEquals("id", index.getIndexColumn(0).getColumn().getName());
   }
View Full Code Here

   }

   public void testRemoveTableAspectStep()
   {
      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

      Table aspect = new Table(schema);

      aspect.setName(m_manager.getFullTableName(null, "aspect"));
      aspect.setType(Table.ASPECT);
      aspect.addColumn(new Column("value", aspect));
      table.addAspect(aspect);
      schema.addTable(aspect);

      RemoveTableAspectStep step = new RemoveTableAspectStep();

      step.setAspectName(aspect.getName());
      step.addPointcutPattern(table.getName(), true);
      schema = upgrade(step, schema, null);
      table = schema.getTable(m_doubleColTableStep.getName());
      assertNotNull(table);
      assertEquals(1, table.getColumnCount());
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.