Package nexj.core.meta.persistence.sql

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


   public void testAdapterCompatibility() throws SQLException
   {
      SQLConnection connection = m_adapter.getConnection();
      Connection con = connection.getConnection();
      RelationalDatabase db = new RelationalDatabase(null);

      try
      {
         String sDBVersion = con.getMetaData().getDatabaseProductVersion();

         // iterate over DataSourceType instead of DataSource in case no DataSources defined
         for (Iterator/*<DataSourceType>*/ itr =
                 m_context.getMetadata().getDataSourceTypeIterator();
              itr.hasNext();)
         {
            db.setType((DataSourceType)itr.next());

            for (Iterator/*<DataSourceType>*/ itr2 = db.getType().getAdapterIterator();
                 itr2.hasNext();)
            {
               db.setDriver(null);
               db.setAdapter((DataSourceAdapter)itr2.next());
               db.setDefaultProperties(J2EEUtil.NONE);
               assertEquals(m_adapter.getClass().equals(db.getAdapter().getClassObject()) &&
                            isCompatibleVersion(sDBVersion),
                            m_adapter.isCompatible(con, db));
            }
         }
      }
View Full Code Here


   public void testSchemaUnicodeValidation() throws Exception
   {
      RelationalSchema schema = (RelationalSchema)m_database.getSchema();
      Table origVersionTable = schema.getVersionTable(); // note original
      Table versionTable = schema.getTable("Version");
      RelationalDatabase origDS = (RelationalDatabase)schema.getDataSource();
      RelationalDatabase ds = (RelationalDatabase)origDS.clone();

      try
      {
         schema.setDataSource(ds);
         schema.setVersionTable(versionTable);

         try
         {
            m_adapter.getVersion(schema); // one of getVersion() has to throw exception
            ds.setUnicode(!ds.isUnicode()); // try the oposite Unicode flag
            m_adapter.getVersion(schema); // one of getVersion() has to throw exception
            fail("Unicode flag validation exception expected.");
         }
         catch (UncheckedException e)
         {
            // test online upgrade prevention
            assertEquals("err.persistence.sql.unicodeMismatch", e.getErrorCode());
         }

         // ensure correct result was provided as per the created schema
         SQLConnection con = m_adapter.getConnection();
         Statement stmt = null;
         ResultSet rs = null;

         try
         {
            stmt = con.getConnection().createStatement();
            rs = stmt.executeQuery(
               "select namespace from " +
               versionTable.getFullName(m_adapter.createSchemaManager().getOwner()));

            // 1 == the namespace column
            assertEquals(Boolean.valueOf(origDS.isUnicode()), m_adapter.isUnicode(schema, rs, 1));
         }
         finally
         {
            try
            {
               if (rs != null)
               {
                  rs.close();
               }
            }
            catch (Throwable t)
            {}

            try
            {
               if (stmt != null)
               {
                  stmt.close();
               }
            }
            catch (Throwable t)
            {}

            con.decRef();
         }

         StringWriter writer = new StringWriter();
         SQLSchemaManager manager = m_adapter.createSchemaManager();

         manager.setSQLAppender(manager.new SQLWriterAppender(writer));
         manager.upgrade(schema);

         // test offline upgrade script guard generation
         assertTrue(writer.toString().contains(getUnicodeCheckGuard(ds.isUnicode())));

         ds.setUnicode(!ds.isUnicode()); // try the oposite Unicode flag
         writer = new StringWriter();
         manager.setSQLAppender(manager.new SQLWriterAppender(writer));
         manager.upgrade(schema);

         // test offline upgrade script guard generation
         assertTrue(writer.toString().contains(getUnicodeCheckGuard(ds.isUnicode())));
      }
      finally
      {
         schema.setVersionTable(origVersionTable); // reset so testUpgrade() will not fail
         schema.setDataSource(origDS); // reset to original
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.