Package nexj.core.meta.persistence.sql

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


         {
            RelationalDenorm denorm = mapping.getDenorm(i);

            if (denorm.getTable() == m_table)
            {
               Column src = denorm.findSource(column);

               if (src != null)
               {
                  return src;
               }
View Full Code Here


      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;

         try
         {
            connection = sqlAdapter.getConnection();
            stmt = connection.getConnection().prepareStatement(buf.toString());
            rs = sqlAdapter.executeQuery(stmt);
            rs.next();

            count = rs.getObject(1);

            if (count == null)
            {
               count = Primitive.ONE_INTEGER;
            }

            count = column.getType().convert(count);
         }
         catch (SQLException e)
         {
            throw sqlAdapter.getException(e, null, 0, 0);
         }
View Full Code Here

      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());
View Full Code Here

      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

                                     getPrimaryKeyName(step.getPrimaryKeyName()).replace('.', '_'),
                                     null),
         index.getName());
      assertEquals(1, index.getIndexColumnCount());

      Column column = index.getIndexColumn(0).getColumn();

      assertEquals("id", column.getName());
      assertEquals(Primitive.INTEGER, column.getType());
   }
View Full Code Here

      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());
View Full Code Here

      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");
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);
View Full Code Here

      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();
View Full Code Here

      table = schema.getTable(schema.getPrefix() + "b");

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

      Column column = table.getColumn(0);

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

      // ensure no data loss
      Statement stmt = null;
      ResultSet rs = null;
View Full Code Here

TOP

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

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.