You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by dl...@apache.org on 2001/08/22 22:00:39 UTC

cvs commit: jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model AppData.java

dlr         01/08/22 13:00:39

  Modified:    src/java/org/apache/torque/engine/database/model
                        AppData.java
  Log:
  * Added a table of Properties files read from db.props and keyed by
  database type (i.e. mysql, oracle, etc.) as idiosyncrasyTable
  instance variable.
  
  * Added ctor which helps initializes application-wide database type
  and base path to properties file.
  
  * Added accessor for database type idiosyncrasies.
  
  * Removed globaly-unique name support...a simpler method of naming
  constraints is now in use.
  
  Revision  Changes    Path
  1.3       +89 -36    jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/AppData.java
  
  Index: AppData.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/AppData.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- AppData.java	2001/08/21 00:04:15	1.2
  +++ AppData.java	2001/08/22 20:00:39	1.3
  @@ -54,23 +54,27 @@
    * <http://www.apache.org/>.
    */
   
  +import java.io.File;
  +import java.io.FileInputStream;
   import java.util.ArrayList;
  -import java.util.HashSet;
  +import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
  -import java.util.Set;
  +import java.util.Map;
  +import java.util.Properties;
   
  -import org.apache.torque.TorqueException;
  -
   import org.xml.sax.Attributes;
   
  +import org.apache.torque.Torque;
  +import org.apache.torque.TorqueException;
  +
   /**
    * A class for holding application data structures.
    *
    * @author <a href="mailto:leon@opticode.co.za>Leon Messerschmidt</a>
    * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
    * @author <a href="mailto:dlr@finemaltcoding.com>Daniel Rall</a>
  - * @version $Id: AppData.java,v 1.2 2001/08/21 00:04:15 dlr Exp $
  + * @version $Id: AppData.java,v 1.3 2001/08/22 20:00:39 dlr Exp $
    */
   public class AppData
   {
  @@ -79,21 +83,90 @@
        */
       private List dbList = new ArrayList(5);
   
  +    /**
  +     * The table of idiosyncrasies for various database types.
  +     */
  +    private Map idiosyncrasyTable = new HashMap(8);
  +
  +    /**
  +     * The type for our databases.
  +     */
  +    private String databaseType;
  +
       /**
  -     * The list of unique names in use by a system.  Any time a
  -     * foreign-key or index entity is added to the RDBMS installation,
  -     * it must be added to this list as well.
  +     * The base of the path to the properties file, including trailing
  +     * slash.
        */
  -    private Set globalNames = new HashSet(32, 0.5f);
  +    private String basePropsFilePath;
   
       /**
        * Creates a new instance.
        */
       public AppData()
       {
  +        this(null, null);
  +    }
  +
  +    /**
  +     * Creates a new instance for the specified database type.
  +     *
  +     * @param databaseType The default type for any databases added to
  +     * this application model.
  +     * @param basePropsFilePath The base of the path to the properties
  +     * file, including trailing slash.
  +     */
  +    public AppData(String databaseType, String basePropsFilePath)
  +    {
  +        this.basePropsFilePath = basePropsFilePath;
  +        this.databaseType = databaseType;
       }
   
       /**
  +     * Each database has its own list of idiosyncrasies which can be
  +     * configured by editting its <code>db.props</code> file.
  +     *
  +     * @param databaseType The type of database to retrieve the
  +     * properties of.
  +     * @return The idiosyncrasies of <code>databaseType</code>.
  +     * @exception TorqueException Couldn't locate properties file.
  +     */
  +    protected Properties getIdiosyncrasies(String databaseType)
  +        throws TorqueException
  +    {
  +        Properties idiosyncrasies =
  +            (Properties) idiosyncrasyTable.get(databaseType);
  +
  +        // If we haven't yet loaded the properties and we have the
  +        // information to do so, proceed with loading.
  +        if (idiosyncrasies == null &&
  +            basePropsFilePath != null && databaseType != null)
  +        {
  +            idiosyncrasies = new Properties();
  +            File propsFile = new File(basePropsFilePath + databaseType,
  +                                      "db.props");
  +            if (propsFile.exists())
  +            {
  +                try
  +                {
  +                    idiosyncrasies.load(new FileInputStream(propsFile));
  +                }
  +                catch (Exception e)
  +                {
  +                    e.printStackTrace();
  +                }
  +                idiosyncrasyTable.put(databaseType, idiosyncrasies);
  +            }
  +            else
  +            {
  +                throw new TorqueException("Database-specific properties " +
  +                                          "file does not exist: " +
  +                                          propsFile.getAbsolutePath());
  +            }
  +        }
  +        return idiosyncrasies;
  +    }
  +
  +    /**
        * Return an array of all databases
        */
       public Database[] getDatabases()
  @@ -151,35 +224,15 @@
       public void addDatabase(Database db)
       {
           db.setAppData (this);
  -        dbList.add(db);
  -    }
  -
  -    /**
  -     * Tests for existance of name in list of global names.
  -     *
  -     * @param name The name to check.
  -     * @return Whether the name has already been used.
  -     */
  -    public boolean isUsedName(String name)
  -    {
  -        return globalNames.contains(name);
  -    }
  -
  -    /**
  -     * Adds a name to the list of globaly-scoped names used by the
  -     * data storage system.
  -     *
  -     * @param name The system-scoped name.
  -     * @exception TorqueException Globaly-scoped name already in use.
  -     */
  -    public void markNameAsUsed(String name)
  -        throws TorqueException
  -    {
  -        if (!globalNames.add(name))
  +        if (db.getName() == null)
           {
  -            throw new TorqueException("Globaly-scoped name already in use: " +
  -                                      name);
  +            db.setName(Torque.getDefaultDB());
           }
  +        if (db.getDatabaseType() == null)
  +        {
  +            db.setDatabaseType(databaseType);
  +        }
  +        dbList.add(db);
       }
   
       /**
  
  
  

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