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 build.xml
Date Sun, 08 Aug 2004 11:28:03 GMT
tomdz       2004/08/08 04:28:03

  Modified:    lib      commons-sql-1.0-dev.jar
               src/java/org/apache/ojb/broker/util/dbhandling
                        CommonsSqlDatabaseHandling.java
                        DatabaseHandling.java DatabaseHandlingTask.java
                        TorqueDatabaseHandling.java
               .        build.xml
  Log:
  Fixed commons-sql dbhandling for SapBD/MaxDB
  Added suport in the dbhandling task for specifying database properties
  
  Revision  Changes    Path
  1.7       +197 -172  db-ojb/lib/commons-sql-1.0-dev.jar
  
  	<<Binary file>>
  
  
  1.6       +83 -13    db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/CommonsSqlDatabaseHandling.java
  
  Index: CommonsSqlDatabaseHandling.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/CommonsSqlDatabaseHandling.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CommonsSqlDatabaseHandling.java	1 Aug 2004 21:42:28 -0000	1.5
  +++ CommonsSqlDatabaseHandling.java	8 Aug 2004 11:28:02 -0000	1.6
  @@ -17,10 +17,13 @@
   
   import java.io.*;
   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.sql.builder.SqlBuilder;
   import org.apache.commons.sql.builder.SqlBuilderFactory;
   import org.apache.commons.sql.io.DatabaseReader;
  @@ -31,6 +34,8 @@
   import org.apache.commons.sql.util.DataSourceWrapper;
   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 commons-sql.
  @@ -39,16 +44,42 @@
    */
   public class CommonsSqlDatabaseHandling implements DatabaseHandling
   {
  +    /** The log */
  +    private Logger _log = LoggerFactory.getLogger(getClass());
       /** Maps jcd platforms to commons-sql database types */
  -    private static HashMap _platformToDatabaseType = new HashMap();
  +    private HashMap _platformToDatabaseType = new HashMap();
  +    /** The database connection descriptor */
  +    private JdbcConnectionDescriptor _jcd;
  +    /** The model */
  +    private DescriptorRepository _model;
  +    /** The datasource for commons-sql */
  +    private DataSourceWrapper _dataSource;
  +    /** The database sql builder */
  +    private SqlBuilder _builder;
  +    /** Properties of the builder */
  +    private Properties _builderProps = new Properties();
  +    /** The database schema */
  +    private Database _schema = new Database();
   
  -    static
  +    /**
  +     * Creates a new database handling object.
  +     */
  +    public CommonsSqlDatabaseHandling()
  +    {
  +        initPlatformMapping();
  +    }
  +
  +    /**
  +     * Initializes the mapping between OJB's platform and commons-sql's database type.
  +     */
  +    private void initPlatformMapping()
       {
           _platformToDatabaseType.put("Db2",         "db2");
           _platformToDatabaseType.put("Firebird",    null);
           _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");
  @@ -62,17 +93,6 @@
           _platformToDatabaseType.put("SybaseASE",   "sybase");
       }
   
  -    /** The database connection descriptor */
  -    private JdbcConnectionDescriptor _jcd;
  -    /** The model */
  -    private DescriptorRepository _model;
  -    /** The datasource for commons-sql */
  -    private DataSourceWrapper _dataSource;
  -    /** The database sql builder */
  -    private SqlBuilder _builder;
  -    /** The database schema */
  -    private Database _schema = new Database();
  -
       /**
        * Returns the database type as used by commons-sql.
        * 
  @@ -109,6 +129,13 @@
           try
           {
               _builder = SqlBuilderFactory.newSqlBuilder(getDatabaseType());
  +            if (!_builderProps.isEmpty())
  +            {
  +                for (Iterator it = _builderProps.keySet().iterator(); it.hasNext();)
  +                {
  +                    applyDatabaseProperty((String)it.next());
  +                }
  +            }
           }
           catch (Exception ex)
           {
  @@ -239,6 +266,49 @@
           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 (_builder != 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(_builder, propName, _builderProps.get(propName));
  +        }
  +        catch (NoSuchMethodException ex)
  +        {
  +           _log.warn("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
"+_builder.getDatabaseName(), ex); 
           }
       }
   
  
  
  
  1.3       +8 -0      db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandling.java
  
  Index: DatabaseHandling.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandling.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DatabaseHandling.java	22 Jul 2004 07:48:52 -0000	1.2
  +++ DatabaseHandling.java	8 Aug 2004 11:28:02 -0000	1.3
  @@ -44,6 +44,14 @@
       public void setConnection(JdbcConnectionDescriptor jcd) throws DatabaseHandlingException;
   
       /**
  +     * Sets a database property.
  +     * 
  +     * @param propName  The property name
  +     * @param propValue The property value
  +     */
  +    public void setDatabaseProperty(String propName, String propValue);
  +
  +    /**
        * Returns the connection descriptor used by this handling object.
        * 
        * @return The connection descriptor
  
  
  
  1.6       +107 -4    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DatabaseHandlingTask.java	29 Jul 2004 20:33:43 -0000	1.5
  +++ DatabaseHandlingTask.java	8 Aug 2004 11:28:02 -0000	1.6
  @@ -16,9 +16,7 @@
    */
   
   import java.io.*;
  -import java.util.ArrayList;
  -import java.util.Iterator;
  -import java.util.Properties;
  +import java.util.*;
   
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  @@ -28,6 +26,7 @@
   import org.apache.ojb.broker.metadata.RepositoryPersistor;
   import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.tools.ant.*;
  +import org.apache.tools.ant.types.FileList;
   import org.apache.tools.ant.types.FileSet;
   
   /**
  @@ -41,6 +40,57 @@
       private final String DEFAULT_HANDLER = CommonsSqlDatabaseHandling.class.getName();
   
       /**
  +     * Represents a database property.
  +     */
  +    public class DatabaseProperty
  +    {
  +        /** The property name */
  +        private String _name;
  +        /** The property value */
  +        private String _value;
  +
  +        /**
  +         * Returns the property name.
  +         * 
  +         * @return The property name
  +         */
  +        public String getName()
  +        {
  +            return _name;
  +        }
  +
  +        /**
  +         * Sets the property name.
  +         * 
  +         * @param name The property name
  +         */
  +        public void setName(String name)
  +        {
  +            _name = name;
  +        }
  +
  +        /**
  +         * Returns the property value.
  +         * 
  +         * @return The property value
  +         */
  +        public String getValue()
  +        {
  +            return _value;
  +        }
  +
  +        /**
  +         * Sets the property value.
  +         * 
  +         * @param value The property value
  +         */
  +        public void setValue(String value)
  +        {
  +            _value = value;
  +        }
  +    }
  +
  +    /**
        * Declares a database action.
        */
       public interface DatabaseAction
  @@ -390,7 +440,9 @@
       private ArrayList _fileSets = new ArrayList();
       /** The actions to perform */
       private ArrayList _actions = new ArrayList();
  -    
  +    /** Database properties */
  +    private ArrayList _dbProps = new ArrayList();
  +
       /**
        * Sets the name of the handling to use.
        * 
  @@ -478,6 +530,57 @@
       public void addFileset(FileSet fileset)
       {
           _fileSets.add(fileset);
  +    }
  +
  +    /**
  +     * Creates a new database property object for Ant.
  +     * 
  +     * @return The property object
  +     */
  +    public DatabaseProperty createDatabaseProperty()
  +    {
  +        DatabaseProperty prop = new DatabaseProperty();
  +
  +        _dbProps.add(prop);
  +        return prop;
  +    }
  +
  +    /**
  +     * Adds the properties contained in the given file.
  +     * 
  +     * @param propFiles The properties files
  +     */
  +    public void addConfiguredDatabaseProperties(FileList propFiles)
  +    {
  +        Properties props = new Properties();
  +        File       dir   = propFiles.getDir(getProject());
  +
  +        if (dir == null)
  +        {
  +            dir = new File(".");
  +            propFiles.setDir(dir);
  +        }
  +
  +        String[] files = propFiles.getFiles(getProject());
  +
  +        for (int idx = 0; idx < files.length; idx++)
  +        {
  +            try
  +            {
  +                props.load(new FileInputStream(new File(dir, files[idx])));
  +            }
  +            catch (IOException ex)
  +            {
  +                throw new BuildException("Could not load the properties file "+files[idx],
ex);
  +            }
  +        }
  +        for (Iterator it = props.keySet().iterator(); it.hasNext();)
  +        {
  +            DatabaseProperty prop = createDatabaseProperty();
  +
  +            prop.setName((String)it.next());
  +            prop.setValue(props.getProperty(prop.getName()));
  +        }
       }
   
       /**
  
  
  
  1.3       +8 -0      db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/TorqueDatabaseHandling.java
  
  Index: TorqueDatabaseHandling.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/dbhandling/TorqueDatabaseHandling.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TorqueDatabaseHandling.java	22 Jul 2004 07:48:52 -0000	1.2
  +++ TorqueDatabaseHandling.java	8 Aug 2004 11:28:02 -0000	1.3
  @@ -117,6 +117,14 @@
           }
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.ojb.broker.util.dbhandling.DatabaseHandling#setDatabaseProperty(java.lang.String,
java.lang.String)
  +     */
  +    public void setDatabaseProperty(String propName, String propValue)
  +    {
  +        // Not supported by Torque
  +    }
  +
       /**
        * Returns the connection descriptor used by this handling object.
        * 
  
  
  
  1.150     +2 -1      db-ojb/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/build.xml,v
  retrieving revision 1.149
  retrieving revision 1.150
  diff -u -r1.149 -r1.150
  --- build.xml	27 Jul 2004 23:14:19 -0000	1.149
  +++ build.xml	8 Aug 2004 11:28:03 -0000	1.150
  @@ -435,6 +435,7 @@
   
           <dbhandling ojbpropertiesfile="${build.test}/ojb/OJB.properties">
               <fileset dir="${build.test}" includes="*schema.xml"/>
  +            <databaseProperties files="profile/${profile}.profile"/>
   
               <!-- This creates a sql file containing the table definitions -->
               <createSql destFile="${build.test}/database.sql"/>
  
  
  

---------------------------------------------------------------------
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