Package nexj.core.meta.persistence.sql

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


               m_adapter.appendBind(buf, nBindCount + nValCount++, column);
            }
         }

         // TODO: Support more than just the primary table denorm
         Table denormTable = null;

         for (int i = 0, n = m_table.getColumnCount(); i < n; ++i)
         {
            Column column = m_table.getColumn(i);

            if (getValue(i) != Undefined.VALUE)
            {
               if (nValCount != 0 || denormTable != null)
               {
                  buf.append(", ");
               }

               m_adapter.appendBind(buf, nBindCount + nValCount++, column);

               if (m_adapter.isCaseConverted(column))
               {
                  buf.append(", ");
                  m_adapter.appendCaseConvertedBind(buf, nBindCount + nValCount++, column);
               }
            }
            else
            {
               Column srcColumn = findSource(column);

               if (srcColumn != null)
               {
                  if (nValCount != 0 || denormTable != null)
                  {
                     buf.append(", ");
                  }

                  buf.append("A.");
                  buf.append(srcColumn.getQuotedName());

                  if (m_adapter.isCaseConverted(column))
                  {
                     buf.append(", ");
                     buf.append("A.");
                     m_adapter.appendCaseConvertedColumn(buf, srcColumn);
                  }

                  denormTable = srcColumn.getTable();
               }
            }
         }

         if (m_bDenorm)
         {
            buf.append(" from ");
            buf.append(denormTable.getQuotedName());
            buf.append(" A where ");

            for (int i = 0, n = pk.getIndexColumnCount(); i < n; ++i)
            {
               if (i != 0)
View Full Code Here


   /**
    * @see nexj.core.persistence.OIDGenerator#generateOID(Instance, nexj.core.persistence.PersistenceAdapter)
    */
   public OID generateOID(Instance instance, PersistenceAdapter adapter)
   {
      Table table = ((RelationalMapping)instance.getPersistenceMapping()).getPrimaryTable();
      UnitOfWork uow = instance.getUnitOfWork();
      Object key = new Pair(table, KEY);
      Object count = uow.getCachedLocal(key);

      if (count == null)
      {
         Column column = table.getPrimaryKey().getIndexColumn(0).getColumn();
         StringBuffer buf = new StringBuffer(128);

         buf.append("select max(");
         buf.append(column.getQuotedName());
         buf.append(") + 1 from ");
         buf.append(table.getQuotedName());

         SQLAdapter sqlAdapter = (SQLAdapter)adapter;
         SQLConnection connection = null;
         PreparedStatement stmt = null;
         ResultSet rs = null;
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());

      DropTableStep drop = new DropTableStep();

      table.setType(Table.MANAGED); // comes in as Table.EXTERNAL from DB
      drop.setName(m_doubleColTableStep.getName());
      upgrade(drop, schema, null);
   }
View Full Code Here

   }

   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

   }

   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();

      assertNotNull(index);
      assertEquals(
         m_manager.generateIndexName(table.getTableName(),
                                     getPrimaryKeyName(step.getPrimaryKeyName()).replace('.', '_'),
                                     null),
         index.getName());
      assertEquals(1, index.getIndexColumnCount());
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);

      assertEquals(2, index.getIndexColumnCount()); // aspect columns always before index columns
      assertEquals("value", index.getIndexColumn(0).getColumn().getName());
   }
View Full Code Here

   }

   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);
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

   }

   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);

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

   }

   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

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.