db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/metadata/auto AutoCreatorDb.java
Date Tue, 24 Dec 2002 13:07:03 GMT
arminw      2002/12/24 05:07:03

  Modified:    src/java/org/apache/ojb/broker/metadata/auto
                        AutoCreatorDb.java
  Log:
  adjust to new metadata handling
  
  Revision  Changes    Path
  1.9       +34 -46    jakarta-ojb/src/java/org/apache/ojb/broker/metadata/auto/AutoCreatorDb.java
  
  Index: AutoCreatorDb.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/auto/AutoCreatorDb.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AutoCreatorDb.java	1 Dec 2002 11:48:38 -0000	1.8
  +++ AutoCreatorDb.java	24 Dec 2002 13:07:03 -0000	1.9
  @@ -7,6 +7,18 @@
    */
   package org.apache.ojb.broker.metadata.auto;
   
  +import com.crossdb.sql.AlterTableQuery;
  +import com.crossdb.sql.Column;
  +import com.crossdb.sql.CreateTableQuery;
  +import com.crossdb.sql.SQLFactory;
  +import com.crossdb.sql.SelectQuery;
  +import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.metadata.DescriptorRepository;
  +import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
  +
   import java.sql.Connection;
   import java.sql.DatabaseMetaData;
   import java.sql.ResultSet;
  @@ -15,37 +27,18 @@
   import java.sql.Statement;
   import java.util.ArrayList;
   import java.util.Enumeration;
  -import java.util.Hashtable;
   import java.util.List;
   
  -import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.accesslayer.ConnectionFactory;
  -import org.apache.ojb.broker.accesslayer.ConnectionFactoryNotPooledImpl;
  -import org.apache.ojb.broker.accesslayer.LookupException;
  -import org.apache.ojb.broker.metadata.ClassDescriptor;
  -import org.apache.ojb.broker.metadata.DescriptorRepository;
  -import org.apache.ojb.broker.metadata.FieldDescriptor;
  -import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  -import org.apache.ojb.broker.singlevm.PersistenceBrokerImpl;
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  -
  -import com.crossdb.sql.AlterTableQuery;
  -import com.crossdb.sql.Column;
  -import com.crossdb.sql.CreateTableQuery;
  -import com.crossdb.sql.SQLFactory;
  -import com.crossdb.sql.SelectQuery;
  -
   public class AutoCreatorDb
   {
       private static Logger logger = LoggerFactory.getLogger(AutoCreatorDb.class);
   
       /**
        * com.spaceprogram.sql.hsqldb.HsqldbFactory
  -    com.spaceprogram.sql.mysql.MySQLFactory
  -    com.thinkvirtual.sql.oracle.OracleSQLFactory
  -    com.thinkvirtual.sql.sqlserver.SQLServerFactory
  -    com.thinkvirtual.sql.sybase.SybaseFactory
  +     com.spaceprogram.sql.mysql.MySQLFactory
  +     com.thinkvirtual.sql.oracle.OracleSQLFactory
  +     com.thinkvirtual.sql.sqlserver.SQLServerFactory
  +     com.thinkvirtual.sql.sybase.SybaseFactory
        */
       public static String getCrossdbDriverFromPlatform(String platform)
       {
  @@ -79,17 +72,14 @@
       }
   
       public static void autoCreate(
  -        DescriptorRepository descriptorRepository,
  -//        PersistenceBrokerImpl persistenceBroker,
  -        Connection connection)
  +            DescriptorRepository descriptorRepository, ConnectionManagerIF conMan)
       {
  -
           String crossdbDriver =
  -            getCrossdbDriverFromPlatform(descriptorRepository.getDefaultJdbcConnection().getDbms());
  -
  +                getCrossdbDriverFromPlatform(conMan.getConnectionDescriptor().getDbms());
  +        Connection connection = null;
           try
           {
  -
  +            connection = conMan.getConnection();
               Class factory_class = Class.forName(crossdbDriver);
               // put the implementation string into forName()
               SQLFactory factory = (SQLFactory) (factory_class.newInstance());
  @@ -97,7 +87,7 @@
               List tableNames = new ArrayList();
               DatabaseMetaData dmd = connection.getMetaData();
   
  -            String types[] = { "TABLE" };
  +            String types[] = {"TABLE"};
               ResultSet rs = dmd.getTables(null, null, null, types);
               //System.out.println("TABLES IN DB:");
   
  @@ -148,12 +138,12 @@
                           {
                               // alter table to add column
                               logger.info(
  -                                "Altering table [" + tname + "] - adding column [" + colname
+ "]");
  +                                    "Altering table [" + tname + "] - adding column ["
+ colname + "]");
                               AlterTableQuery altq = factory.getAlterTableQuery();
                               altq.setTable(tname);
   
                               altq.addColumn(
  -                                new Column(colname, fieldDescriptor.getColumnJdbcType()));
  +                                    new Column(colname, fieldDescriptor.getColumnJdbcType()));
                               altq.execute(st);
                           }
                       }
  @@ -188,21 +178,19 @@
   
               }
           }
  -        catch (SQLException e)
  +        catch (Exception e)
           {
  -            e.printStackTrace();
  +            logger.error("", e);
           }
  -        catch (ClassNotFoundException e)
  +        finally
           {
  -            e.printStackTrace(); //To change body of catch statement use Options | File
Templates.
  -        }
  -        catch (InstantiationException e)
  -        {
  -            e.printStackTrace(); //To change body of catch statement use Options | File
Templates.
  -        }
  -        catch (IllegalAccessException e)
  -        {
  -            e.printStackTrace(); //To change body of catch statement use Options | File
Templates.
  +            try
  +            {
  +                if(connection != null) connection.close();
  +            }
  +            catch (SQLException ignore)
  +            {
  +            }
           }
       }
   
  
  
  

Mime
View raw message