Package nexj.core.meta.persistence.sql

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


      }
      else if (sCommand.equals("setup"))
      {
         Metadata metadata = new MetadataLoaderDispatcher().load(null, null,
            MetadataLoader.DATASOURCE_ONLY | MetadataLoader.INTEGRATION_EXCLUDED, null);
         RelationalDatabase database = getDatabase(metadata);

         manager = getSchemaManager(database);
         manager.createDatabase((RelationalSchema)database.getSchema(), new PropertyMap()
         {
            public Object findValue(String sName, Object defaultValue)
            {
               Object value = getValue(sName);
View Full Code Here


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

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

   public void testViewScriptUpgradeMismtch()
   {
      Upgrade upgrade = new Upgrade(null);
      RelationalSchemaUpgrade version = new RelationalSchemaUpgrade("test");
      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());
      step.setViewScript(upgradeScript);
      schema.addTable(table);
      schema.setDataSource(ds);
      ds.setAdapter(m_database.getSchema().getDataSource().getAdapter());
      ds.setSchema(schema);
      ds.setType(new DataSourceType(null));
      ds.getType().setMetadata(metadata);
      version.setDataSource(ds);
      version.addStep(step);
      metadata.setVersion(version.getName());
      upgrade.setMetadata(metadata);
      upgrade.addVersion(version);
View Full Code Here

   public void testUpgradeValidation()
   {
      StringWriter buf = new StringWriter();
      DataSourceAdapter invalid = new DataSourceAdapter("InvalidAdapter");
      DataSourceAdapter valid = new DataSourceAdapter("ValidAdapter");
      RelationalDatabase ds = new RelationalDatabase("DataSource");
      RelationalSchema schema = new RelationalSchema();
      final Upgrade upgrade = new Upgrade(null);
      XMLMetadata metadata = new XMLMetadata(null, null, null, null, null)
      {
         public Upgrade getUpgrade(String sName) { return upgrade; }
      };
      SQLSchemaManager manager = m_adapter.createSchemaManager();
      RelationalSchemaUpgrade upgradeVersion;

      ds.setAdapter(valid);
      ds.setComponent(new Component("Component"));
      ds.setSchema(schema);
      ds.setType(new DataSourceType("DataSourceType"));
      ds.getType().setMetadata(metadata);
      ds.getType().addAdapter(ds.getAdapter());
      ds.getType().addAdapter(invalid);
      ((RelationalDatabaseFragment)ds.getDefaultFragment()).setDatabase("Database");
      metadata.addDataSource(ds);
      manager.setSQLAppender(manager.new SQLWriterAppender(buf));
      schema.setVersionTable(new Table(schema));
      schema.getVersionTable().setName("VersionTable");
      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());
      createTableStep.setType(table.getType());
      createTableStep.setViewScript(tableScript);
      adapterStep.setAdapter(invalid);

      // incompatible step -> compatible step
      metadata.setVersion("2-step");
      upgradeVersion = new RelationalSchemaUpgrade(metadata.getVersion());
      upgradeVersion.addStep(adapterStep);
      upgradeVersion.addStep(createTableStep);
      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 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());
      }

      buf.getBuffer().setLength(0);
      ds.setAdapter(invalid);
      manager.upgrade(schema, "2-step"); // validation of invalid adapter should not be prevented
      AssertUtil.assertContained(tableStmtInvalid.getSQL(), buf.toString());
      ds.setAdapter(valid);

      try
      {
         manager.upgrade(schema, "2-step"); // must fail since validating current adapter from start
         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());
      }

      adapterStep.setAdapter(ds.getAdapter());
      upgrade.validate(null, null); // must pass since adapter validation from "2-step"
      buf.getBuffer().setLength(0);
      manager.upgrade(schema, null); // must upgrade starting from "2-step"
      AssertUtil.assertContained(tableStmtValid.getSQL(), buf.toString());
View Full Code Here

       */
      public void addJMSDBApplicationPolicy(Element policies, JDBCConnectionInfo jmsJDBCConnInfo)
      {
         if (jmsJDBCConnInfo != null)
         {
            RelationalDatabase db = jmsJDBCConnInfo.getBackingDB();
            RelationalDatabaseFragment dbFragment = (RelationalDatabaseFragment)db.getDefaultFragment();

            addApplicationPolicy(policies, getJAASDomain(dbFragment), LOCAL_TX_JCA_SERVICE_NAME,
               SysUtil.NAMESPACE + "/jms/jdbc/" + dbFragment.getAlias(), dbFragment.getUser(), dbFragment.getPassword());
         }
      }
View Full Code Here

      /**
       * @see nexj.core.admin.platform.jboss.JBossInstaller.JBossInstallerStrategy#addJMSDBApplicationPolicy(org.w3c.dom.Element, java.lang.String, RelationalDatabase)
       */
      public void addJMSDBApplicationPolicy(Element policies, JDBCConnectionInfo jmsJDBCConnInfo)
      {
         RelationalDatabase db = jmsJDBCConnInfo.getBackingDB();
         RelationalDatabaseFragment dbFragment = (RelationalDatabaseFragment)db.getDefaultFragment();

         addApplicationPolicy(policies, getJAASDomain(dbFragment), LOCAL_TX_JCA_SERVICE_NAME,
            SysUtil.NAMESPACE + "/jms/jdbc/" + dbFragment.getAlias(), dbFragment.getUser(), dbFragment.getPassword());
      }
View Full Code Here

       * @return JDBCConnectionInfo containing the derived RelationalDatabase and additional  connection info.
       */
      protected JDBCConnectionInfo getDerivedJMSDBConnectionInfo()
      {
         String sJMSDBName = "JMS_DATABASE";
         RelationalDatabase defaultDB = getDefaultDatabase();
         RelationalDatabaseFragment defaultDBFragment = (RelationalDatabaseFragment)defaultDB.getDefaultFragment();

         RelationalDatabase jmsDB = new RelationalDatabase(sJMSDBName);
         RelationalDatabaseFragment jmsDBFragment = (RelationalDatabaseFragment)jmsDB.getDefaultFragment();

         jmsDB.setAdapter(defaultDB.getAdapter());
         jmsDB.setComponent(defaultDB.getComponent());
         jmsDB.setDriver(defaultDB.getDriver());
         jmsDB.setAlias(sJMSDBName);
         jmsDB.setUnicode(false);

         jmsDBFragment.setAlias(sJMSDBName + jmsDBFragment.getSuffix());
         jmsDBFragment.setDefaultProperties(J2EEUtil.JBOSS);
         jmsDBFragment.setHost(defaultDBFragment.getHost());
         jmsDBFragment.setPort(defaultDBFragment.getPort());
View Full Code Here

         map.setValue("password", null);

         return map;
      }

      RelationalDatabase rd = (RelationalDatabase)schema.getDataSource();
      RelationalDatabaseFragment rdf = (RelationalDatabaseFragment)rd.getDefaultFragment();
      String sIndexspace = ((RelationalDatabase)schema.getDataSource()).getIndexspaceName();
      String sLongspace = ((RelationalDatabase)schema.getDataSource()).getLongspaceName();
      String sTablespace = ((RelationalDatabase)schema.getDataSource()).getTablespaceName();

      sIndexspace = (sIndexspace == null) ? schema.getIndexspaceName() : sIndexspace;
      sLongspace = (sLongspace == null) ? schema.getLongspaceName() : sLongspace;
      sTablespace = (sTablespace == null) ? schema.getTablespaceName() : sTablespace;

      map.setValue("adapter", rd.getAdapter().getName());
      map.setValue("database", rdf.getDatabase());
      map.setValue("host", rdf.getHost());
      map.setValue("indexfill",
                   (schema.getIndexFill() == 0) ? null : Byte.valueOf(schema.getIndexFill()));
      map.setValue("indexspace", (DEFAULT_TABLESPACE.equals(sIndexspace)) ? null : sIndexspace);
      map.setValue("instance", rdf.getInstance());
      map.setValue("longspace", (DEFAULT_TABLESPACE.equals(sLongspace)) ? null : sLongspace);
      map.setValue("pagesize",
                   (rd.getPageSize() == 0) ? null : Primitive.createInteger(rd.getPageSize()));
      map.setValue("port", (rdf.getPort() == 0) ? null : Primitive.createInteger(rdf.getPort()));
      map.setValue("role", schema.getRoleName());
      map.setValue("tablespace", (DEFAULT_TABLESPACE.equals(sTablespace)) ? null : sTablespace);
      map.setValue("user", rdf.getUser());
      map.setValue("password", rdf.getPassword());
View Full Code Here

    */
   protected Boolean isUnicode(RelationalSchema schema, ResultSet rs, int nColumn)
      throws SQLException
   {
      ResultSetMetaData rsMeta = rs.getMetaData();
      RelationalDatabase ds = (RelationalDatabase)schema.getDataSource();
      StringBuffer buf = new StringBuffer(128);

      // the table_schema column actually contains the database name
      // rsMeta.getSchemaName(nColumn) returns empty string
      buf.append("select character_set_name from information_schema.columns where table_schema=");
      appendLiteral(buf, ((RelationalDatabaseFragment)ds.getDefaultFragment()).getDatabase());
      buf.append(" and table_name=");
      appendLiteral(buf, rsMeta.getTableName(nColumn));
      buf.append(" and column_name=");
      appendLiteral(buf, rsMeta.getColumnName(nColumn));

View Full Code Here

       * @param connection The resource connection
       * @param location The server location
       */
      public void install(ResourceConnection connection, Location location, int nNodeIdx) throws Exception
      {
         RelationalDatabase defaultDatabase = getDefaultDatabase();

         installTrustStore(connection.getResource(location.getConfigDir(), TRUST_STORE_FILE_NAME));

         installPropertiesService(connection.getResource(location.getDeploymentDir(), PROPERTIES_SERVICE_FILE_NAME));
         installDataSource(connection.getResource(location.getDeploymentDir(), DATASOURCE_FILE_NAME));
View Full Code Here

TOP

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

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.