Package nexj.core.meta.persistence.sql

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


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


      StringWriter sql = new StringWriter();

      upgrade(m_singleColTableStep, null, sql);

      ExecStep step = new ExecStep();
      SQLScript script = new SQLScript();
      SQLStatement stmt = new SQLStatement();
      String sSQL = sql.toString();
      int nSQLStmt = sSQL.indexOf(m_manager.getSeparator());

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

      assertEquals(1, table.getColumnCount());
      assertEquals("id", table.getColumn(0).getName());
      table.setType(Table.MANAGED); // comes in as Table.EXTERNAL from DB

      SQLStatement statement = new SQLStatement();
      SQLScript script = new SQLScript();
      ExecStep populate = new ExecStep();

      statement.setSQL("insert into " + table.getQuotedName() + " values (1)");
      script.addStatement(statement);
      populate.getScriptHolder().addScript(script);
      upgrade(populate, schema, null);

      RenameColumnStep step = new RenameColumnStep();
View Full Code Here

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

      SQLStatement statement = new SQLStatement();
      SQLScript script = new SQLScript();
      ExecStep populate = new ExecStep();

      statement.setSQL("insert into " + table.getQuotedName() + " values (1)");
      script.addStatement(statement);
      populate.getScriptHolder().addScript(script);
      upgrade(populate, schema, null);

      RenameTableStep step = new RenameTableStep();
      step.setOldName(table.getName());
View Full Code Here

      XMLMetadata metadata = new XMLMetadata(null, null, null, null, null);
      RelationalDatabase ds = new RelationalDatabase(null);
      RelationalSchema schema = new RelationalSchema();
      CreateTableStep step = new CreateTableStep(); // only step that can populate ViewScript
      Table table = new Table(schema);
      SQLScript finalScript = new SQLScript();
      SQLScript upgradeScript = new SQLScript();
      SQLStatement finalStmt = new SQLStatement();
      SQLStatement upgradeStmt = new SQLStatement();

      upgradeStmt.addAdapter("*", m_database.getSchema().getDataSource().getType());
      finalStmt.addAdapter("*", m_database.getSchema().getDataSource().getType());
      upgradeStmt.setSQL("upgrade view SQL");
      finalStmt.setSQL("final view SQL");
      upgradeScript.addStatement(upgradeStmt);
      finalScript.addStatement(finalStmt);
      table.setName("testTable");
      table.setType(Table.VIEW);
      step.setName(table.getName());
      step.setType(table.getType());
View Full Code Here

      schema.addTable(schema.getVersionTable());
      upgrade.setMetadata(metadata);

      // setup for first upgrade version
      ExecStep execStep = new ExecStep(); // step lacking match for current adapter
      SQLScript stepScript = new SQLScript();
      SQLStatement stepStmt = new SQLStatement();

      stepStmt.addAdapter(invalid.getName(), ds.getType());
      stepStmt.setSQL("SQLStatement SQL");
      stepScript.addStatement(stepStmt);
      execStep.getScriptHolder().addScript(stepScript);

      // single incompatible step
      metadata.setVersion("1-step");
      upgradeVersion = new RelationalSchemaUpgrade(metadata.getVersion());
      upgradeVersion.addStep(execStep);
      upgradeVersion.setDataSource(ds);
      upgrade.addVersion(upgradeVersion);

      try
      {
         upgrade.validate(null, null); // must fail since an incompatible step "1-step" exists
         fail(); // exception expected
      }
      catch (MetadataException e)
      {
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
      }

      try
      {
         manager.upgrade(schema, null); //must fail since no compatible versions found to start with
         fail(); // exception expected
      }
      catch (MetadataException e)
      {
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
      }

      try
      {
         manager.upgrade(schema, "1-step"); // must fail since step "1-step" is incompatible
         fail(); // exception expected
      }
      catch (MetadataException e)
      {
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertTrue(e.getCause() instanceof MetadataException);
         e = (MetadataException)e.getCause();
         assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
      }

      // setup for second upgrade version
      SupportAdapterStep adapterStep = new SupportAdapterStep();
      CreateTableStep createTableStep = new CreateTableStep(); // step has match for current adapter
      Table table = new Table(schema);
      SQLScript tableScript = new SQLScript();
      SQLStatement tableStmtInvalid = new SQLStatement();
      SQLStatement tableStmtValid = new SQLStatement();

      tableStmtInvalid.addAdapter(invalid.getName(), ds.getType());
      tableStmtInvalid.setSQL("SQLStatement Table SQL Invalid");
      tableStmtValid.addAdapter(ds.getAdapter().getName(), ds.getType());
      tableStmtValid.setSQL("SQLStatement Table SQL Valid");
      tableScript.addStatement(tableStmtValid);
      tableScript.addStatement(tableStmtInvalid);
      tableScript.addStatement(stepStmt);
      table.setName("Table");
      table.setType(Table.VIEW);
      table.setViewScript(tableScript);
      schema.addTable(table);
      createTableStep.setName(table.getName());
View Full Code Here

      if (ds instanceof RelationalDatabase) // SysVersion persisted in RDBMS
      {
         Table table = ((RelationalMapping)mapping).getPrimaryTable();
         RelationalSchemaUpgrade version = new RelationalSchemaUpgrade(sName);
         ExecStep step = new ExecStep();
         SQLScript script = new SQLScript();
         SQLStatement stmt = new SQLStatement();

         stmt.setSQL("update ${table:"+ table.getName() +"} set " +
                     table.getColumn("loaded").getQuotedName() + "=0");
         script.addStatement(stmt);
         step.getScriptHolder().addScript(script);
         version.setDataSource(ds);
         version.addStep(step);

         return version;
View Full Code Here

TOP

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

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.