db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject cvs commit: db-ojb .classpath build.xml
Date Sun, 11 Dec 2005 20:07:10 GMT
tomdz       2005/12/11 12:07:10

  Modified:    src/java/org/apache/ojb/broker/util/dbhandling
                        PreparedModel.java DatabaseHandlingTask.java
                        DataSet.java
               .        .classpath build.xml
  Added:       lib      commons-betwixt-0.8-dev.jar DdlUtils-1.0-dev.jar
               src/java/org/apache/ojb/broker/util/dbhandling
                        DdlUtilsDataHandling.java
                        DdlUtilslDatabaseHandling.java
  Removed:     lib      commons-betwixt-0.7RC2.jar commons-sql-1.0-dev.jar
               src/java/org/apache/ojb/broker/util/dbhandling
                        CommonsSqlDatabaseHandling.java
                        CommonsSqlDataHandling.java
  Log:
  Changed database handling to use DdlUtils instead of commons-sql (should fix the gump failures)
  
  Revision  Changes    Path
  1.2       +1214 -0   db-ojb/lib/commons-betwixt-0.8-dev.jar
  
  	<<Binary file>>
  
  
  1.2       +897 -0    db-ojb/lib/DdlUtils-1.0-dev.jar
  
  	<<Binary file>>
  
  
  1.4       +30 -14    db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/PreparedModel.java
  
  Index: PreparedModel.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/PreparedModel.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PreparedModel.java	26 Jul 2004 22:25:15 -0000	1.3
  +++ PreparedModel.java	11 Dec 2005 20:07:10 -0000	1.4
  @@ -15,17 +15,22 @@
   * limitations under the License.
   */
   
  -import java.util.*;
  -
  -import org.apache.commons.sql.model.Column;
  -import org.apache.commons.sql.model.Database;
  -import org.apache.commons.sql.model.Table;
  +import java.util.ArrayList;
  +import java.util.Arrays;
  +import java.util.HashMap;
  +import java.util.HashSet;
  +import java.util.Iterator;
  +import java.util.Set;
  +import java.util.TreeMap;
  +
  +import org.apache.commons.beanutils.DynaBean;
  +import org.apache.ddlutils.model.Column;
  +import org.apache.ddlutils.model.Database;
  +import org.apache.ddlutils.model.Table;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   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;
   
   /**
    * Provides a model derived from {@link org.apache.ojb.broker.metadata.DescriptorRepository}
that
  @@ -35,8 +40,8 @@
    */
   public class PreparedModel
   {
  -    /** The log */
  -    private Logger  _log                            = LoggerFactory.getLogger(DatabaseHandling.class);
  +    /** The database model. */
  +    private Database _schema;
       /** Maps dtd elements to tables */
       private TreeMap _elementToTable                 = new TreeMap();
       /** Maps dtd elements to lists of class descriptors (which all map to the same table)
*/
  @@ -48,7 +53,8 @@
   
       public PreparedModel(DescriptorRepository model, Database schema)
       {
  -        prepareModel(model, schema);
  +        _schema = schema;
  +        prepareModel(model);
       }
   
       public Iterator getElementNames()
  @@ -84,6 +90,17 @@
           return (Table)_elementToTable.get(elementName);
       }
   
  +    /**
  +     * Creates a dyna bean for the table associated to the given element.
  +     * 
  +     * @param elementName The element name
  +     * @return The dyna bean
  +     */
  +    public DynaBean createBeanFor(String elementName)
  +    {
  +        return _schema.createDynaBeanFor(getTableFor(elementName));
  +    }
  +    
       public ArrayList getClassDescriptorsMappingTo(String elementName)
       {
           return (ArrayList)_elementToClassDescriptors.get(elementName);
  @@ -100,10 +117,9 @@
        * Prepares a representation of the model that is easier accessible for our purposes.
        * 
        * @param model  The original model
  -     * @param schema The database schema
        * @return The model representation
        */
  -    private void prepareModel(DescriptorRepository model, Database schema)
  +    private void prepareModel(DescriptorRepository model)
       {
           TreeMap result = new TreeMap();
   
  @@ -125,7 +141,7 @@
   
               if (mappedTable == null)
               {
  -                mappedTable = schema.findTable(classDesc.getFullTableName());
  +                mappedTable = _schema.findTable(classDesc.getFullTableName());
                   if (mappedTable == null)
                   {
                       continue;
  @@ -141,7 +157,7 @@
               classDescs.add(classDesc);
               extractAttributes(classDesc, mappedTable, columnsMap, requiredAttributes);
           }
  -        extractIndirectionTables(model, schema);
  +        extractIndirectionTables(model, _schema);
       }
   
       private void extractAttributes(ClassDescriptor classDesc, Table mappedTable, TreeMap
columnsMap, HashMap requiredColumnsMap)
  
  
  
  1.11      +15 -5     db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandlingTask.java
  
  Index: DatabaseHandlingTask.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandlingTask.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DatabaseHandlingTask.java	5 Dec 2004 19:53:03 -0000	1.10
  +++ DatabaseHandlingTask.java	11 Dec 2005 20:07:10 -0000	1.11
  @@ -15,17 +15,27 @@
    * limitations under the License.
    */
   
  -import java.io.*;
  -import java.util.*;
  +import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.FileWriter;
  +import java.io.IOException;
  +import java.io.OutputStreamWriter;
  +import java.io.Writer;
  +import java.util.ArrayList;
  +import java.util.Iterator;
  +import java.util.Properties;
   
  -import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.OJB;
  +import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.metadata.ConnectionRepository;
   import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
   import org.apache.ojb.broker.metadata.MetadataManager;
   import org.apache.ojb.broker.metadata.RepositoryPersistor;
   import org.apache.ojb.broker.util.ClassHelper;
  -import org.apache.tools.ant.*;
  +import org.apache.tools.ant.AntClassLoader;
  +import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.DirectoryScanner;
  +import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.FileList;
   import org.apache.tools.ant.types.FileSet;
   
  @@ -37,7 +47,7 @@
   public class DatabaseHandlingTask extends Task
   {
       /** The name of the default database handler */
  -    private final String DEFAULT_HANDLER = CommonsSqlDatabaseHandling.class.getName();
  +    private final String DEFAULT_HANDLER = DdlUtilslDatabaseHandling.class.getName();
   
       /**
        * Represents a database property.
  
  
  
  1.4       +9 -14     db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/DataSet.java
  
  Index: DataSet.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/DataSet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DataSet.java	14 Aug 2004 20:09:38 -0000	1.3
  +++ DataSet.java	11 Dec 2005 20:07:10 -0000	1.4
  @@ -24,9 +24,8 @@
   import javax.sql.DataSource;
   
   import org.apache.commons.beanutils.DynaBean;
  -import org.apache.commons.sql.builder.SqlBuilder;
  -import org.apache.commons.sql.dynabean.DynaSql;
  -import org.apache.commons.sql.model.Database;
  +import org.apache.ddlutils.Platform;
  +import org.apache.ddlutils.model.Database;
   
   /**
    * Encapsulates the data objects read by Digester.
  @@ -51,17 +50,15 @@
       /**
        * Generates and writes the sql for inserting the currently contained data objects.
        * 
  -     * @param db     The database model
  -     * @param writer The output stream
  +     * @param db       The database model
  +     * @param platform The platform
  +     * @param writer   The output stream
        */
  -    public void createInsertionSql(Database db, SqlBuilder builder, Writer writer) throws
IOException
  +    public void createInsertionSql(Database db, Platform platform, Writer writer) throws
IOException
       {
  -        DynaSql dynaSql = new DynaSql(builder);
  -
  -        dynaSql.setDatabase(db);
           for (Iterator it = _beans.iterator(); it.hasNext();)
           {
  -            writer.write(dynaSql.getInsertSql((DynaBean)it.next()));
  +            writer.write(platform.getInsertSql(db, (DynaBean)it.next()));
               if (it.hasNext())
               {
                   writer.write("\n");
  @@ -75,13 +72,11 @@
        * @param ds The datasource pointing to the actual database
        * @param db The database model
        */
  -    public void insert(DataSource ds, SqlBuilder builder, Database db) throws SQLException
  +    public void insert(DataSource ds, Platform platform, Database db) throws SQLException
       {
  -        DynaSql dynaSql = new DynaSql(builder, ds, db);
  -
           for (Iterator it = _beans.iterator(); it.hasNext();)
           {
  -            dynaSql.insert((DynaBean)it.next());
  +            platform.insert(db, (DynaBean)it.next());
           }
       }
   }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/DdlUtilsDataHandling.java
  
  Index: DdlUtilsDataHandling.java
  ===================================================================
  package org.apache.ojb.broker.util.dbhandling;
  
  /* Copyright 2004-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import java.io.IOException;
  import java.io.Reader;
  import java.io.StringReader;
  import java.io.Writer;
  import java.util.ArrayList;
  import java.util.Iterator;
  
  import javax.sql.DataSource;
  
  import org.apache.commons.beanutils.DynaBean;
  import org.apache.commons.digester.Digester;
  import org.apache.commons.digester.ExtendedBaseRules;
  import org.apache.commons.digester.Rule;
  import org.apache.commons.digester.RuleSetBase;
  import org.apache.ddlutils.Platform;
  import org.apache.ddlutils.model.Column;
  import org.apache.ddlutils.model.Database;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.metadata.DescriptorRepository;
  import org.xml.sax.Attributes;
  import org.xml.sax.EntityResolver;
  import org.xml.sax.InputSource;
  
  /**
   * Provides data input and output via DdlUtils.
   * 
   * @author Thomas Dudziak
   */
  public class DdlUtilsDataHandling
  {
      private class DynaFactoryCreateRule extends Rule
      {
          /**
           * {@inheritDoc}
           */
          public void begin(String namespace, String name, Attributes attributes) throws Exception
          {
              DynaBean bean = _preparedModel.createBeanFor(name);
  
              if (bean == null)
              {
                  throw new DatabaseHandlingException("Unknown element "+name);
              }
  
              for (int idx = 0; idx < attributes.getLength(); idx++)
              {
                  String attrName  = attributes.getLocalName(idx);
                  String attrValue = attributes.getValue(idx);
                  Column column    = _preparedModel.getColumnFor(name, attrName);
  
                  if (column == null)
                  {
                      throw new DatabaseHandlingException("Unknown attribute "+attrName+"
of element "+name);
                  }
                  bean.set(column.getName(), attrValue);
              }
              DdlUtilsDataHandling.this._digester.push(bean);
          }
  
          /**
           * {@inheritDoc}
           */
          public void end(String namespace, String name) throws Exception
          {
              DynaBean bean = (DynaBean)DdlUtilsDataHandling.this._digester.pop();
  
              ((DataSet)DdlUtilsDataHandling.this._digester.peek()).add(bean);
          }
      }
  
      public class DataRuleSet extends RuleSetBase
      {
          /**
           * {@inheritDoc}
           */
          public void addRuleInstances(Digester digester)
          {
              digester.addObjectCreate("dataset", DataSet.class);
              digester.addRule("*/dataset/*", new DynaFactoryCreateRule());
          }
      }
  
      /** The database model */
      private Database _db;
      /** The platform */
      private Platform _platform;
      /** The prepared model */
      private PreparedModel _preparedModel;
      /** The digester for parsing the XML */
      private Digester _digester;
  
      /**
       * Creates a new data handling object.
       * 
       * @param db    The database model
       * @param model The model
       */
      public DdlUtilsDataHandling(Database db, Platform platform, DescriptorRepository model)
      {
          _db            = db;
          _platform      = platform;
          _preparedModel = new PreparedModel(model, db);
          _digester      = new Digester();
          _digester.setEntityResolver(new EntityResolver() {
              public InputSource resolveEntity(String publicId, String systemId)
              {
                  // we don't care about the DTD for data files
                  return new InputSource(new StringReader(""));
              }
  
          });
          _digester.setNamespaceAware(true);
          _digester.setValidating(false);
          _digester.setUseContextClassLoader(true);
          _digester.setRules(new ExtendedBaseRules());
          _digester.addRuleSet(new DataRuleSet());
      }
  
      /**
       * Writes a DTD that can be used for data XML files matching the current model to the
given writer. 
       * 
       * @param output The writer to write the DTD to
       */
      public void getDataDTD(Writer output) throws DatabaseHandlingException
      {
          try
          {
              output.write("<!ELEMENT dataset (\n");
              for (Iterator it = _preparedModel.getElementNames(); it.hasNext();)
              {
                  String elementName = (String)it.next();
  
                  output.write("    ");
                  output.write(elementName);
                  output.write("*");
                  output.write(it.hasNext() ? " |\n" : "\n");
              }
              output.write(")>\n<!ATTLIST dataset\n    name CDATA #REQUIRED\n>\n");
              for (Iterator it = _preparedModel.getElementNames(); it.hasNext();)
              {
                  String    elementName = (String)it.next();
                  ArrayList classDescs  = _preparedModel.getClassDescriptorsMappingTo(elementName);
  
                  if (classDescs == null)
                  {
                      output.write("\n<!-- Indirection table");
                  }
                  else
                  {
                      output.write("\n<!-- Mapped to : ");
                      for (Iterator classDescIt = classDescs.iterator(); classDescIt.hasNext();)
                      {
                          ClassDescriptor classDesc = (ClassDescriptor)classDescIt.next();
      
                          output.write(classDesc.getClassNameOfObject());
                          if (classDescIt.hasNext())
                          {
                              output.write("\n                 ");
                          }
                      }
                  }
                  output.write(" -->\n<!ELEMENT ");
                  output.write(elementName);
                  output.write(" EMPTY>\n<!ATTLIST ");
                  output.write(elementName);
                  output.write("\n");
  
                  for (Iterator attrIt = _preparedModel.getAttributeNames(elementName); attrIt.hasNext();)
                  {
                      String attrName = (String)attrIt.next();
  
                      output.write("    ");
                      output.write(attrName);
                      output.write(" CDATA #");
                      output.write(_preparedModel.isRequired(elementName, attrName) ? "REQUIRED"
: "IMPLIED");
                      output.write("\n");
                  }
                  output.write(">\n");
              }
          }
          catch (IOException ex)
          {
              throw new DatabaseHandlingException(ex);
          }
      }
  
      /**
       * Returns the sql necessary to add the data XML contained in the given input stream.

       * Note that the data is expected to match the repository metadata (not the table schema).
       * Also note that you should not use the reader after passing it to this method except
closing
       * it (which is not done automatically).
       * 
       * @param input  A reader returning the content of the data file
       * @param output The writer to write the sql to
       */
      public void getInsertDataSql(Reader input, Writer output) throws DatabaseHandlingException
      {
          try
          {
              DataSet set = (DataSet)_digester.parse(input);
  
              set.createInsertionSql(_db, _platform, output);
          }
          catch (Exception ex)
          {
              if (ex instanceof DatabaseHandlingException)
              {
                  // is not declared by digester, but may be thrown
                  throw (DatabaseHandlingException)ex;
              }
              else
              {
                  throw new DatabaseHandlingException(ex);
              }
          }
      }
  
      /**
       * Returns the sql necessary to add the data XML contained in the given input stream.

       * Note that the data is expected to match the repository metadata (not the table schema).
       * Also note that you should not use the reader after passing it to this method except
closing
       * it (which is not done automatically).
       * 
       * @param input A reader returning the content of the data file
       * @param ds    The datasource
       */
      public void insertData(Reader input, DataSource ds) throws DatabaseHandlingException
      {
          try
          {
              DataSet set = (DataSet)_digester.parse(input);
              
              set.insert(ds, _platform, _db);
          }
          catch (Exception ex)
          {
              if (ex instanceof DatabaseHandlingException)
              {
                  // is not declared by digester, but may be thrown
                  throw (DatabaseHandlingException)ex;
              }
              else
              {
                  throw new DatabaseHandlingException(ex);
              }
          }
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/DdlUtilslDatabaseHandling.java
  
  Index: DdlUtilslDatabaseHandling.java
  ===================================================================
  package org.apache.ojb.broker.util.dbhandling;
  
  /* Copyright 2004-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import java.io.FileReader;
  import java.io.IOException;
  import java.io.Reader;
  import java.io.Writer;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Properties;
  import java.util.StringTokenizer;
  
  import javax.sql.DataSource;
  
  import org.apache.commons.beanutils.PropertyUtils;
  import org.apache.commons.dbcp.BasicDataSource;
  import org.apache.ddlutils.Platform;
  import org.apache.ddlutils.PlatformFactory;
  import org.apache.ddlutils.io.DatabaseIO;
  import org.apache.ddlutils.model.Database;
  import org.apache.ojb.broker.metadata.DescriptorRepository;
  import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  import org.apache.ojb.broker.util.logging.Logger;
  import org.apache.ojb.broker.util.logging.LoggerFactory;
  
  /**
   * Provides database handling via DdlUtils.
   * 
   * @author Thomas Dudziak
   */
  public class DdlUtilslDatabaseHandling implements DatabaseHandling
  {
      /** The log */
      private Logger _log = LoggerFactory.getLogger(getClass());
      /** Maps jcd platforms to DdlUtils database types */
      private HashMap _platformToDatabaseType = new HashMap();
      /** The database connection descriptor */
      private JdbcConnectionDescriptor _jcd;
      /** The model */
      private DescriptorRepository _model;
      /** The datasource for DdlUtils */
      private BasicDataSource _dataSource;
      /** The platform */
      private Platform _platform;
      /** Properties of the builder */
      private Properties _builderProps = new Properties();
      /** The database schema */
      private Database _schema = new Database();
  
      /**
       * Creates a new database handling object.
       */
      public DdlUtilslDatabaseHandling()
      {
          initPlatformMapping();
      }
  
      /**
       * Initializes the mapping between OJB's platform and DdlUtils's database type.
       */
      private void initPlatformMapping()
      {
          _platformToDatabaseType.put("Cloudscape",  "cloudscape");
          _platformToDatabaseType.put("Derby",       "derby");
          _platformToDatabaseType.put("Db2",         "db2");
          _platformToDatabaseType.put("Firebird",    "firebird");
          _platformToDatabaseType.put("Hsqldb",      "hsqldb");
          _platformToDatabaseType.put("Informix",    null);
          _platformToDatabaseType.put("MaxDB",       "maxdb");
          _platformToDatabaseType.put("Mckoi",       "mckoi");
          _platformToDatabaseType.put("MsAccess",    null);
          _platformToDatabaseType.put("MsSQLServer", "mssql");
          _platformToDatabaseType.put("MySQL",       "mysql");
          _platformToDatabaseType.put("Oracle",      "oracle");
          _platformToDatabaseType.put("Oracle9i",    "oracle9");
          _platformToDatabaseType.put("WLOracle9i",  "oracle9");
          _platformToDatabaseType.put("PostgreSQL",  "postgresql");
          _platformToDatabaseType.put("Sapdb",       "sapdb");
          _platformToDatabaseType.put("Sybase",      "sybase");
          _platformToDatabaseType.put("SybaseASA",   "sysbase");
          _platformToDatabaseType.put("SybaseASE",   "sybase");
      }
  
      /**
       * Returns the database type as used by DdlUtils.
       * 
       * @return The database type
       * @throws DatabaseHandlingException If the database specified in the JCD is not supported
by DdlUtils
       */
      private String getDatabaseType() throws DatabaseHandlingException
      {
          String dbType = (String)_platformToDatabaseType.get(_jcd.getDbms());
  
          if (dbType == null)
          {
              throw new DatabaseHandlingException("Database "+_jcd.getDbms()+" is currently
not supported by DdlUtils");
          }
          return dbType;
      }
  
      /**
       * {@inheritDoc}
       */
      public void setWorkDir(String dir) throws IOException
      {
          // Not necessary for DdlUtils
      }
  
      /**
       * {@inheritDoc}
       */
      public void setConnection(JdbcConnectionDescriptor jcd) throws DatabaseHandlingException
      {
          _jcd         = jcd;
          _dataSource  = null;
      }
  
      /**
       * {@inheritDoc}
       */
      public JdbcConnectionDescriptor getConnection()
      {
          return _jcd;
      }
  
      /**
       * Returns the datasource. Note we're using lazy initialization for the datasource
       * (e.g. the first call to this method will initialize it) to enable using the
       * sql-generation methods (except dump) without actually having a database (or a
       * jdbc driver for it).
       * 
       * @return The datasource
       */
      public DataSource getDataSource() throws DatabaseHandlingException
      {
          if (_dataSource == null)
          {
              _dataSource = new BasicDataSource();
  
              _dataSource.setDriverClassName(_jcd.getDriver());
              _dataSource.setUrl(_jcd.getProtocol() + ":" + _jcd.getSubProtocol() + ":" +
_jcd.getDbAlias());
              _dataSource.setUsername(_jcd.getUserName());
              _dataSource.setPassword(_jcd.getPassWord());
          }
          
          return _dataSource;
      }
  
      /**
       * {@inheritDoc}
       */
      public DescriptorRepository getMetadata()
      {
          return _model;
      }
  
      /**
       * {@inheritDoc}
       */
      public void setMetadata(DescriptorRepository metaModel)
      {
          _model = metaModel;
      }
  
      /**
       * {@inheritDoc}
       */
      public void addSchemaFiles(String srcDir, String listOfFilenames) throws IOException,
DatabaseHandlingException
      {
          StringTokenizer tokenizer = new StringTokenizer(listOfFilenames, ",");
          String          baseDir   = ((srcDir != null) && (srcDir.length() > 0)
? srcDir : ".") + "/";
          String          token;
  
          try
          {
              DatabaseIO dbIO = new DatabaseIO();
  
              dbIO.setValidateXml(false);
              dbIO.setUseInternalDtd(true);
              while (tokenizer.hasMoreTokens())
              {
                  token = tokenizer.nextToken();
                  if (token.length() > 0)
                  {
                      _schema.mergeWith(dbIO.read(baseDir + token));
                  }
              }
          }
          catch (Exception ex)
          {
              if (ex instanceof IOException)
              {
                  throw (IOException)ex;
              }
              else
              {
                  throw new DatabaseHandlingException(ex);
              }
          }
      }
  
      /**
       * {@inheritDoc}
       */
      public void addSchemaFile(Reader reader) throws IOException, DatabaseHandlingException
      {
          try
          {
              DatabaseIO dbIO = new DatabaseIO();
  
              dbIO.setValidateXml(false);
              dbIO.setUseInternalDtd(true);
  
              _schema.mergeWith(dbIO.read(reader));
          }
          catch (Exception ex)
          {
              if (ex instanceof IOException)
              {
                  throw (IOException)ex;
              }
              else
              {
                  throw new DatabaseHandlingException(ex);
              }
          }
          finally
          {
              reader.close();
          }
      }
  
      /**
       * Sets a database property. Currently defined are the following properties:<br/>
       * <table>
       * <tr><td>database</td><td>property</td><td>description</td></tr>
       * <tr><td>SapDb, MaxDB</td><td>characterType</td>
       * <td>Specifies the character type of the database, either <code>ASCII</code>
or
       *     <code>UNICODE</code>. Default is <code>ASCII</code>.</td></tr>

       * </table>
       * 
       * @param propName  The property name
       * @param propValue The property value
       */
      public void setDatabaseProperty(String propName, String propValue)
      {
          _builderProps.setProperty(propName, propValue);
          if (_platform != null)
          {
              applyDatabaseProperty(propName);
          }
      }
  
      /**
       * Actually applies the property, i.e. sets it at the builder. If the builder does
       * not support the property, a warning is logged but no exception is issued.
       * 
       * @param propName The property name
       */
      private void applyDatabaseProperty(String propName)
      {
          try
          {
              PropertyUtils.setProperty(_platform.getSqlBuilder(), propName, _builderProps.get(propName));
          }
          catch (NoSuchMethodException ex)
          {
             //_log.info("The builder for database "+_builder.getDatabaseName()+" does not
support the property "+propName); 
          }
          catch (Exception ex)
          {
              _log.warn("Unable to set the property "+propName+" on the builder for database
"+_platform.getName(), ex); 
          }
      }
  
      /**
       * Returns the platform instance.
       * 
       * @return The platform instance
       */
      private Platform getPlatform() throws DatabaseHandlingException
      {
          if (_platform == null)
          {
              try
              {
                  _platform = PlatformFactory.createNewPlatformInstance(getDatabaseType());
                  if (!_builderProps.isEmpty())
                  {
                      for (Iterator it = _builderProps.keySet().iterator(); it.hasNext();)
                      {
                          applyDatabaseProperty((String)it.next());
                      }
                  }
                  _platform.setDataSource(getDataSource());
              }
              catch (Exception ex)
              {
                  throw new DatabaseHandlingException(ex);
              }
          }
          return _platform;
      }
  
      /**
       * {@inheritDoc}
       */
      public void createDatabase() throws DatabaseHandlingException
      {
          try
          {
              getPlatform().createTables(_schema, true, true);
          }
          catch (Exception ex)
          {
              throw new DatabaseHandlingException(ex);
          }
      }
  
      /**
       * {@inheritDoc}
       */
      public void alterDatabase() throws DatabaseHandlingException
      {
          try
          {
              getPlatform().alterTables(_schema, true);
          }
          catch (Exception ex)
          {
              throw new DatabaseHandlingException(ex);
          }
      }
  
      /**
       * {@inheritDoc}
       */
      public void dropDatabase() throws DatabaseHandlingException
      {
          try
          {
              getPlatform().dropTables(_schema, true);
          }
          catch (Exception ex)
          {
              throw new DatabaseHandlingException(ex);
          }
      }
  
      /**
       * {@inheritDoc}
       */
      public void dumpDatabaseSchema(Writer writer) throws DatabaseHandlingException
      {
          try
          {
              Database   db   = getPlatform().readModelFromDatabase();
              DatabaseIO dbIO = new DatabaseIO();
  
              dbIO.write(db, writer);
          }
          catch (Exception ex)
          {
              throw new DatabaseHandlingException(ex);
          }
      }
  
      /**
       * {@inheritDoc}
       */
      public void getDropDatabaseSql(Writer writer) throws DatabaseHandlingException
      {
          try
          {
              Database db = getPlatform().readModelFromDatabase();
  
              writer.write(getPlatform().getDropTablesSql(db, true));
          }
          catch (Exception ex)
          {
              throw new DatabaseHandlingException(ex);
          }
      }
  
      /**
       * {@inheritDoc}
       */
      public void getAlterDatabaseSql(Writer writer) throws DatabaseHandlingException
      {
          try
          {
              writer.write(getPlatform().getAlterTablesSql(_schema, true, true, true));
          }
          catch (Exception ex)
          {
              throw new DatabaseHandlingException(ex);
          }
      }
  
      /**
       * {@inheritDoc}
       */
      public void getCreateDatabaseSql(Writer writer) throws DatabaseHandlingException
      {
          try
          {
              writer.write(getPlatform().getCreateTablesSql(_schema, true, true));
          }
          catch (Exception ex)
          {
              throw new DatabaseHandlingException(ex);
          }
      }
  
      /**
       * {@inheritDoc}
       */
      public void insertData(Reader reader) throws IOException, DatabaseHandlingException
      {
          new DdlUtilsDataHandling(_schema, _platform, _model).insertData(reader, getDataSource());
      }
  
      /**
       * {@inheritDoc}
       */
      public void insertData(String srcDir, String listOfFilenames) throws IOException, DatabaseHandlingException
      {
          DataSource           dataSource   = getDataSource();
          DdlUtilsDataHandling dataHandling = new DdlUtilsDataHandling(_schema, _platform,
_model);
          StringTokenizer      tokenizer    = new StringTokenizer(listOfFilenames, ",");
          String               baseDir      = ((srcDir != null) && (srcDir.length()
> 0) ? srcDir : ".") + "/";
          String               token;
  
          while (tokenizer.hasMoreTokens())
          {
              token = tokenizer.nextToken();
              if (token.length() > 0)
              {
                  dataHandling.insertData(new FileReader(baseDir + token), dataSource);
              }
          }
      }
  
      /**
       * {@inheritDoc}
       */
      public void getInsertDataSql(Reader reader, Writer writer) throws DatabaseHandlingException
      {
          new DdlUtilsDataHandling(_schema, _platform, _model).getInsertDataSql(reader, writer);
      }
  
      /**
       * {@inheritDoc}
       */
      public void getInsertDataSql(String srcDir, String listOfFilenames, Writer writer) throws
IOException, DatabaseHandlingException
      {
          DdlUtilsDataHandling dataHandling = new DdlUtilsDataHandling(_schema, _platform,
_model);
          StringTokenizer        tokenizer  = new StringTokenizer(listOfFilenames, ",");
          String                 baseDir    = ((srcDir != null) && (srcDir.length()
> 0) ? srcDir : ".") + "/";
          String                 token;
  
          while (tokenizer.hasMoreTokens())
          {
              token = tokenizer.nextToken();
              if (token.length() > 0)
              {
                  dataHandling.getInsertDataSql(new FileReader(baseDir + token), writer);
              }
          }
      }
  
      /**
       * {@inheritDoc}
       */
      public void getDataDTD(Writer writer) throws DatabaseHandlingException
      {
          new DdlUtilsDataHandling(_schema, _platform, _model).getDataDTD(writer);
      }
  }
  
  
  
  1.53      +3 -3      db-ojb/.classpath
  
  Index: .classpath
  ===================================================================
  RCS file: /home/cvs/db-ojb/.classpath,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- .classpath	5 Sep 2005 11:26:58 -0000	1.52
  +++ .classpath	11 Dec 2005 20:07:10 -0000	1.53
  @@ -17,12 +17,10 @@
   	<classpathentry kind="lib" path="lib/jdo.jar"/>
   	<classpathentry kind="lib" path="lib/junit.jar"/>
   	<classpathentry kind="lib" path="lib/xalan.jar"/>
  -	<classpathentry kind="lib" path="lib/xml-apis.jar"/>
   	<classpathentry kind="lib" path="lib/jdori.jar"/>
   	<classpathentry kind="lib" path="lib/log4j-1.2.8.jar"/>
   	<classpathentry kind="lib" path="lib/velocity-1.3.1.jar"/>
   	<classpathentry kind="lib" path="lib/prevayler.jar"/>
  -	<classpathentry kind="lib" path="lib/commons-sql-1.0-dev.jar"/>
   	<classpathentry kind="lib" path="lib/picocontainer-1.1.jar"/>
   	<classpathentry kind="lib" path="lib/spring-core.jar"/>
   	<classpathentry kind="lib" path="lib/commons-collections-3.1.jar"/>
  @@ -33,12 +31,14 @@
   	<classpathentry kind="lib" path="lib/xdoclet-1.2.3.jar"/>
   	<classpathentry kind="lib" path="lib/xjavadoc-1.1.jar"/>
   	<classpathentry kind="lib" path="lib/cglib-2.1.jar"/>
  -	<classpathentry kind="lib" path="lib/commons-betwixt-0.7RC2.jar"/>
   	<classpathentry kind="lib" path="lib/commons-digester-1.7.jar"/>
   	<classpathentry kind="lib" path="lib/commons-lang-2.1.jar"/>
   	<classpathentry kind="lib" path="lib/antlr-2.7.5.jar"/>
   	<classpathentry kind="lib" path="lib/jcs-1.2.6.5.jar"/>
   	<classpathentry kind="lib" path="lib/oscache-2.1.1.jar"/>
   	<classpathentry kind="lib" path="lib/commons-transaction-1.1.jar"/>
  +	<classpathentry kind="lib" path="lib/DdlUtils-1.0-dev.jar"/>
  +	<classpathentry kind="lib" path="lib/xml-apis-1.3.02.jar"/>
  +	<classpathentry kind="lib" path="lib/commons-betwixt-0.8-dev.jar"/>
   	<classpathentry kind="output" path="target/classes/main"/>
   </classpath>
  
  
  
  1.174     +10 -10    db-ojb/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/build.xml,v
  retrieving revision 1.173
  retrieving revision 1.174
  diff -u -r1.173 -r1.174
  --- build.xml	27 Aug 2005 13:52:00 -0000	1.173
  +++ build.xml	11 Dec 2005 20:07:10 -0000	1.174
  @@ -349,19 +349,19 @@
   	</target>
   
       <!-- ================================================================== -->
  -    <!-- prepare testdb                                                     -->
  +    <!-- prepare test database                                              -->
       <!-- ================================================================== -->
       <target name="prepare-testdb"
  -            description="prepare testdb using torque or commons-sql"
  -            depends="prepare-testdb-torque, prepare-testdb-commons-sql"/>
  +            description="prepare testdb using torque or ddlutils"
  +            depends="prepare-testdb-torque, prepare-testdb-ddlutils"/>
   
       <!-- ================================================================== -->
  -    <!-- prepare testdb using torque                                        -->
  +    <!-- prepare test database using torque                                 -->
       <!-- ================================================================== -->
       <target name="prepare-testdb-torque"
               description="prepare testdb using torque"
               depends="prepare, prepare-repository"
  -            unless="use-commons-sql">
  +            unless="use-ddlutils">
   
           <copy todir="${build.test}">
               <fileset dir="${src.dir}/schema" includes="*.xml,*.dtd"/>
  @@ -408,12 +408,12 @@
       </target>
   
       <!-- ================================================================== -->
  -    <!-- prepare testdb using commons-sql                                   -->
  +    <!-- prepare testdb using DdlUtils                                      -->
       <!-- ================================================================== -->
  -    <target name="prepare-testdb-commons-sql"
  -            description="prepare testdb using commons-sql"
  +    <target name="prepare-testdb-ddlutils"
  +            description="prepare testdb using DdlUtils"
               depends="prepare, prepare-repository"
  -            if="use-commons-sql">
  +            if="use-ddlutils">
   
           <copy todir="${build.test}">
               <fileset dir="${src.dir}/schema" includes="*.xml,*.dtd"/>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message