db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r232530 [2/4] - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/ java/org/apache/ddlutils/builder/ java/org/apache/ddlutils/dynabean/ java/org/apache/ddlutils/io/ java/org/apache/ddlutils/model/ java/org/apache/ddlutils/platform/ java/o...
Date Sat, 13 Aug 2005 21:39:40 GMT
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/PostgreSqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/PostgreSqlBuilder.java?rev=232530&r1=232529&r2=232530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/PostgreSqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/PostgreSqlBuilder.java Sat Aug 13 14:36:44 2005
@@ -20,12 +20,13 @@
 import java.sql.Types;
 import java.util.Iterator;
 
+import org.apache.ddlutils.PlatformInfo;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.Table;
 
 /**
- * An SQL Builder for PostgresSql, based upon version 7.2.
+ * The SQL Builder for PostgresSql.
  * 
  * @author <a href="mailto:john@zenplex.com">John Thorhauer</a>
  * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
@@ -33,50 +34,14 @@
  */
 public class PostgreSqlBuilder extends SqlBuilder
 {
-    /** Database name of this builder */
-    public static final String DATABASENAME      = "PostgreSql";
-    /** The standard PostgreSQL jdbc driver */
-    public static final String JDBC_DRIVER       = "org.postgresql.Driver";
-    /** The subprotocol used by the standard PostgreSQL driver */
-    public static final String JDBC_SUBPROTOCOL  = "postgresql";
-
-    public PostgreSqlBuilder()
-    {
-        // this is the default length though it might be changed when building PostgreSQL
-        // in file src/include/postgres_ext.h
-        setMaxIdentifierLength(31);
-        setRequiringNullAsDefaultValue(false);
-        setPrimaryKeyEmbedded(true);
-        setForeignKeysEmbedded(false);
-        setIndicesEmbedded(false);
-        addNativeTypeMapping(Types.ARRAY,         "BYTEA");
-        addNativeTypeMapping(Types.BINARY,        "BYTEA");
-        addNativeTypeMapping(Types.BIT,           "BOOLEAN");
-        addNativeTypeMapping(Types.BLOB,          "BYTEA");
-        addNativeTypeMapping(Types.CLOB,          "TEXT");
-        addNativeTypeMapping(Types.DECIMAL,       "NUMERIC");
-        addNativeTypeMapping(Types.DISTINCT,      "BYTEA");
-        addNativeTypeMapping(Types.DOUBLE,        "DOUBLE PRECISION");
-        addNativeTypeMapping(Types.FLOAT,         "DOUBLE PRECISION");
-        addNativeTypeMapping(Types.JAVA_OBJECT,   "BYTEA");
-        addNativeTypeMapping(Types.LONGVARBINARY, "BYTEA");
-        addNativeTypeMapping(Types.LONGVARCHAR,   "TEXT");
-        addNativeTypeMapping(Types.NULL,          "BYTEA");
-        addNativeTypeMapping(Types.OTHER,         "BYTEA");
-        addNativeTypeMapping(Types.REF,           "BYTEA");
-        addNativeTypeMapping(Types.STRUCT,        "BYTEA");
-        addNativeTypeMapping(Types.TINYINT,       "SMALLINT");
-        addNativeTypeMapping(Types.VARBINARY,     "BYTEA");
-
-        addNativeTypeMapping("DATALINK", "BYTEA");
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.ddlutils.builder.SqlBuilder#getDatabaseName()
+    /**
+     * Creates a new builder instance.
+     * 
+     * @param info The platform info
      */
-    public String getDatabaseName()
+    public PostgreSqlBuilder(PlatformInfo info)
     {
-        return DATABASENAME;
+        super(info);
     }
 
     /* (non-Javadoc)

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SapDbBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SapDbBuilder.java?rev=232530&r1=232529&r2=232530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SapDbBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SapDbBuilder.java Sat Aug 13 14:36:44 2005
@@ -19,11 +19,12 @@
 import java.io.IOException;
 import java.sql.Types;
 
+import org.apache.ddlutils.PlatformInfo;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Table;
 
 /**
- * An SQL Builder for SapDB.
+ * The SQL Builder for SapDB.
  * 
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
@@ -31,57 +32,14 @@
  */
 public class SapDbBuilder extends SqlBuilder
 {
-    /** Database name of this builder */
-    public static final String DATABASENAME     = "SapDB";
-
-    // Note that SapDB and MaxDB currently use the same jdbc driver
-
-    /** The standard SapDB/MaxDB jdbc driver */
-    public static final String JDBC_DRIVER      = "com.sap.dbtech.jdbc.DriverSapDB";
-    /** The subprotocol used by the standard SapDB/MaxDB driver */
-    public static final String JDBC_SUBPROTOCOL = "sapdb";
-
-    
-    public SapDbBuilder()
-    {
-        setMaxIdentifierLength(32);
-        setRequiringNullAsDefaultValue(false);
-        setPrimaryKeyEmbedded(true);
-        setForeignKeysEmbedded(false);
-        setIndicesEmbedded(false);
-        setCommentPrefix("/*");
-        setCommentSuffix("*/");
-
-        addNativeTypeMapping(Types.ARRAY,         "LONG BYTE");
-        addNativeTypeMapping(Types.BIGINT,        "FIXED(38,0)");
-        addNativeTypeMapping(Types.BINARY,        "LONG BYTE");
-        addNativeTypeMapping(Types.BIT,           "BOOLEAN");
-        addNativeTypeMapping(Types.BLOB,          "LONG BYTE");
-        addNativeTypeMapping(Types.CLOB,          "LONG");
-        addNativeTypeMapping(Types.DISTINCT,      "LONG BYTE");
-        addNativeTypeMapping(Types.DOUBLE,        "DOUBLE PRECISION");
-        addNativeTypeMapping(Types.FLOAT,         "DOUBLE PRECISION");
-        addNativeTypeMapping(Types.JAVA_OBJECT,   "LONG BYTE");
-        addNativeTypeMapping(Types.LONGVARBINARY, "LONG BYTE");
-        addNativeTypeMapping(Types.LONGVARCHAR,   "LONG VARCHAR");
-        addNativeTypeMapping(Types.NULL,          "LONG BYTE");
-        addNativeTypeMapping(Types.NUMERIC,       "DECIMAL");
-        addNativeTypeMapping(Types.OTHER,         "LONG BYTE");
-        addNativeTypeMapping(Types.REF,           "LONG BYTE");
-        addNativeTypeMapping(Types.STRUCT,        "LONG BYTE");
-        addNativeTypeMapping(Types.TINYINT,       "SMALLINT");
-        addNativeTypeMapping(Types.VARBINARY,     "LONG BYTE");
-
-        // Types.DATALINK is only available since 1.4 so we're using the safe mapping method
-        addNativeTypeMapping("DATALINK", "LONG BYTE");
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.ddlutils.builder.SqlBuilder#getDatabaseName()
+    /**
+     * Creates a new builder instance.
+     * 
+     * @param info The platform info
      */
-    public String getDatabaseName()
+    public SapDbBuilder(PlatformInfo info)
     {
-        return DATABASENAME;
+        super(info);
     }
 
     /* (non-Javadoc)

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SqlBuilder.java?rev=232530&r1=232529&r2=232530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SqlBuilder.java Sat Aug 13 14:36:44 2005
@@ -18,9 +18,6 @@
 
 import java.io.IOException;
 import java.io.Writer;
-import java.lang.reflect.Field;
-import java.sql.Connection;
-import java.sql.SQLException;
 import java.sql.Types;
 import java.text.DateFormat;
 import java.text.NumberFormat;
@@ -33,7 +30,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.ddlutils.io.JdbcModelReader;
+import org.apache.ddlutils.PlatformInfo;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.ForeignKey;
@@ -61,7 +58,8 @@
  * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
  * @version $Revision$
  */
-public abstract class SqlBuilder {
+public abstract class SqlBuilder
+{
 
     private static final String LINE_SEPERATOR = System.getProperty("line.separator", "\n");
 
@@ -74,33 +72,8 @@
     /** The indentation used to indent commands */
     private String _indent = "    ";
 
-    /** Whether the database requires the explicit stating of NULL as the default value */
-    private boolean _requiringNullAsDefaultValue = false;
-
-    /** Whether primary key constraints are embedded inside the create table statement */
-    private boolean _primaryKeyEmbedded = true;
-    
-    /** Whether foreign key constraints are embedded inside the create table statement */
-    private boolean _foreignKeysEmbedded = false;
-
-    /** Whether indices are embedded inside the create table statement */
-    private boolean _indicesEmbedded = false;
-
-    /** Whether embedded foreign key constraints are explicitly named */
-    private boolean _embeddedForeignKeysNamed = false;
-
-    /** Is an ALTER TABLE needed to drop indexes? */
-    private boolean _useAlterTableForDrop = false;
-
-    /** Specifies the maximum length that an identifier (name of a table, column, constraint etc.)
-     *  can have for this database; use -1 if there is no limit */
-    private int _maxIdentifierLength = -1;
-
-    /** Whether identifiers are case sensitive or not */
-    private boolean _caseSensitive = false;
-
-    /** The string used for escaping values when generating textual SQL statements */
-    private String _valueQuoteChar = "'";
+    /** The platform info */
+    private PlatformInfo _info;
 
     /** An optional locale specification for number and date formatting */
     private String _valueLocale;
@@ -113,61 +86,29 @@
 
     /** The number formatter */
     private NumberFormat _valueNumberFormat;
-    
-    /** Whether comments are supported */
-    private boolean _commentsSupported = true;
-
-    /** The string that starts a comment */
-    private String _commentPrefix = "--";
-
-    /** The string that ends a comment */
-    private String _commentSuffix = "";
-
-    /** Contains non-default mappings from jdbc to native types */
-    private HashMap _specialTypes = new HashMap();
 
     //
     // Configuration
     //                
 
     /**
-     * Adds a mapping from jdbc type to database-native type.
+     * Creates a new sql builder.
      * 
-     * @param jdbcTypeCode The jdbc type code as defined by {@link java.sql.Types}
-     * @param nativeType   The native type
+     * @param info The plaftform information
      */
-    protected void addNativeTypeMapping(int jdbcTypeCode, String nativeType)
+    public SqlBuilder(PlatformInfo info)
     {
-        _specialTypes.put(new Integer(jdbcTypeCode), nativeType);
+        _info = info;
     }
 
     /**
-     * Adds a mapping from jdbc type to database-native type. Note that this
-     * method accesses the named constant in {@link java.sql.Types} via reflection
-     * and is thus safe to use under JDK 1.2/1.3 even with constants defined
-     * only in later Java versions - for these, the method simply will not add
-     * a mapping.
+     * Returns the platform info object.
      * 
-     * @param jdbcTypeName The jdbc type name, one of the constants defined in
-     *                     {@link java.sql.Types}
-     * @param nativeType   The native type
+     * @return The info object
      */
-    protected void addNativeTypeMapping(String jdbcTypeName, String nativeType)
+    public PlatformInfo getPlatformInfo()
     {
-        try
-        {
-            Field constant = Types.class.getField(jdbcTypeName);
-
-            if (constant != null)
-            {
-                addNativeTypeMapping(constant.getInt(null), nativeType);
-            }
-        }
-        catch (Exception ex)
-        {
-            // ignore -> won't be defined
-            // TODO: add a logging statement
-        }
+        return _info;
     }
 
     /**
@@ -211,178 +152,6 @@
     }
 
     /**
-     * Determines whether a NULL needs to be explicitly stated when the column
-     * has no specified default value. Default is false.
-     * 
-     * @return <code>true</code> if NULL must be written for empty default values
-     */
-    public boolean isRequiringNullAsDefaultValue()
-    {
-        return _requiringNullAsDefaultValue;
-    }
-    /**
-     * Specifies whether a NULL needs to be explicitly stated when the column
-     * has no specified default value. Default is false.
-     *
-     * @param requiresNullAsDefaultValue Whether NULL must be written for empty
-     *                                   default values
-     */
-    public void setRequiringNullAsDefaultValue(boolean requiresNullAsDefaultValue)
-    {
-        _requiringNullAsDefaultValue = requiresNullAsDefaultValue;
-    }
-
-    /**
-     * Determines whether primary key constraints are embedded in the create 
-     * table clause or as seperate alter table statements. The default is
-     * embedded pks.
-     * 
-     * @return <code>true</code> if pk constraints are embedded
-     */
-    public boolean isPrimaryKeyEmbedded()
-    {
-        return _primaryKeyEmbedded;
-    }
-
-    /**
-     * Specifies whether the primary key constraints are embedded in the create 
-     * table clause or as seperate alter table statements.
-     * 
-     * @param primaryKeyEmbedded Whether pk constraints are embedded
-     */
-    public void setPrimaryKeyEmbedded(boolean primaryKeyEmbedded)
-    {
-        _primaryKeyEmbedded = primaryKeyEmbedded;
-    }
-
-    /**
-     * Determines whether foreign key constraints are embedded in the create 
-     * table clause or as seperate alter table statements. Per default,
-     * foreign keys are external.
-     * 
-     * @return <code>true</code> if fk constraints are embedded
-     */
-    public boolean isForeignKeysEmbedded()
-    {
-        return _foreignKeysEmbedded;
-    }
-
-    /**
-     * Specifies whether foreign key constraints are embedded in the create 
-     * table clause or as seperate alter table statements.
-     * 
-     * @param foreignKeysEmbedded Whether fk constraints are embedded
-     */
-    public void setForeignKeysEmbedded(boolean foreignKeysEmbedded)
-    {
-        _foreignKeysEmbedded = foreignKeysEmbedded;
-    }
-
-    /**
-     * Determines whether the indices are embedded in the create table clause
-     * or as seperate statements. Per default, indices are external.
-     * 
-     * @return <code>true</code> if indices are embedded
-     */
-    public boolean isIndicesEmbedded()
-    {
-        return _indicesEmbedded;
-    }
-
-    /**
-     * Specifies whether indices are embedded in the create table clause or
-     * as seperate alter table statements.
-     * 
-     * @param indicesEmbedded Whether indices are embedded
-     */
-    public void setIndicesEmbedded(boolean indicesEmbedded)
-    {
-        _indicesEmbedded = indicesEmbedded;
-    }
-
-    /**
-     * Returns whether embedded foreign key constraints should have a name.
-     * 
-     * @return <code>true</code> if embedded fks have name
-     */
-    public boolean isEmbeddedForeignKeysNamed()
-    {
-        return _embeddedForeignKeysNamed;
-    }
-
-    /**
-     * Specifies whether embedded foreign key constraints should be named.
-     * 
-     * @param embeddedForeignKeysNamed Whether embedded fks shall have a name
-     */
-    public void setEmbeddedForeignKeysNamed(boolean embeddedForeignKeysNamed)
-    {
-        _embeddedForeignKeysNamed = embeddedForeignKeysNamed;
-    }
-
-    /**
-     * Determines whether an ALTER TABLE statement shall be used for dropping indices
-     * or constraints.  The default is false.
-     * 
-     * @return <code>true</code> if ALTER TABLE is required
-     */
-    public boolean isUseAlterTableForDrop()
-    {
-        return _useAlterTableForDrop;
-    }
-
-    /**
-     * Specifies whether an ALTER TABLE statement shall be used for dropping indices
-     * or constraints.
-     * 
-     * @param useAlterTableForDrop Whether ALTER TABLE will be used
-     */
-    public void setUseAlterTableForDrop(boolean useAlterTableForDrop)
-    {
-        _useAlterTableForDrop = useAlterTableForDrop;
-    }
-
-    /**
-     * Returns the maximum length of identifiers that this database allows.
-     * 
-     * @return The maximum identifier length, -1 if unlimited
-     */
-    public int getMaxIdentifierLength()
-    {
-        return _maxIdentifierLength;
-    }
-
-    /**
-     * Sets the maximum length of identifiers that this database allows.
-     * 
-     * @param maxIdentifierLength The maximum identifier length, -1 if unlimited
-     */
-    public void setMaxIdentifierLength(int maxIdentifierLength)
-    {
-        _maxIdentifierLength = maxIdentifierLength;
-    }
-
-    /**
-     * Determines whether the database has case sensitive identifiers.
-     *
-     * @return <code>true</code> if case of the the identifiers is important
-     */
-    public boolean isCaseSensitive()
-    {
-        return _caseSensitive;
-    }
-
-    /**
-     * Specifies whether the database has case sensitive identifiers.
-     *
-     * @param caseSensitive <code>true</code> if case of the the identifiers is important
-     */
-    public void setCaseSensitive(boolean caseSensitive)
-    {
-        _caseSensitive = caseSensitive;
-    }
-
-    /**
      * Returns the locale that is used for number and date formatting
      * (when printing default values and in generates insert/update/delete
      * statements).
@@ -456,124 +225,40 @@
         _valueNumberFormat = null;
     }
 
-    /**
-     * Returns the text that is used for for quoting values (e.g. text) when
-     * printing default values and in generates insert/update/delete statements.
-     * 
-     * @return The quote text
-     */
-    public String getValueQuoteChar()
-    {
-        return _valueQuoteChar;
-    }
-
-    /**
-     * Sets the text that is used for for quoting values (e.g. text) when
-     * printing default values and in generates insert/update/delete statements.
-     *
-     * @param valueQuoteChar The new quote text
-     */
-    public void setValueQuoteChar(String valueQuoteChar)
-    {
-        _valueQuoteChar = valueQuoteChar;
-    }
-
-    /**
-     * Determines whether the database supports comments.
-     *
-     * @return <code>true</code> if comments are supported
-     */
-    public boolean getCommentsSupported()
-    {
-        return _commentsSupported;
-    }
-
-    /**
-     * Specifies whether comments are supported by the database.
-     * 
-     * @param commentsSupported <code>true</code> if comments are supported
-     */
-    public void setCommentsSupported(boolean commentsSupported)
-    {
-        _commentsSupported = commentsSupported;
-    }
-
-    /**
-     * Returns the string that denotes the beginning of a comment.
-     *
-     * @return The comment prefix
-     */
-    public String getCommentPrefix()
-    {
-        return _commentPrefix;
-    }
-
-    /**
-     * Sets the text that starts a comment.
-     * 
-     * @param commentPrefix The new comment prefix
-     */
-    public void setCommentPrefix(String commentPrefix)
-    {
-        _commentPrefix = (commentPrefix == null ? "" : commentPrefix);
-    }
-
-    /**
-     * Returns the string that denotes the end of a comment. Note that comments will
-     * be always on their own line.
-     *
-     * @return The comment suffix
-     */
-    public String getCommentSuffix()
-    {
-        return _commentSuffix;
-    }
-
-    /**
-     * Sets the text that ends a comment.
-     * 
-     * @param commentSuffix The new comment suffix
-     */
-    public void setCommentSuffix(String commentSuffix)
-    {
-        _commentSuffix = (commentSuffix == null ? "" : commentSuffix);
-    }
-
     //
     // public interface
     //
 
     /**
-     * Returns the name of the database that this builder is for.
-     * 
-     * @return The database name
-     */
-    public abstract String getDatabaseName();
-    
-    /**
-     * Outputs the DDL required to drop and recreate the database.
+     * Outputs the DDL required to drop and (re)create all tables in the database model.
      * 
      * @param database The database model 
      */
-    public void createDatabase(Database database) throws IOException
+    public void createTables(Database database) throws IOException
     {
-        createDatabase(database, true);
+        createTables(database, true);
     }
 
     /**
-     * Outputs the DDL required to drop (if requested) and recreate the database.
+     * Outputs the DDL required to drop (if requested) and (re)create all tables in the database model.
      * 
      * @param database   The database
      * @param dropTables Whether to drop tables before creating them
      */
-    public void createDatabase(Database database, boolean dropTables) throws IOException
+    public void createTables(Database database, boolean dropTables) throws IOException
     {
         if (dropTables)
         {
-            dropDatabase(database);
+            dropTables(database);
         }
 
-        createTables(database);
+        for (Iterator it = database.getTables().iterator(); it.hasNext(); )
+        {
+            Table table = (Table)it.next();
+
+            writeTableComment(table);
+            createTable(database, table);
+        }
 
         // we're writing the external foreignkeys last to ensure that all referenced tables are already defined
         createExternalForeignKeys(database);
@@ -584,37 +269,33 @@
      * the current specified database schema. Drops and modifications will
      * not be made.
      *
-     * @param desiredDb  The desired database schema
-     * @param connection A connection to the existing database that shall be modified
-     * @throws IOException  If the ddl could notz be written
-     * @throws SQLException if there is an error reading the current schema
+     * @param currentModel  The current database schema
+     * @param desiredModel  The desired database schema
      */
-    public void alterDatabase(Database desiredDb, Connection connection) throws IOException, SQLException
+    public void alterDatabase(Database currentModel, Database desiredModel) throws IOException
     {
-        alterDatabase(desiredDb, connection, false, false);
+        alterDatabase(currentModel, desiredModel, false, false);
     }
 
     /**
      * Generates the DDL to modify an existing database so the schema matches
      * the current specified database schema.
      *
-     * @param desiredDb     The desired database schema
+     * @param currentModel  The current database schema
+     * @param desiredModel  The desired database schema
      * @param connection    A connection to the existing database that shall be modified
      * @param doDrops       Whether columns and indexes should be dropped if not in the
      *                      new schema
      * @param modifyColumns Whether columns should be altered for datatype, size as required
-     * @throws IOException  If the ddl could not be written
-     * @throws SQLException If there is an error reading the current schema
      */
-    public void alterDatabase(Database desiredDb, Connection connection, boolean doDrops, boolean modifyColumns) throws IOException, SQLException
+    public void alterDatabase(Database currentModel, Database desiredModel, boolean doDrops, boolean modifyColumns) throws IOException
     {
-        Database  currentDb = new JdbcModelReader(connection).getDatabase();
         ArrayList newTables = new ArrayList();
 
-        for (Iterator tableIt = desiredDb.getTables().iterator(); tableIt.hasNext();)
+        for (Iterator tableIt = desiredModel.getTables().iterator(); tableIt.hasNext();)
         {
             Table desiredTable = (Table)tableIt.next();
-            Table currentTable = currentDb.findTable(desiredTable.getName());
+            Table currentTable = currentModel.findTable(desiredTable.getName());
 
             if (currentTable == null)
             {
@@ -622,7 +303,7 @@
                 {
                     _log.info("Creating table " + desiredTable.getName());
                 }
-                createTable(desiredDb, desiredTable);
+                createTable(desiredModel, desiredTable);
                 // we're deferring foreignkey generation
                 newTables.add(desiredTable);
             }
@@ -675,7 +356,7 @@
                         {
                             _log.info("Creating foreign key " + desiredTable.getName() + "." + desiredFk);
                         }
-                        writeExternalForeignKeyCreateStmt(desiredDb, desiredTable, desiredFk);
+                        writeExternalForeignKeyCreateStmt(desiredModel, desiredTable, desiredFk);
                     }
                 }
 
@@ -785,14 +466,14 @@
         //TODO should we try to generate new FKs on existing tables?
         for (Iterator fkIt = newTables.iterator(); fkIt.hasNext();)
         {
-            createExternalForeignKeys(desiredDb, (Table)fkIt.next());
+            createExternalForeignKeys(desiredModel, (Table)fkIt.next());
         }
 
         // check for table drops
-        for (Iterator tableIt = currentDb.getTables().iterator(); tableIt.hasNext();)
+        for (Iterator tableIt = currentModel.getTables().iterator(); tableIt.hasNext();)
         {
             Table currentTable = (Table)tableIt.next();
-            Table desiredTable = desiredDb.findTable(currentTable.getName());
+            Table desiredTable = desiredModel.findTable(currentTable.getName());
 
             if ((desiredTable == null) && (currentTable.getName() != null) && (currentTable.getName().length() > 0))
             {
@@ -819,22 +500,6 @@
     }
 
     /** 
-     * Outputs the DDL to create all tables of the given database model.
-     * 
-     * @param database The database
-     */
-    public void createTables(Database database) throws IOException
-    {
-        for (Iterator it = database.getTables().iterator(); it.hasNext(); )
-        {
-            Table table = (Table)it.next();
-
-            writeTableComment(table);
-            createTable(database, table);
-        }
-    }
-
-    /** 
      * Outputs the DDL to create the table along with any non-external constraints as well
      * as with external primary keys and indices (but not foreign keys).
      * 
@@ -849,15 +514,15 @@
 
         writeColumns(table);
 
-        if (isPrimaryKeyEmbedded())
+        if (getPlatformInfo().isPrimaryKeyEmbedded())
         {
             writeEmbeddedPrimaryKeysStmt(table);
         }
-        if (isForeignKeysEmbedded())
+        if (getPlatformInfo().isForeignKeysEmbedded())
         {
             writeEmbeddedForeignKeysStmt(database, table);
         }
-        if (isIndicesEmbedded())
+        if (getPlatformInfo().isIndicesEmbedded())
         {
             writeEmbeddedIndicesStmt(table);
         }
@@ -865,11 +530,11 @@
         print(")");
         printEndOfStatement();
 
-        if (!isPrimaryKeyEmbedded())
+        if (!getPlatformInfo().isPrimaryKeyEmbedded())
         {
             writeExternalPrimaryKeysCreateStmt(table);
         }
-        if (!isIndicesEmbedded())
+        if (!getPlatformInfo().isIndicesEmbedded())
         {
             writeExternalIndicesCreateStmt(table);
         }
@@ -896,7 +561,7 @@
      */
     public void createExternalForeignKeys(Database database, Table table) throws IOException
     {
-        if (!isForeignKeysEmbedded())
+        if (!getPlatformInfo().isForeignKeysEmbedded())
         {
             int numKey = 1;
 
@@ -912,7 +577,7 @@
      * 
      * @param database The database 
      */
-    public void dropDatabase(Database database) throws IOException
+    public void dropTables(Database database) throws IOException
     {
         List tables = database.getTables();
 
@@ -964,7 +629,7 @@
      */
     public void dropExternalForeignKeys(Table table) throws IOException
     {
-        if (!isForeignKeysEmbedded())
+        if (!getPlatformInfo().isForeignKeysEmbedded())
         {
             int numKey = 1;
 
@@ -1221,7 +886,7 @@
      */
     protected String getTableName(Table table)
     {
-        return shortenName(table.getName(), _maxIdentifierLength);
+        return shortenName(table.getName(), getPlatformInfo().getMaxIdentifierLength());
     }
     
     /** 
@@ -1276,7 +941,7 @@
      */
     protected String getColumnName(Column column) throws IOException
     {
-        return shortenName(column.getName(), _maxIdentifierLength);
+        return shortenName(column.getName(), getPlatformInfo().getMaxIdentifierLength());
     }
 
     /** 
@@ -1295,16 +960,16 @@
         if (column.getDefaultValue() != null)
         {
             print(" DEFAULT ");
-            print(_valueQuoteChar);
+            print(getPlatformInfo().getValueQuoteChar());
             print(column.getDefaultValue());
-            print(_valueQuoteChar);
+            print(getPlatformInfo().getValueQuoteChar());
         }
         if (column.isRequired())
         {
             print(" ");
             writeColumnNotNullableStmt();
         }
-        else if (isRequiringNullAsDefaultValue() &&
+        else if (getPlatformInfo().isRequiringNullAsDefaultValue() &&
                  (TypeMap.isTextType(column.getTypeCode()) || TypeMap.isBinaryType(column.getTypeCode())))
         {
             print(" ");
@@ -1379,7 +1044,7 @@
      */
     protected String getNativeType(Column column)
     {
-        String nativeType = (String)_specialTypes.get(new Integer(column.getTypeCode()));
+        String nativeType = (String)getPlatformInfo().getNativeType(column.getTypeCode());
 
         return nativeType == null ? column.getType() : nativeType;
     }
@@ -1405,7 +1070,7 @@
         {
             // Note: TIMESTAMP (java.sql.Timestamp) is properly handled by its toString method
             case Types.DATE:
-                result.append(_valueQuoteChar);
+                result.append(getPlatformInfo().getValueQuoteChar());
                 if (!(value instanceof String) && (_valueDateFormat != null))
                 {
                     // TODO: Can the format method handle java.sql.Date properly ?
@@ -1415,10 +1080,10 @@
                 {
                     result.append(value.toString());
                 }
-                result.append(_valueQuoteChar);
+                result.append(getPlatformInfo().getValueQuoteChar());
                 break;
             case Types.TIME:
-                result.append(_valueQuoteChar);
+                result.append(getPlatformInfo().getValueQuoteChar());
                 if (!(value instanceof String) && (_valueTimeFormat != null))
                 {
                     // TODO: Can the format method handle java.sql.Date properly ?
@@ -1428,14 +1093,14 @@
                 {
                     result.append(value.toString());
                 }
-                result.append(_valueQuoteChar);
+                result.append(getPlatformInfo().getValueQuoteChar());
                 break;
             case Types.REAL:
             case Types.NUMERIC:
             case Types.FLOAT:
             case Types.DOUBLE:
             case Types.DECIMAL:
-                result.append(_valueQuoteChar);
+                result.append(getPlatformInfo().getValueQuoteChar());
                 if (!(value instanceof String) && (_valueNumberFormat != null))
                 {
                     result.append(_valueNumberFormat.format(value));
@@ -1444,12 +1109,12 @@
                 {
                     result.append(value.toString());
                 }
-                result.append(_valueQuoteChar);
+                result.append(getPlatformInfo().getValueQuoteChar());
                 break;
             default:
-                result.append(_valueQuoteChar);
+                result.append(getPlatformInfo().getValueQuoteChar());
                 result.append(value.toString());
-                result.append(_valueQuoteChar);
+                result.append(getPlatformInfo().getValueQuoteChar());
                 break;
         }
         return result.toString();
@@ -1559,7 +1224,7 @@
             result.append("_");
             result.append(suffix);
         }
-        return shortenName(result.toString(), _maxIdentifierLength);
+        return shortenName(result.toString(), getPlatformInfo().getMaxIdentifierLength());
     }
 
     /**
@@ -1731,13 +1396,13 @@
      */
     public void writeExternalIndexDropStmt(Table table, Index index) throws IOException
     {
-        if (isUseAlterTableForDrop())
+        if (getPlatformInfo().isUseAlterTableForDrop())
         {
             writeTableAlterStmt(table);
         }
         print("DROP INDEX ");
         print(getIndexName(index));
-        if (!isUseAlterTableForDrop())
+        if (!getPlatformInfo().isUseAlterTableForDrop())
         {
             print(" ON ");
             print(getTableName(table));
@@ -1769,7 +1434,7 @@
                 println(",");
                 printIndent();
                 
-                if (isEmbeddedForeignKeysNamed())
+                if (getPlatformInfo().isEmbeddedForeignKeysNamed())
                 {
                     print("CONSTRAINT ");
                     print(getConstraintName(null, table, "FK", Integer.toString(numKey)));
@@ -1878,14 +1543,14 @@
      */
     protected void printComment(String text) throws IOException
     {
-        if (getCommentsSupported())
+        if (getPlatformInfo().isCommentsSupported())
         {
-            print(getCommentPrefix());
+            print(getPlatformInfo().getCommentPrefix());
             // Some databases insist on a space after the prefix
             print(" ");
             print(text);
             print(" ");
-            print(getCommentSuffix());
+            print(getPlatformInfo().getCommentSuffix());
             println();
         }
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java?rev=232530&r1=232529&r2=232530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java Sat Aug 13 14:36:44 2005
@@ -17,14 +17,14 @@
  */
 
 import java.io.IOException;
-import java.sql.Types;
 
+import org.apache.ddlutils.PlatformInfo;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.ForeignKey;
 import org.apache.ddlutils.model.Table;
 
 /**
- * An SQL Builder for Sybase
+ * The SQL Builder for Sybase
  * 
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
@@ -32,56 +32,14 @@
  */
 public class SybaseBuilder extends SqlBuilder
 {
-    /** Database name of this builder */
-    public static final String DATABASENAME     = "Sybase";
-    /** The standard Sybase jdbc driver */
-    public static final String JDBC_DRIVER      = "com.sybase.jdbc2.jdbc.SybDriver";
-    /** The old Sybase jdbc driver */
-    public static final String JDBC_DRIVER_OLD  = "com.sybase.jdbc.SybDriver";
-    /** The subprotocol used by the standard Sybase driver */
-    public static final String JDBC_SUBPROTOCOL = "sybase:Tds";
-
-    public SybaseBuilder()
-    {
-        setMaxIdentifierLength(30);
-        setRequiringNullAsDefaultValue(false);
-        setPrimaryKeyEmbedded(true);
-        setForeignKeysEmbedded(false);
-        setIndicesEmbedded(false);
-        setCommentPrefix("/*");
-        setCommentSuffix("*/");
-
-        addNativeTypeMapping(Types.ARRAY,         "IMAGE");
-        addNativeTypeMapping(Types.BIGINT,        "DECIMAL(19,0)");
-        addNativeTypeMapping(Types.BLOB,          "IMAGE");
-        addNativeTypeMapping(Types.CLOB,          "TEXT");
-        addNativeTypeMapping(Types.DATE,          "DATETIME");
-        addNativeTypeMapping(Types.DISTINCT,      "IMAGE");
-        addNativeTypeMapping(Types.DOUBLE,        "DOUBLE PRECISION");
-        addNativeTypeMapping(Types.FLOAT,         "DOUBLE PRECISION");
-        addNativeTypeMapping(Types.INTEGER,       "INT");
-        addNativeTypeMapping(Types.JAVA_OBJECT,   "IMAGE");
-        addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE");
-        addNativeTypeMapping(Types.LONGVARCHAR,   "TEXT");
-        addNativeTypeMapping(Types.NULL,          "IMAGE");
-        addNativeTypeMapping(Types.OTHER,         "IMAGE");
-        addNativeTypeMapping(Types.REF,           "IMAGE");
-        addNativeTypeMapping(Types.STRUCT,        "IMAGE");
-        addNativeTypeMapping(Types.TIME,          "DATETIME");
-        addNativeTypeMapping(Types.TIMESTAMP,     "DATETIME");
-        addNativeTypeMapping(Types.TINYINT,       "SMALLINT");
-
-        // These types are only available since 1.4 so we're using the safe mapping method
-        addNativeTypeMapping("BOOLEAN",  "BIT");
-        addNativeTypeMapping("DATALINK", "IMAGE");
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.ddlutils.builder.SqlBuilder#getDatabaseName()
+    /**
+     * Creates a new builder instance.
+     * 
+     * @param info The platform info
      */
-    public String getDatabaseName()
+    public SybaseBuilder(PlatformInfo info)
     {
-        return DATABASENAME;
+        super(info);
     }
 
     /* (non-Javadoc)

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaClassCache.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaClassCache.java?rev=232530&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaClassCache.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaClassCache.java Sat Aug 13 14:36:44 2005
@@ -0,0 +1,147 @@
+package org.apache.ddlutils.dynabean;
+
+/*
+ * Copyright 1999-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.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.DynaBean;
+import org.apache.commons.beanutils.DynaClass;
+import org.apache.ddlutils.DynaSqlException;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Provides a cache of dyna class instances for a specific model, as well as
+ * helper methods for dealing with these classes.
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision: 231110 $
+ */
+public class DynaClassCache
+{
+    /** A cache of the SqlDynaClasses per table name */
+    private Map _dynaClassCache = new HashMap();
+
+    /**
+     * Creates a new dyna bean instance for the given table.
+     * 
+     * @param table The table
+     * @return The new empty dyna bean
+     */
+    public DynaBean createNewInstance(Table table) throws DynaSqlException
+    {
+        try
+        {
+            return getDynaClass(table).newInstance();
+        }
+        catch (InstantiationException ex)
+        {
+            throw new DynaSqlException("Could not create a new dyna bean for table "+table.getName(), ex);
+        }
+        catch (IllegalAccessException ex)
+        {
+            throw new DynaSqlException("Could not create a new dyna bean for table "+table.getName(), ex);
+        }
+    }
+
+    /**
+     * Creates a new dyna bean instance for the given table and copies the values from the
+     * given source object. The source object can be a bean, a map or a dyna bean.
+     * This method is useful when iterating through an arbitrary dyna bean
+     * result set after performing a query, then creating a copy as a DynaBean
+     * which is bound to a specific table.
+     * This new DynaBean can be kept around, changed and stored back into the database.
+     *
+     * @param table  The table to create the dyna bean for
+     * @param source Either a bean, a {@link java.util.Map} or a dyna bean that will be used
+     *               to populate the resultint dyna bean
+     * @return A new dyna bean bound to the given table and containing all the properties from
+     *         the source object
+     */
+    public DynaBean copy(Table table, Object source) throws DynaSqlException
+    {
+        DynaBean answer = createNewInstance(table);
+
+        try
+        {
+            // copy all the properties from the source
+            BeanUtils.copyProperties(answer, source);
+        }
+        catch (InvocationTargetException ex)
+        {
+            throw new DynaSqlException("Could not populate the bean", ex);
+        }
+        catch (IllegalAccessException ex)
+        {
+            throw new DynaSqlException("Could not populate the bean", ex);
+        }
+
+        return answer;
+    }
+
+    /**
+     * Returns the {@link SqlDynaClass} for the given table. If the it does not
+     * exist yet, a new one will be created based on the Table definition.
+     * 
+     * @param table The table
+     * @return The <code>SqlDynaClass</code> for the indicated table
+     */
+    public SqlDynaClass getDynaClass(Table table)
+    {
+        SqlDynaClass answer = (SqlDynaClass)_dynaClassCache.get(table.getName());
+
+        if (answer == null)
+        {
+            answer = createDynaClass(table);
+            _dynaClassCache.put(table.getName(), answer);
+        }
+        return answer;
+    }
+
+    /**
+     * Returns the {@link SqlDynaClass} for the given bean.
+     * 
+     * @return The dyna bean class
+     */
+    public SqlDynaClass getDynaClass(DynaBean dynaBean) throws DynaSqlException
+    {
+        DynaClass dynaClass = dynaBean.getDynaClass();
+
+        if (dynaClass instanceof SqlDynaClass)
+        {
+            return (SqlDynaClass) dynaClass;
+        }
+        else
+        {
+            // TODO: we could autogenerate an SqlDynaClass here ?
+            throw new DynaSqlException("The dyna bean is not an instance of a SqlDynaClass");
+        }
+    }
+
+    /**
+     * Creates a new {@link SqlDynaClass} instance for the given table based on the table definition.
+     * 
+     * @param table The table
+     */
+    private SqlDynaClass createDynaClass(Table table)
+    {
+        return SqlDynaClass.newInstance(table);
+    }
+}

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java?rev=232530&r1=232529&r2=232530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java Sat Aug 13 14:36:44 2005
@@ -15,7 +15,10 @@
 import org.apache.commons.beanutils.DynaClass;
 import org.apache.commons.beanutils.DynaProperty;
 import org.apache.commons.collections.map.ListOrderedMap;
+import org.apache.ddlutils.DynaSqlException;
+import org.apache.ddlutils.PlatformInfo;
 import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.Table;
 
 /**
@@ -42,12 +45,13 @@
     /**
      * Creates a new iterator.
      * 
-     * @param dynaSql            The dyna sql instance
+     * @param platformInfo       The platform info
+     * @param model              The database model
      * @param resultSet          The result set
      * @param cleanUpAfterFinish Whether to close the statement and connection after finishing
      *                           the iteration, upon on exception, or when this iterator is garbage collected
      */
-    public DynaSqlIterator(DynaSql dynaSql, ResultSet resultSet, boolean cleanUpAfterFinish) throws DynaSqlException
+    public DynaSqlIterator(PlatformInfo platformInfo, Database model, ResultSet resultSet, boolean cleanUpAfterFinish) throws DynaSqlException
     {
         if (resultSet != null)
         {
@@ -56,7 +60,7 @@
 
             try
             {
-                initFromMetaData(dynaSql, resultSet);
+                initFromMetaData(platformInfo, model, resultSet);
             }
             catch (SQLException ex)
             {
@@ -73,15 +77,16 @@
     /**
      * Initializes this iterator from the resultset metadata.
      * 
-     * @param dynaSql   The dyna sql instance
-     * @param resultSet The result set
+     * @param platformInfo The platform info
+     * @param model        The database model
+     * @param resultSet    The result set
      */
-    private void initFromMetaData(DynaSql dynaSql, ResultSet resultSet) throws SQLException
+    private void initFromMetaData(PlatformInfo platformInfo, Database model, ResultSet resultSet) throws SQLException
     {
         ResultSetMetaData metaData         = resultSet.getMetaData();
         String            tableName        = null;
         boolean           singleKnownTable = true;
-        boolean           caseSensitive    = (dynaSql.getSqlBuilder() == null ? false : dynaSql.getSqlBuilder().isCaseSensitive());
+        boolean           caseSensitive    = platformInfo.isCaseSensitive();
 
         for (int idx = 1; idx <= metaData.getColumnCount(); idx++)
         {
@@ -99,7 +104,7 @@
                 }
             }
 
-            Table  table      = dynaSql.getDatabase().findTable(tableOfColumn, caseSensitive);
+            Table  table      = model.findTable(tableOfColumn, caseSensitive);
             String columnName = metaData.getColumnName(idx);
             String propName   = columnName;
 
@@ -116,7 +121,7 @@
         }
         if (singleKnownTable && (tableName != null))
         {
-            _dynaClass = dynaSql.getDynaClass(tableName);
+            _dynaClass = model.getDynaClassFor(tableName);
         }
         else
         {

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataReader.java?rev=232530&r1=232529&r2=232530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataReader.java Sat Aug 13 14:36:44 2005
@@ -19,8 +19,8 @@
 import java.sql.Types;
 import java.util.HashMap;
 import java.util.Iterator;
+
 import org.apache.commons.digester.Digester;
-import org.apache.ddlutils.dynabean.DynaSql;
 import org.apache.ddlutils.io.converters.DateConverter;
 import org.apache.ddlutils.io.converters.NumberConverter;
 import org.apache.ddlutils.io.converters.SqlTypeConverter;
@@ -196,10 +196,6 @@
                 throw new NullPointerException("No data sink model specified");
             }
 
-            DynaSql dynaSql = new DynaSql(null);
-    
-            dynaSql.setDatabase(_model);
-
             DigesterRules rules = new DigesterRules();
 
             rules.setCaseSensitive(isCaseSensitive());
@@ -210,7 +206,7 @@
                 Table  table = (Table)tableIt.next();
                 String path  = "data/"+table.getName();
     
-                addRule(path, new DynaSqlCreateRule(dynaSql, table, _sink));
+                addRule(path, new DynaSqlCreateRule(_model, table, _sink));
                 for (Iterator columnIt = table.getColumns().iterator(); columnIt.hasNext();)
                 {
                     Column           column    = (Column)columnIt.next();

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataToDatabaseSink.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataToDatabaseSink.java?rev=232530&r1=232529&r2=232530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataToDatabaseSink.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DataToDatabaseSink.java Sat Aug 13 14:36:44 2005
@@ -22,12 +22,12 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import javax.sql.DataSource;
+
 import org.apache.commons.beanutils.DynaBean;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.ddlutils.builder.SqlBuilder;
-import org.apache.ddlutils.dynabean.DynaSql;
+import org.apache.ddlutils.DynaSqlException;
+import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.dynabean.SqlDynaClass;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Database;
@@ -46,7 +46,9 @@
     private final Log _log = LogFactory.getLog(DataToDatabaseSink.class);
  
     /** Generates the sql and writes it to the database */
-    private DynaSql _dynaSql;
+    private Platform _platform;
+    /** The database model */
+    private Database _model;
     /** The connection to the database */
     private Connection _connection;
     /** Whether to stop when an error has occurred while inserting a bean into the database */
@@ -61,13 +63,13 @@
     /**
      * Creates a new sink instance.
      * 
-     * @param dataSource The database to write to
-     * @param model      The database model
-     * @param builder    The sql builder
+     * @param platform The database platform
+     * @param model    The database model
      */
-    public DataToDatabaseSink(DataSource dataSource, Database model, SqlBuilder builder)
+    public DataToDatabaseSink(Platform platform, Database model)
     {
-        _dynaSql = new DynaSql(builder, dataSource, model);
+        _platform = platform;
+        _model    = model;
     }
 
     /**
@@ -145,7 +147,7 @@
         // lists of already-processed identities for these tables
         _processedIdentities.clear();
         _waitingObjects.clear();
-        for (Iterator tableIt = _dynaSql.getDatabase().getTables().iterator(); tableIt.hasNext();)
+        for (Iterator tableIt = _model.getTables().iterator(); tableIt.hasNext();)
         {
             Table curTable = (Table)tableIt.next();
 
@@ -161,9 +163,9 @@
         }
         try
         {
-            _connection = _dynaSql.borrowConnection();
+            _connection = _platform.borrowConnection();
         }
-        catch (SQLException ex)
+        catch (DynaSqlException ex)
         {
             throw new DataSinkException(ex);
         }
@@ -174,7 +176,7 @@
      */
     public void addBean(DynaBean bean) throws DataSinkException
     {
-        Table table = _dynaSql.getSqlDynaClass(bean).getTable();
+        Table table = _model.getDynaClassFor(bean).getTable();
 
         if (!table.getForeignKeys().isEmpty())
         {
@@ -217,7 +219,7 @@
         
         try
         {
-            _dynaSql.insert(bean, _connection);
+            _platform.insert(_model, bean, _connection);
             if (!_connection.getAutoCommit())
             {
                 _connection.commit();
@@ -227,11 +229,11 @@
                 _log.debug("Inserted bean "+buildIdentityFromPKs(table, bean).toString());
             }
         }
-        catch (SQLException ex)
+        catch (Exception ex)
         {
             if (_haltOnErrors)
             {
-                _dynaSql.returnConnection(_connection);
+                _platform.returnConnection(_connection);
                 throw new DataSinkException(ex);
             }
             else

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DynaSqlCreateRule.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DynaSqlCreateRule.java?rev=232530&r1=232529&r2=232530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DynaSqlCreateRule.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DynaSqlCreateRule.java Sat Aug 13 14:36:44 2005
@@ -18,22 +18,22 @@
 
 import org.apache.commons.beanutils.DynaBean;
 import org.apache.commons.digester.Rule;
-import org.apache.ddlutils.dynabean.DynaSql;
+import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.Table;
 import org.xml.sax.Attributes;
 
 /**
- * A digester rule for creating dyna beans via the {@link org.apache.ddlutils.dynabean.DynaSql} class.
+ * A digester rule for creating dyna beans.
  * 
  * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
  * @version $Revision:$
  */
 public class DynaSqlCreateRule extends Rule
 {
-    /** The dyna sql instance to use for creating the dyna beans */
-    private DynaSql _dynaSql;
+    /** The database model for which we'l be creating beans */
+    private Database _model;
     /** The table that we're creating instances for */
-    private Table   _table;
+    private Table    _table;
     /** The object that will receive the read beans */
     private DataSink _receiver;
 
@@ -44,9 +44,9 @@
      * @param table    The table that we're creating instances for
      * @param receiver The object that will receive the read beans
      */
-    public DynaSqlCreateRule(DynaSql dynaSql, Table table, DataSink receiver)
+    public DynaSqlCreateRule(Database model, Table table, DataSink receiver)
     {
-        _dynaSql  = dynaSql;
+        _model    = model;
         _table    = table;
         _receiver = receiver;
     }
@@ -56,7 +56,7 @@
      */
     public void begin(String namespace, String name, Attributes attributes) throws Exception
     {
-        Object instance = _dynaSql.newInstance(_table.getName());
+        Object instance = _model.createDynaBeanFor(_table);
 
         if (digester.getLogger().isDebugEnabled())
         {

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Database.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Database.java?rev=232530&r1=232529&r2=232530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Database.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Database.java Sat Aug 13 14:36:44 2005
@@ -20,45 +20,51 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.beanutils.DynaBean;
+import org.apache.ddlutils.DynaSqlException;
+import org.apache.ddlutils.dynabean.DynaClassCache;
+import org.apache.ddlutils.dynabean.SqlDynaClass;
+
 /**
- * Models a database.
+ * Represents the database model, ie. the tables in the database. It also
+ * contains the corresponding dyna classes for creating dyna beans for the
+ * objects stored in the tables.
  *
- * @version $Id$
  * @author John Marshall/Connectria
  * @author Matthew Hawthorne
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision$
  */
 public class Database
 {
-    private String name;
-
-    private String idMethod;
-
-    /** Database version id */
-    private String version;
-
-    private List tables = new ArrayList();
+    /** The name of the database model */
+    private String _name;
+    /** The method for generating primary keys (currently ignored) */
+    private String _idMethod;
+    /** The version of the model */
+    private String _version;
+    /** The tables */
+    private List _tables = new ArrayList();
 
-    public Database()
-    {
-    }
+    /** The dyna class cache for this model */
+    private DynaClassCache _dynaClassCache = new DynaClassCache();
 
     /**
      * Adds all tables from the other database to this database.
      * Note that the other database is not changed.
      * 
      * @param otherDb The other database model
-     * @exception IllegalArgumentException If duplicated tables were found
      */
-    public void mergeWith(Database otherDb) throws IllegalArgumentException
+    public void mergeWith(Database otherDb) throws DynaSqlException
     {
-        for (Iterator it = otherDb.tables.iterator(); it.hasNext();)
+        for (Iterator it = otherDb._tables.iterator(); it.hasNext();)
         {
             Table table = (Table)it.next();
 
             if (findTable(table.getName()) != null)
             {
-                // TODO: It might make more sense to log a warning and overwrite the table ?
-                throw new IllegalArgumentException("Table "+table.getName()+" already defined in this database");
+                // TODO: It might make more sense to log a warning and overwrite the table (or merge them) ?
+                throw new DynaSqlException("Cannot merge the models because table "+table.getName()+" already defined in this model");
             }
             try
             {
@@ -71,41 +77,107 @@
         }
     }
 
+    /**
+     * Returns the name of this database model.
+     * 
+     * @return The name
+     */
     public String getName()
     {
-        return name;
+        return _name;
     }
 
+    /**
+     * Sets the name of this database model.
+     * 
+     * @param name The name
+     */
     public void setName(String name)
     {
-        this.name=name;
+        _name = name;
     }
 
+    /**
+     * Returns the version of this database model.
+     * 
+     * @return The version
+     */
     public String getVersion()
     {
-        return version;
+        return _version;
     }
 
-    public void setVersion(String ver)
+    /**
+     * Sets the version of this database model.
+     * 
+     * @param version The version
+     */
+    public void setVersion(String version)
     {
-        version = ver;
+        _version = version;
     }
 
+    /**
+     * Returns the method for generating primary key values.
+     * 
+     * @return The method
+     */
+    public String getIdMethod()
+    {
+        return _idMethod;
+    }
 
+    /**
+     * Sets the method for generating primary key values. Note that this
+     * value is ignored by DdlUtils and only for compatibility with Torque.
+     * 
+     * @param idMethod The method
+     */
     public void setIdMethod(String idMethod)
     {
-        this.idMethod=idMethod;
+        _idMethod = idMethod;
     }
 
+    /**
+     * Returns the list of tables in this model.
+     * 
+     * @return The tables
+     */
+    public List getTables()
+    {
+        return _tables;
+    }
 
+    /**
+     * Returns the table at the specified position.
+     * 
+     * @param index The index of the table
+     * @return The table
+     */
+    public Table getTable(int index)
+    {
+        return (Table)_tables.get(index);
+    }
+
+    /**
+     * Adds a table.
+     * 
+     * @param table The table to add
+     */
     public void addTable(Table table)
     {
-        tables.add(table);
+        _tables.add(table);
     }
 
-    public List getTables()
+    /**
+     * Replaces the table at the specified position.
+     * 
+     * @param index The index of the table
+     * @param table The new table
+     */
+    public void setTable(int index, Table table)
     {
-        return tables;
+        _tables.set(index, table);
     }
 
     // Helper methods
@@ -134,7 +206,7 @@
      */
     public Table findTable(String name, boolean caseSensitive)
     {
-        for (Iterator iter = tables.iterator(); iter.hasNext();)
+        for (Iterator iter = _tables.iterator(); iter.hasNext();)
         {
             Table table = (Table) iter.next();
 
@@ -156,21 +228,46 @@
         return null;
     }
 
-    // Additions for PropertyUtils
-
-    public void setTable(int index, Table table)
+    /**
+     * Returns the {@link org.apache.ddlutils.dynabean.SqlDynaClass} for the given table name. If the it does not
+     * exist yet, a new one will be created based on the Table definition.
+     * 
+     * @return The <code>SqlDynaClass</code> for the indicated table or <code>null</code>
+     *         if the model contains no such table
+     */
+    public SqlDynaClass getDynaClassFor(String tableName)
     {
-        addTable(table);
+        Table table = findTable(tableName);
+
+        return table != null ? _dynaClassCache.getDynaClass(table) : null;
     }
 
-    public Table getTable(int index)
+    /**
+     * Returns the {@link org.apache.ddlutils.dynabean.SqlDynaClass} for the given dyna bean.
+     * 
+     * @return The <code>SqlDynaClass</code> for the given bean
+     */
+    public SqlDynaClass getDynaClassFor(DynaBean bean)
     {
-        return (Table) tables.get(index);
+        return _dynaClassCache.getDynaClass(bean);
     }
 
+    /**
+     * Creates a new dyna bean for the given table.
+     * 
+     * @return The new dyna bean
+     */
+    public DynaBean createDynaBeanFor(Table table) throws DynaSqlException
+    {
+        return _dynaClassCache.createNewInstance(table);
+    }
 
+    /*
+     * (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
     public String toString()
     {
-        return super.toString() + "[name=" + name + ";tableCount=" + tables.size() + "]";
+        return super.toString() + "[name=" + _name + ";tableCount=" + _tables.size() + "]";
     }
 }

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/AxionPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/AxionPlatform.java?rev=232530&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/AxionPlatform.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/AxionPlatform.java Sat Aug 13 14:36:44 2005
@@ -0,0 +1,78 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 1999-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.sql.Types;
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.builder.AxionBuilder;
+
+/**
+ * The platform for the Axion database.
+ * 
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision: 231306 $
+ */
+public class AxionPlatform extends PlatformImplBase
+{
+    /** Database name of this platform */
+    public static final String DATABASENAME     = "Axion";
+    /** The axion jdbc driver */
+    public static final String JDBC_DRIVER      = "org.axiondb.jdbc.AxionDriver";
+    /** The subprotocol used by the axion driver */
+    public static final String JDBC_SUBPROTOCOL = "axiondb";
+
+    /**
+     * Creates a new axion platform instance.
+     */
+    public AxionPlatform()
+    {
+        PlatformInfo info = new PlatformInfo();
+
+        info.setRequiringNullAsDefaultValue(false);
+        info.setPrimaryKeyEmbedded(true);
+        info.setForeignKeysEmbedded(false);
+        info.setIndicesEmbedded(true);
+        info.addNativeTypeMapping(Types.ARRAY,         "BLOB");
+        info.addNativeTypeMapping(Types.BINARY,        "VARBINARY");
+        info.addNativeTypeMapping(Types.BIT,           "BOOLEAN");
+        info.addNativeTypeMapping(Types.DECIMAL,       "NUMBER");
+        info.addNativeTypeMapping(Types.DISTINCT,      "VARBINARY");
+        info.addNativeTypeMapping(Types.DOUBLE,        "FLOAT");
+        info.addNativeTypeMapping(Types.LONGVARBINARY, "VARBINARY");
+        info.addNativeTypeMapping(Types.LONGVARCHAR,   "VARCHAR");
+        info.addNativeTypeMapping(Types.NULL,          "VARBINARY");
+        info.addNativeTypeMapping(Types.NUMERIC,       "NUMBER");
+        info.addNativeTypeMapping(Types.OTHER,         "BLOB");
+        info.addNativeTypeMapping(Types.REAL,          "FLOAT");
+        info.addNativeTypeMapping(Types.REF,           "VARBINARY");
+        info.addNativeTypeMapping(Types.SMALLINT,      "SHORT");
+        info.addNativeTypeMapping(Types.STRUCT,        "VARBINARY");
+        info.addNativeTypeMapping(Types.TINYINT,       "SHORT");
+        info.addNativeTypeMapping("DATALINK", "VARBINARY");
+
+        setSqlBuilder(new AxionBuilder(info));
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.Platform#getDatabaseName()
+     */
+    public String getDatabaseName()
+    {
+        return DATABASENAME;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/CloudscapePlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/CloudscapePlatform.java?rev=232530&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/CloudscapePlatform.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/CloudscapePlatform.java Sat Aug 13 14:36:44 2005
@@ -0,0 +1,76 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 1999-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.sql.Types;
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.builder.CloudscapeBuilder;
+
+/**
+ * The Cloudscape platform implementation.
+ * 
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision: 231306 $
+ */
+public class CloudscapePlatform extends PlatformImplBase
+{
+    /** Database name of this platform */
+    public static final String DATABASENAME = "Cloudscape";
+
+    /**
+     * Creates a new platform instance.
+     */
+    public CloudscapePlatform()
+    {
+        PlatformInfo info = new PlatformInfo();
+
+        info.setRequiringNullAsDefaultValue(false);
+        info.setPrimaryKeyEmbedded(true);
+        info.setForeignKeysEmbedded(false);
+        info.setIndicesEmbedded(false);
+        info.setMaxIdentifierLength(128);
+        // BINARY and VARBINARY will also be handled by CloudscapeBuilder.getSqlType
+        info.addNativeTypeMapping(Types.ARRAY,         "BLOB");
+        info.addNativeTypeMapping(Types.BINARY,        "CHAR");
+        info.addNativeTypeMapping(Types.BIT,           "CHAR FOR BIT DATA");
+        info.addNativeTypeMapping(Types.DISTINCT,      "BLOB");
+        info.addNativeTypeMapping(Types.DOUBLE,        "DOUBLE PRECISION");
+        info.addNativeTypeMapping(Types.FLOAT,         "DOUBLE PRECISION");
+        info.addNativeTypeMapping(Types.JAVA_OBJECT,   "BLOB");
+        info.addNativeTypeMapping(Types.LONGVARBINARY, "LONG VARCHAR FOR BIT DATA");
+        info.addNativeTypeMapping(Types.LONGVARCHAR,   "LONG VARCHAR");
+        info.addNativeTypeMapping(Types.OTHER,         "BLOB");
+        info.addNativeTypeMapping(Types.NULL,          "LONG VARCHAR FOR BIT DATA");
+        info.addNativeTypeMapping(Types.REF,           "LONG VARCHAR FOR BIT DATA");
+        info.addNativeTypeMapping(Types.STRUCT,        "BLOB");
+        info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT");
+        info.addNativeTypeMapping(Types.VARBINARY,     "VARCHAR");
+        info.addNativeTypeMapping("BOOLEAN",  "CHAR FOR BIT DATA");
+        info.addNativeTypeMapping("DATALINK", "LONG VARCHAR FOR BIT DATA");
+
+        setSqlBuilder(new CloudscapeBuilder(info));
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.Platform#getDatabaseName()
+     */
+    public String getDatabaseName()
+    {
+        return DATABASENAME;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/Db2Platform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/Db2Platform.java?rev=232530&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/Db2Platform.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/Db2Platform.java Sat Aug 13 14:36:44 2005
@@ -0,0 +1,75 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 1999-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.sql.Types;
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.builder.Db2Builder;
+
+/**
+ * The DB2 platform implementation.
+ * 
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision: 231306 $
+ */
+public class Db2Platform extends PlatformImplBase
+{
+    /** Database name of this platform */
+    public static final String DATABASENAME     = "DB2";
+    /** The standard DB2 jdbc driver */
+    public static final String JDBC_DRIVER      = "COM.ibm.db2.jdbc.app.DB2Driver";
+    /** The subprotocol used by the standard DB2 driver */
+    public static final String JDBC_SUBPROTOCOL = "db2";
+
+    /**
+     * Creates a new platform instance.
+     */
+    public Db2Platform()
+    {
+        PlatformInfo info = new PlatformInfo();
+
+        info.setMaxIdentifierLength(18);
+        info.setRequiringNullAsDefaultValue(false);
+        info.setPrimaryKeyEmbedded(true);
+        info.setForeignKeysEmbedded(false);
+        info.setIndicesEmbedded(false);
+        // the BINARY types are also handled by Db2Builder.getSqlType(Column)
+        info.addNativeTypeMapping(Types.ARRAY,         "BLOB");
+        info.addNativeTypeMapping(Types.BINARY,        "CHAR");
+        info.addNativeTypeMapping(Types.BIT,           "CHAR FOR BIT DATA");
+        info.addNativeTypeMapping(Types.JAVA_OBJECT,   "BLOB");
+        info.addNativeTypeMapping(Types.LONGVARBINARY, "LONG VARCHAR FOR BIT DATA");
+        info.addNativeTypeMapping(Types.LONGVARCHAR,   "LONG VARCHAR");
+        info.addNativeTypeMapping(Types.NULL,          "LONG VARCHAR FOR BIT DATA");
+        info.addNativeTypeMapping(Types.OTHER,         "BLOB");
+        info.addNativeTypeMapping(Types.STRUCT,        "BLOB");
+        info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT");
+        info.addNativeTypeMapping(Types.VARBINARY,     "VARCHAR");
+        info.addNativeTypeMapping("BOOLEAN", "CHAR FOR BIT DATA");
+
+        setSqlBuilder(new Db2Builder(info));
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.Platform#getDatabaseName()
+     */
+    public String getDatabaseName()
+    {
+        return DATABASENAME;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/DerbyPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/DerbyPlatform.java?rev=232530&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/DerbyPlatform.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/DerbyPlatform.java Sat Aug 13 14:36:44 2005
@@ -0,0 +1,43 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 1999-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.
+ */
+
+/**
+ * The platform implementation for Derby.
+ * 
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision: 231306 $
+ */
+public class DerbyPlatform extends CloudscapePlatform
+{
+    /** Database name of this platform */
+    public static final String DATABASENAME         = "Derby";
+    /** The derby jdbc driver for use as a client for a normal server */
+    public static final String JDBC_DRIVER          = "org.apache.derby.jdbc.ClientDriver";
+    /** The derby jdbc driver for use as an embedded database */
+    public static final String JDBC_DRIVER_EMBEDDED = "org.apache.derby.jdbc.EmbeddedDriver";
+    /** The subprotocol used by the derby drivers */
+    public static final String JDBC_SUBPROTOCOL     = "derby";
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.Platform#getDatabaseName()
+     */
+    public String getDatabaseName()
+    {
+        return DATABASENAME;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/FirebirdPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/FirebirdPlatform.java?rev=232530&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/FirebirdPlatform.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/FirebirdPlatform.java Sat Aug 13 14:36:44 2005
@@ -0,0 +1,41 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 1999-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.
+ */
+
+/**
+ * The platform implementation for the Firebird database.
+ * 
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision: 231306 $
+ */
+public class FirebirdPlatform extends InterbasePlatform
+{
+    /** Database name of this platform */
+    public static final String DATABASENAME     = "Firebird";
+    /** The standard Firebird jdbc driver */
+    public static final String JDBC_DRIVER      = "org.firebirdsql.jdbc.FBDriver";
+    /** The subprotocol used by the standard Firebird driver */
+    public static final String JDBC_SUBPROTOCOL = "firebirdsql";
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.Platform#getDatabaseName()
+     */
+    public String getDatabaseName()
+    {
+        return DATABASENAME;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbPlatform.java?rev=232530&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbPlatform.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/HsqlDbPlatform.java Sat Aug 13 14:36:44 2005
@@ -0,0 +1,73 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 1999-2002,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.sql.Types;
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.builder.HsqlDbBuilder;
+
+/**
+ * The platform implementation for the HsqlDb database.
+ * 
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision: 231306 $
+ */
+public class HsqlDbPlatform extends PlatformImplBase
+{
+    /** Database name of this platform */
+    public static final String DATABASENAME     = "HsqlDb";
+    /** The standard Hsqldb jdbc driver */
+    public static final String JDBC_DRIVER      = "org.hsqldb.jdbcDriver";
+    /** The subprotocol used by the standard Hsqldb driver */
+    public static final String JDBC_SUBPROTOCOL = "hsqldb";
+
+    /**
+     * Creates a new instance of the Hsqldb platform.
+     */
+    public HsqlDbPlatform()
+    {
+        PlatformInfo info = new PlatformInfo();
+
+        info.setRequiringNullAsDefaultValue(false);
+        info.setPrimaryKeyEmbedded(true);
+        info.setForeignKeysEmbedded(false);
+        info.setIndicesEmbedded(false);
+        info.addNativeTypeMapping(Types.ARRAY,       "LONGVARBINARY");
+        info.addNativeTypeMapping(Types.BLOB,        "LONGVARBINARY");
+        info.addNativeTypeMapping(Types.CLOB,        "LONGVARCHAR");
+        info.addNativeTypeMapping(Types.DISTINCT,    "LONGVARBINARY");
+        info.addNativeTypeMapping(Types.FLOAT,       "DOUBLE");
+        info.addNativeTypeMapping(Types.JAVA_OBJECT, "OBJECT");
+        info.addNativeTypeMapping(Types.NULL,        "LONGVARBINARY");
+        info.addNativeTypeMapping(Types.OTHER,       "OTHER");
+        info.addNativeTypeMapping(Types.REF,         "LONGVARBINARY");
+        info.addNativeTypeMapping(Types.STRUCT,      "LONGVARBINARY");
+        info.addNativeTypeMapping("BOOLEAN",  "BIT");
+        info.addNativeTypeMapping("DATALINK", "LONGVARBINARY");
+
+        setSqlBuilder(new HsqlDbBuilder(info));
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.Platform#getDatabaseName()
+     */
+    public String getDatabaseName()
+    {
+        return DATABASENAME;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/InterbasePlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/InterbasePlatform.java?rev=232530&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/InterbasePlatform.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/InterbasePlatform.java Sat Aug 13 14:36:44 2005
@@ -0,0 +1,86 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 1999-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.sql.Types;
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.builder.InterbaseBuilder;
+
+/**
+ * The platform implementation for the Interbase database.
+ * 
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision: 231306 $
+ */
+public class InterbasePlatform extends PlatformImplBase
+{
+    /** Database name of this platform */
+    public static final String DATABASENAME     = "Interbase";
+    /** The interbase jdbc driver */
+    public static final String JDBC_DRIVER      = "interbase.interclient.Driver";
+    /** The subprotocol used by the interbase driver */
+    public static final String JDBC_SUBPROTOCOL = "interbase";
+
+    /**
+     * Creates a new platform instance.
+     */
+    public InterbasePlatform()
+    {
+        PlatformInfo info = new PlatformInfo();
+
+        info.setMaxIdentifierLength(31);
+        info.setRequiringNullAsDefaultValue(false);
+        info.setPrimaryKeyEmbedded(true);
+        info.setForeignKeysEmbedded(false);
+        info.setIndicesEmbedded(false);
+        info.setCommentPrefix("/*");
+        info.setCommentSuffix("*/");
+
+        // BINARY and VARBINARY are also handled by the InterbaseBuilder.getSqlType method
+        info.addNativeTypeMapping(Types.ARRAY,         "BLOB");
+        info.addNativeTypeMapping(Types.BIGINT,        "DECIMAL(38,0)");
+        info.addNativeTypeMapping(Types.BINARY,        "CHAR");
+        info.addNativeTypeMapping(Types.BIT,           "DECIMAL(1,0)");
+        info.addNativeTypeMapping(Types.CLOB,          "BLOB SUB_TYPE TEXT");
+        info.addNativeTypeMapping(Types.DISTINCT,      "BLOB");
+        info.addNativeTypeMapping(Types.DOUBLE,        "DOUBLE PRECISION");
+        info.addNativeTypeMapping(Types.FLOAT,         "DOUBLE PRECISION");
+        info.addNativeTypeMapping(Types.JAVA_OBJECT,   "BLOB");
+        info.addNativeTypeMapping(Types.LONGVARBINARY, "BLOB");
+        info.addNativeTypeMapping(Types.LONGVARCHAR,   "BLOB SUB_TYPE TEXT");
+        info.addNativeTypeMapping(Types.NULL,          "BLOB");
+        info.addNativeTypeMapping(Types.OTHER,         "BLOB");
+        info.addNativeTypeMapping(Types.REAL,          "FLOAT");
+        info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT");
+        info.addNativeTypeMapping(Types.REF,           "BLOB");
+        info.addNativeTypeMapping(Types.STRUCT,        "BLOB");
+        info.addNativeTypeMapping(Types.VARBINARY,     "VARCHAR");
+        info.addNativeTypeMapping("BOOLEAN",  "DECIMAL(1,0)");
+        info.addNativeTypeMapping("DATALINK", "BLOB");
+
+        setSqlBuilder(new InterbaseBuilder(info));
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.Platform#getDatabaseName()
+     */
+    public String getDatabaseName()
+    {
+        return DATABASENAME;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MSSqlPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MSSqlPlatform.java?rev=232530&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MSSqlPlatform.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MSSqlPlatform.java Sat Aug 13 14:36:44 2005
@@ -0,0 +1,84 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 1999-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.sql.Types;
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.builder.MSSqlBuilder;
+
+/**
+ * The platform implementation for the Microsoft SQL Server database.
+ * 
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision: 231306 $
+ */
+public class MSSqlPlatform extends PlatformImplBase
+{
+    /** Database name of this platform */
+    public static final String DATABASENAME     = "MsSql";
+    /** The standard SQLServer jdbc driver */
+    public static final String JDBC_DRIVER      = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
+    /** The subprotocol used by the standard SQLServer driver */
+    public static final String JDBC_SUBPROTOCOL = "microsoft:sqlserver";
+
+    /**
+     * Creates a new platform instance.
+     */
+    public MSSqlPlatform()
+    {
+        PlatformInfo info = new PlatformInfo();
+
+        info.setMaxIdentifierLength(128);
+        info.setRequiringNullAsDefaultValue(false);
+        info.setPrimaryKeyEmbedded(true);
+        info.setForeignKeysEmbedded(false);
+        info.setIndicesEmbedded(false);
+        //info.setCommentPrefix("#");
+
+        info.addNativeTypeMapping(Types.ARRAY,         "IMAGE");
+        info.addNativeTypeMapping(Types.BIGINT,        "DECIMAL(19,0)");
+        info.addNativeTypeMapping(Types.BLOB,          "IMAGE");
+        info.addNativeTypeMapping(Types.CLOB,          "TEXT");
+        info.addNativeTypeMapping(Types.DATE,          "DATETIME");
+        info.addNativeTypeMapping(Types.DISTINCT,      "IMAGE");
+        info.addNativeTypeMapping(Types.DOUBLE,        "FLOAT");
+        info.addNativeTypeMapping(Types.INTEGER,       "INT");
+        info.addNativeTypeMapping(Types.JAVA_OBJECT,   "IMAGE");
+        info.addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE");
+        info.addNativeTypeMapping(Types.LONGVARCHAR,   "TEXT");
+        info.addNativeTypeMapping(Types.NULL,          "IMAGE");
+        info.addNativeTypeMapping(Types.OTHER,         "IMAGE");
+        info.addNativeTypeMapping(Types.REF,           "IMAGE");
+        info.addNativeTypeMapping(Types.STRUCT,        "IMAGE");
+        info.addNativeTypeMapping(Types.TIME,          "DATETIME");
+        info.addNativeTypeMapping(Types.TIMESTAMP,     "DATETIME");
+        info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT");
+        info.addNativeTypeMapping("BOOLEAN",  "BIT");
+        info.addNativeTypeMapping("DATALINK", "IMAGE");
+
+        setSqlBuilder(new MSSqlBuilder(info));
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.Platform#getDatabaseName()
+     */
+    public String getDatabaseName()
+    {
+        return DATABASENAME;
+    }
+}



Mime
View raw message