Package nexj.core.meta.persistence.sql

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


       * @param jmsDBConnectionInfo The JMS data source connection info
       * @throws IOException
       */
      public void installPersistenceService(ResourceConnection connection, Location location, JDBCConnectionInfo jmsDBConnectionInfo) throws IOException
      {
         RelationalDatabase jmsDB = (jmsDBConnectionInfo != null) ? jmsDBConnectionInfo.getBackingDB() : getDefaultDatabase();

         if (jmsDB != null)
         {
            String sPersistenceFilenamePrefix = JDBCInfo.getInstance(jmsDB.getDriver(), jmsDB.getAdapter().getName()).getDBTypeName().toLowerCase(Locale.ENGLISH);
            String sTemplateFileName = PERSISTENCE_SERVICE_TEMPLATE_DIR_NAME + sPersistenceFilenamePrefix + getPersistenceServiceTemplateFileSuffix();
            Resource templateFile =  connection.getResource(location.getBaseDir(), PERSISTENCE_SERVICE_TEMPLATE_HOME_DIR_NAME + sTemplateFileName);

            if (!templateFile.exists())
            {
View Full Code Here


      {
         DataSource ds = (DataSource)dsItr.next();

         if (ds.isEnabled() && ds instanceof RelationalDatabase)
         {
            RelationalDatabase db = (RelationalDatabase)ds;

            for (Iterator fragmentItr = db.getFragmentIterator(); fragmentItr.hasNext();)
            {
               RelationalDatabaseFragment fragment = (RelationalDatabaseFragment)fragmentItr.next();

               addDataSource(doc, db, fragment, null, SysUtil.NAMESPACE + "/jdbc/");
            }
View Full Code Here

      {
         DataSource ds = (DataSource)dsItr.next();

         if (ds.isEnabled() && ds instanceof RelationalDatabase)
         {
            RelationalDatabase dataBase = (RelationalDatabase)ds;

            for (Iterator fragmentItr = dataBase.getFragmentIterator(); fragmentItr.hasNext();)
            {
               RelationalDatabaseFragment fragment = (RelationalDatabaseFragment)fragmentItr.next();

               if (fragment.isFirst())
               {
View Full Code Here

    */
   public void deleteData(DataSource dataSource) throws Exception
   {
      if (dataSource instanceof RelationalDatabase)
      {
         RelationalDatabase database = (RelationalDatabase)dataSource;
         SQLAdapter adapter = (SQLAdapter)database.getComponent().getInstance(m_context);
         SQLSchemaManager manager = adapter.createSchemaManager(database);
         RelationalSchema schema = (RelationalSchema)database.getSchema();
         String sOrigFragment = m_context.getFragmentName();
         Connection connection = null;

         try
         {
View Full Code Here

         throw new RuntimeException("Please ensure that all of the following jms.jdbc.* properties " +
            "are specified for a custom JMS data source: url, driver, user, password");
      }

      JDBCInfo jdbcInfo = JDBCInfo.getInstance(sJMSDBURL);
      RelationalDatabase jmsDB = new RelationalDatabase(sJMSDBName);
      RelationalDatabaseFragment jmsDBFragment = (RelationalDatabaseFragment)jmsDB.getDefaultFragment();

      jmsDB.setAlias(sJMSDBName);
      jmsDB.setUnicode(false);
      jmsDB.setAdapter(new DataSourceAdapter(jdbcInfo.getDBTypeName()));
      jmsDBFragment.setAlias(sJMSDBName + jmsDBFragment.getSuffix());
      jmsDBFragment.setUser(sJMSDBUser);
      jmsDBFragment.setPassword(sJMSDBPassword);

      int nMinPoolSize;
View Full Code Here

    */
   public void dropSchema(DataSource dataSource) throws Exception
   {
      if (dataSource instanceof RelationalDatabase)
      {
         RelationalDatabase database = (RelationalDatabase)dataSource;
         SQLAdapter adapter = (SQLAdapter)database.getComponent().getInstance(m_context);
         SQLSchemaManager manager = adapter.createSchemaManager(database);
         RelationalSchema schema = (RelationalSchema)database.getSchema();
         String sOrigFragment = m_context.getFragmentName();
         Connection connection = null;

         try
         {
View Full Code Here

    */
   public void createSchema(DataSource dataSource) throws Exception
   {
      if (dataSource instanceof RelationalDatabase)
      {
         RelationalDatabase database = (RelationalDatabase)dataSource;
         SQLAdapter adapter = (SQLAdapter)database.getComponent().getInstance(m_context);
         SQLSchemaManager manager = adapter.createSchemaManager(database);
         RelationalSchema schema = (RelationalSchema)database.getSchema();
         String sOrigFragment = m_context.getFragmentName();
         Connection connection = null;

         try
         {
View Full Code Here

      if (schema == null)
      {
         return null;
      }

      RelationalDatabase db = (RelationalDatabase)schema.getDataSource();
      Table table = ((RelationalSchema)schema).getVersionTable();
      Metadata metadata = m_context.getMetadata();

      if (metadata.getNamespace() == null || table == null)
      {
         return null;
      }

      Column namespaceColumn = table.getColumn("namespace");
      Column versionColumn = table.getColumn("version");
      Column stepColumn = table.getColumn("step");
      Column upgradableColumn = table.getColumn("upgradable");
      Column testColumn = table.getColumn("test");
      StringBuffer buf = new StringBuffer(128);

      buf.append("select ");
      buf.append(namespaceColumn.getQuotedName());
      buf.append(", ");
      buf.append(versionColumn.getQuotedName());
      buf.append(", ");
      buf.append(stepColumn.getQuotedName());
      buf.append(", ");
      buf.append(upgradableColumn.getQuotedName());
      buf.append(", ");
      buf.append(testColumn.getQuotedName());
      buf.append(" from ");
      buf.append(table.getQuotedName());

      String sSQL = buf.toString();
      SQLConnection connection = null;
      PreparedStatement stmt = null;

      try
      {
         connection = getConnection();

         log(sSQL);

         Connection con = connection.getConnection();

         if (!isCompatible(con, db))
         {
            String sDBName = con.getMetaData().getDatabaseProductName();
            String sDBVersion = con.getMetaData().getDatabaseProductVersion();

            throw new PersistenceException("err.persistence.adapterMismatch",
               new Object[]{db.getName(), db.getAdapter().getName(),
                  (sDBVersion.contains(sDBName)) ? sDBVersion : (sDBName + " " + sDBVersion)});
         }

         stmt = con.prepareStatement(sSQL);

         ResultSet rs = executeQuery(stmt);

         if (!rs.next())
         {
            throw new PersistenceException("err.persistence.noStorageVersion",
               new Object[]{db.getName()});
         }

         SchemaVersion version = new SchemaVersion();

         version.setNamespace(Primitive.toString(getBind(namespaceColumn).getValue(rs, 0, this)));
         version.setVersion(Primitive.toString(getBind(versionColumn).getValue(rs, 1, this)));

         Integer step = Primitive.toInteger(getBind(stepColumn).getValue(rs, 2, this));

         version.setStep((step == null) ? -1 : step.intValue());

         Boolean upgradable = Primitive.toBoolean(getBind(upgradableColumn).getValue(rs, 3, this));

         version.setUpgradable((upgradable == null) ? false : upgradable.booleanValue());

         Boolean test = Primitive.toBoolean(getBind(testColumn).getValue(rs, 4, this));

         version.setTest((test == null) ? false : test.booleanValue());

         // has to be done while still have data in ResultSet on DB2
         Boolean unicode = isUnicode((RelationalSchema)schema, rs, 1); // 1 == "namespace" column
         boolean bUnicode = db.isUnicode();

         if (unicode == null)
         {
            throw new PersistenceException(
               "err.persistence.sql.unicodeUnknown",
               new Object[]{db.getName(), Boolean.valueOf(bUnicode)});
         }

         if (unicode.booleanValue() != bUnicode)
         {
            throw new PersistenceException(
               "err.persistence.sql.unicodeMismatch",
               new Object[]{db.getName(), Boolean.valueOf(bUnicode)});
         }

         if (rs.next())
         {
            throw new PersistenceException("err.persistence.ambiguousStorageVersion",
               new Object[]{db.getName()});
         }

         return version;
      }
      catch (SQLException e)
      {
         throw new PersistenceException("err.persistence.checkVersion",
            new Object[]{db.getName()}, e);
      }
      finally
      {
         close(stmt);
View Full Code Here

    * @see nexj.core.persistence.sql.SQLSchemaManager#appendUpgradeStepStart(java.lang.StringBuffer, nexj.core.meta.persistence.sql.RelationalSchema, nexj.core.persistence.SchemaVersion)
    * Note: Have to create a separate procedure for each step because MySQL will have trouble processing the packet size if all steps are in one long procedure.
    */
   protected void appendUpgradeStepStart(StringBuffer buf, RelationalSchema schema, SchemaVersion version)
   {
      RelationalDatabase ds = (RelationalDatabase)schema.getDataSource();

      buf.append("delimiter /");
      buf.append(SysUtil.LINE_SEP);
      buf.append("create procedure _upgrade()");
      buf.append(SysUtil.LINE_SEP);
      buf.append("begin");
      buf.append(SysUtil.LINE_SEP);

      // the table_schema column actually contains the database name
      buf.append("   if exists (select 1");
         appendVersionTableFrom(buf, schema, version);
      buf.append(") and exists(select character_set_name from information_schema.columns");
      buf.append(" where table_schema=");
      m_adapter.appendLiteral(
         buf, ((RelationalDatabaseFragment)ds.getDefaultFragment()).getDatabase());
      buf.append(" and table_name=");
      m_adapter.appendLiteral(buf, schema.getVersionTable().getTableName());
      buf.append(" and column_name=");
      m_adapter.appendLiteral(buf, "namespace");
      buf.append(" and character_set_name");
      buf.append((ds.isUnicode()) ? "" : " is not null and character_set_name!");
      buf.append('=');
      m_adapter.appendLiteral(buf, "utf8");
      buf.append(')');
      buf.append(SysUtil.LINE_SEP);
      buf.append("   then");
View Full Code Here

      }

      m_managedFactory = (SQLManagedConnectionFactory)Class.forName(
            SysUtil.PACKAGE + ".core.rpc.sql.ra.SQLManagedConnectionFactory").newInstance();

      RelationalDatabase ds = (RelationalDatabase)m_fragment.getDataSource();

      m_managedFactory.setStatementCacheSize(m_fragment.getStatementCacheSize());
      m_managedFactory.setName(ds.getName());
      m_managedFactory.setDataSource(ds.getDriver());
      m_managedFactory.setPassword(m_fragment.getPassword());
      m_managedFactory.setProperties(
         PropertyUtil.toString(m_fragment.getPropertyHolder().getProperties()));
      m_managedFactory.setUser(m_fragment.getUser());
      m_managedFactory.setInitialSQL(m_sInitialSQL);
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.