Package nexj.core.meta.persistence.sql

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


      try
      {
         if (m_database == null)
         {
            m_database = new RelationalDatabase(sDataSourceName);
            m_database.setSchema(new RelationalSchema());

            manager = getSchemaManager(getConnection());
            manager.readSchema(
               (RelationalSchema)m_database.getSchema(),
               getProperty("db.catalog"),
View Full Code Here


      assertEquals("value", table.getColumn(1).getName());
   }

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

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

      CreateIndexStep step = new CreateIndexStep();
      IndexOutline outline = new IndexOutline();

      outline.setName("idx01");
      outline.addColumn("id", true);
      step.setTableName(table.getName());
      step.setOutline(outline);
      schema = upgrade(step, schema, null);
      table = schema.getTable(m_singleColTableStep.getName());
      assertNotNull(table);
      assertEquals(1, table.getIndexCount());

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

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

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

      assertNotNull(table);
      assertEquals(1, table.getColumnCount());

      Column column = table.getColumn(0);

      assertEquals("id", column.getName());
      assertEquals(Primitive.INTEGER, column.getType());

      // validate tablespace propagation, cannot use DB since tablespaces not defined there
      schema = new RelationalSchema();
      schema.setDataSource(m_database);
      m_singlePKColTableStep.setIndexspaceName("iSpace");
      m_singlePKColTableStep.setLongspaceName("lSpace");
      m_singlePKColTableStep.setTablespaceName("tSpace");
      m_singlePKColTableStep.apply(new RelationalSchemaUpgradeState(schema, null, null));
      table = schema.getTable(m_singlePKColTableStep.getName());
      assertNotNull(table);
      assertEquals(m_singlePKColTableStep.getIndexspaceName(), table.getIndexspaceName());
      assertEquals(m_singlePKColTableStep.getLongspaceName(), table.getLongspaceName());
      assertEquals(m_singlePKColTableStep.getTablespaceName(), table.getTablespaceName());
   }
View Full Code Here

      assertEquals(m_singlePKColTableStep.getTablespaceName(), table.getTablespaceName());
   }

   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

      assertEquals("id", table.getColumn(0).getName());
   }

   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

      assertEquals(0, table.getIndexCount());
   }

   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);
      assertNull(schema.findTable(m_singlePKColTableStep.getName()));
   }
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();)
      {
         String sName = ((DataSourceAdapter)itr.next()).getName();

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
      {
         schema.setVersionTable(schema.getTable("Version"));
         sSQL = upgrade(loadUpgrade, schema);
      }
      finally
      {
         schema.setVersionTable(origVersionTable); // reset so testUpgrade() will not fail
      }

      AssertUtil.assertContained("update test.Version set loaded=0", sSQL);
   }
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.