Package nexj.core.persistence.sql

Examples of nexj.core.persistence.sql.SQLSchemaManager$DatabaseTemplateSubstReader


    */
   protected void execute(String sCommand) throws Exception
   {
      m_sCommand = sCommand;

      SQLSchemaManager manager = null;

      if (sCommand.equals("create"))
      {
         manager = getSchemaManager();
         manager.createSchema(getSchema());
      }
      else if (sCommand.equals("drop"))
      {
         manager = getSchemaManager();
         manager.dropSchema(getSchema());
      }
      else if (sCommand.equals("insert"))
      {
         generateInsertScript();
      }
      else if (sCommand.equals("truncate"))
      {
         manager = getSchemaManager();
         manager.truncateSchema(getSchema());
      }
      else if (sCommand.equals("upgrade"))
      {
         manager = getSchemaManager();
         manager.upgrade(getSchema(), getProperty("meta.start"));
      }
      else if (sCommand.equals("analyze"))
      {
         manager = getSchemaManager();
         manager.analyzeSchema(getSchema());
      }
      else if (sCommand.equals("export"))
      {
         exportSchema();
      }
      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);

               return (value == null) ? defaultValue : value;
            }

            public Object getValue(String sName)
            {
               Object value = getProperty(sName);

               return (value == null) ? getProperty("setup." + sName) : value; // also check CMD args
            }

            // thin wrapper around corresponding getProperty(...) methods
            public Object findValue(String sName) { return getValue(sName); }
            public String getClassName() { return getClass().getName(); }
            public PropertyIterator getIterator() { throw new UnsupportedOperationException(); }
            public int getValueCount() { throw new UnsupportedOperationException(); }
            public boolean hasValue(String sName) { return getValue(sName) != null; }
            public void setValue(String sName, Object value)
            {
               throw new UnsupportedOperationException();
            }
         });
      }
      else if (sCommand.equals("wrap"))
      {
         exportSchema();
         exportClasses();
      }
      else
      {
         throw new IllegalArgumentException("Invalid command \"" + sCommand + "\"");
      }

      if (manager != null && manager.getSQLAppender() instanceof SQLFileAppender)
      {
         ((SQLFileAppender)manager.getSQLAppender()).close();
      }
   }
View Full Code Here


      {
         dir.mkdirs();
      }

      File file = new File(dir, sDataSourceName + ".datasource");
      SQLSchemaManager manager = null;
      Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), XMLUtil.ENCODING);

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

            manager = getSchemaManager(getConnection());
            manager.readSchema(
               (RelationalSchema)m_database.getSchema(),
               getProperty("db.catalog"),
               getProperty("db.schema"),
               getProperty("db.table"),
               null,
               null);
         }

         StringWriter swriter = new StringWriter(0x8000);

         if (s_logger.isDebugEnabled())
         {
            s_logger.debug("Writing relational database metadata \"" + m_database.getName() +
               "\" to file \"" + file.toString() + "\"");
         }

         new XMLRelationalMetadataExporter(new XMLMetadataExporter(swriter)).exportDatabase(m_database);
         writer.write(XMLUtil.formatXML(swriter.toString()));
      }
      finally
      {
         if (manager != null)
         {
            manager.setConnection(null);
         }

         writer.close();
      }
   }
View Full Code Here

      String sFile = getRequiredProperty("sql.file")
         .replace("${cmd}", m_sCommand)
         .replace("${ds}", database.getName());
      String sOwner = getProperty("meta.owner");
      SQLAdapter adapter = (SQLAdapter)database.getComponent().getInstance(null);
      SQLSchemaManager manager = adapter.createSchemaManager(database);

      if (sOwner != null) // some SchemaManagers (e.g. DB2) will have a different default for null
      {
         manager.setOwner((sOwner.equals(".")) ? "" : sOwner);
      }

      manager.setSQLAppender(manager.new SQLFileAppender((sFile.equals("-")) ? null : new File(sFile)));

      return manager;
   }
View Full Code Here

    * @param connection The SQL connection. Can be null.
    */
   protected SQLSchemaManager getSchemaManager(Connection connection) throws SQLException
   {
      String sDataSource = (connection == null) ? getRequiredProperty("meta.datasource") : getProperty("meta.datasource") ;
      SQLSchemaManager manager;

      if (sDataSource == null)
      {
         manager = DefaultSQLSchemaManagerFactory.create(connection);
      }
      else
      {
         manager = ((SQLAdapter)getDatabase().getComponent().getInstance(null)).createSchemaManager(getDatabase());

         if (connection != null)
         {
            manager.setConnection(connection);
         }
      }

      String sOwner = getProperty("meta.owner");

      if (sOwner != null)
      {
         manager.setOwner((sOwner.equals(".")) ? "" : sOwner);
      }

      return manager;
   }
View Full Code Here

   {
      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
         {
            for (Iterator itr = dataSource.getFragmentIterator(); itr.hasNext();) // each fragment
            {
               m_context.setFragmentName(((Named)itr.next()).getName()); // connection for fragment

               try
               {
                  if (s_logger.isDebugEnabled())
                  {
                     s_logger.debug("Deleting data in data source \"" + dataSource.getName() + '"');
                  }

                  connection = adapter.getConnectionFactory().getConnection(adapter);
                  manager.setSQLAppender(new SQLSchemaManager.SQLConnectionAppender(connection, true));
                  manager.truncateSchema(schema);

                  if (s_logger.isDebugEnabled())
                  {
                     s_logger.debug("Deletion completed");
                  }
View Full Code Here

   {
      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
         {
            for (Iterator itr = dataSource.getFragmentIterator(); itr.hasNext();) // each fragment
            {
               m_context.setFragmentName(((Named)itr.next()).getName()); // connection for fragment

               try
               {
                  connection = adapter.getConnectionFactory().getConnection(adapter);
                  manager.setSQLAppender(
                     new SQLSchemaManager.SQLConnectionAppender(connection, true));

                  if (s_logger.isDebugEnabled())
                  {
                     s_logger.debug(
                        "Dropping the schema of data source \"" + dataSource.getName() + '"');
                  }

                  manager.dropSchema(schema);

                  if (s_logger.isDebugEnabled())
                  {
                     s_logger.debug("Schema dropped");
                  }
View Full Code Here

    * @param db The relational database.
    * @return The schema manager.
    */
   protected SQLSchemaManager getSchemaManager(RelationalDatabase db)
   {
      SQLSchemaManager manager = (SQLSchemaManager)m_schemaManagerMap.get(db);

      if (manager == null)
      {
         manager = getAdapter(db).createSchemaManager(db);
         m_schemaManagerMap.put(db, manager);
View Full Code Here

   {
      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
         {
            for (Iterator itr = dataSource.getFragmentIterator(); itr.hasNext();) // each fragment
            {
               m_context.setFragmentName(((Named)itr.next()).getName()); // connection for fragment

               try
               {
                  connection = adapter.getConnectionFactory().getConnection(adapter);
                  manager.setSQLAppender(
                     new SQLSchemaManager.SQLConnectionAppender(connection, false));

                  if (s_logger.isDebugEnabled())
                  {
                     s_logger.debug(
                        "Creating the schema of data source \"" + dataSource.getName() + '"');
                  }

                  manager.createSchema(schema);

                  if (s_logger.isDebugEnabled())
                  {
                     s_logger.debug("Schema created");
                  }
View Full Code Here

TOP

Related Classes of nexj.core.persistence.sql.SQLSchemaManager$DatabaseTemplateSubstReader

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.