You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by to...@apache.org on 2006/02/04 15:25:10 UTC

svn commit: r374870 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils: Platform.java platform/PlatformImplBase.java

Author: tomdz
Date: Sat Feb  4 06:24:43 2006
New Revision: 374870

URL: http://svn.apache.org/viewcvs?rev=374870&view=rev
Log:
Added alterTables and getAlterTablesSql variants that allow the specification of the catalog, schema, and table types to read from the existing database (fixes DDLUTILS-65)

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java?rev=374870&r1=374869&r2=374870&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java Sat Feb  4 06:24:43 2006
@@ -307,6 +307,78 @@
     /**
      * Alters the database schema so that it match the given model.
      *
+     * @param catalog         The catalog in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param schema          The schema in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param tableTypes      The table types to read from the existing database;
+     *                        use <code>null</code> or an empty array for the platform-specific default value
+     * @param desiredDb       The desired database schema
+     * @param doDrops         Whether columns, tables and indexes should be dropped if not in the
+     *                        new schema
+     * @param modifyColumns   Whether columns should be altered for datatype, size as required
+     * @param continueOnError Whether to continue with the next sql statement when an error occurred
+     */
+    public void alterTables(String catalog, String schema, String[] tableTypes, Database desiredDb, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException;
+
+    /**
+     * Returns the SQL for altering the database schema so that it match the given model.
+     *
+     * @param catalog         The catalog in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param schema          The schema in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param tableTypes      The table types to read from the existing database;
+     *                        use <code>null</code> or an empty array for the platform-specific default value
+     * @param desiredDb       The desired database schema
+     * @param doDrops         Whether columns, tables and indexes should be dropped if not in the
+     *                        new schema
+     * @param modifyColumns   Whether columns should be altered for datatype, size as required
+     * @param continueOnError Whether to continue with the next sql statement when an error occurred
+     * @return The SQL statements
+     */
+    public String getAlterTablesSql(String catalog, String schema, String[] tableTypes, Database desiredDb, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException;
+
+    /**
+     * Alters the database schema so that it match the given model.
+     *
+     * @param catalog         The catalog in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param schema          The schema in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param tableTypes      The table types to read from the existing database;
+     *                        use <code>null</code> or an empty array for the platform-specific default value
+     * @param desiredDb       The desired database schema
+     * @param params          The parameters used in the creation
+     * @param doDrops         Whether columns, tables and indexes should be dropped if not in the
+     *                        new schema
+     * @param modifyColumns   Whether columns should be altered for datatype, size as required
+     * @param continueOnError Whether to continue with the next sql statement when an error occurred
+     */
+    public void alterTables(String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException;
+
+    /**
+     * Returns the SQL for altering the database schema so that it match the given model.
+     *
+     * @param catalog         The catalog in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param schema          The schema in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param tableTypes      The table types to read from the existing database;
+     *                        use <code>null</code> or an empty array for the platform-specific default value
+     * @param desiredDb       The desired database schema
+     * @param params          The parameters used in the creation
+     * @param doDrops         Whether columns, tables and indexes should be dropped if not in the
+     *                        new schema
+     * @param modifyColumns   Whether columns should be altered for datatype, size as required
+     * @param continueOnError Whether to continue with the next sql statement when an error occurred
+     * @return The SQL statements
+     */
+    public String getAlterTablesSql(String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException;
+
+    /**
+     * Alters the database schema so that it match the given model.
+     *
      * @param connection      A connection to the existing database that shall be modified
      * @param desiredDb       The desired database schema
      * @param doDrops         Whether columns, tables and indexes should be dropped if not in the
@@ -355,6 +427,82 @@
      * @return The SQL statements
      */
     public String getAlterTablesSql(Connection connection, Database desiredDb, CreationParameters params, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException;
+
+    /**
+     * Alters the database schema so that it match the given model.
+     *
+     * @param connection      A connection to the existing database that shall be modified
+     * @param catalog         The catalog in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param schema          The schema in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param tableTypes      The table types to read from the existing database;
+     *                        use <code>null</code> or an empty array for the platform-specific default value
+     * @param desiredDb       The desired database schema
+     * @param doDrops         Whether columns, tables and indexes should be dropped if not in the
+     *                        new schema
+     * @param modifyColumns   Whether columns should be altered for datatype, size as required
+     * @param continueOnError Whether to continue with the next sql statement when an error occurred
+     */
+    public void alterTables(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredDb, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException;
+
+    /**
+     * Returns the SQL for altering the database schema so that it match the given model.
+     *
+     * @param connection      A connection to the existing database that shall be modified
+     * @param catalog         The catalog in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param schema          The schema in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param tableTypes      The table types to read from the existing database;
+     *                        use <code>null</code> or an empty array for the platform-specific default value
+     * @param desiredDb       The desired database schema
+     * @param doDrops         Whether columns, tables and indexes should be dropped if not in the
+     *                        new schema
+     * @param modifyColumns   Whether columns should be altered for datatype, size as required
+     * @param continueOnError Whether to continue with the next sql statement when an error occurred
+     * @return The SQL statements
+     */
+    public String getAlterTablesSql(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredDb, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException;
+
+    /**
+     * Alters the database schema so that it match the given model.
+     *
+     * @param connection      A connection to the existing database that shall be modified
+     * @param catalog         The catalog in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param schema          The schema in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param tableTypes      The table types to read from the existing database;
+     *                        use <code>null</code> or an empty array for the platform-specific default value
+     * @param desiredDb       The desired database schema
+     * @param params          The parameters used in the creation
+     * @param doDrops         Whether columns, tables and indexes should be dropped if not in the
+     *                        new schema
+     * @param modifyColumns   Whether columns should be altered for datatype, size as required
+     * @param continueOnError Whether to continue with the next sql statement when an error occurred
+     */
+    public void alterTables(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException;
+
+    /**
+     * Returns the SQL for altering the database schema so that it match the given model.
+     *
+     * @param connection      A connection to the existing database that shall be modified
+     * @param catalog         The catalog in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param schema          The schema in the existing database to read (can be a pattern);
+     *                        use <code>null</code> for the platform-specific default value
+     * @param tableTypes      The table types to read from the existing database;
+     *                        use <code>null</code> or an empty array for the platform-specific default value
+     * @param desiredDb       The desired database schema
+     * @param params          The parameters used in the creation
+     * @param doDrops         Whether columns, tables and indexes should be dropped if not in the
+     *                        new schema
+     * @param modifyColumns   Whether columns should be altered for datatype, size as required
+     * @param continueOnError Whether to continue with the next sql statement when an error occurred
+     * @return The SQL statements
+     */
+    public String getAlterTablesSql(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException;
 
     /**
      * Drops the tables defined in the given database.

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java?rev=374870&r1=374869&r2=374870&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java Sat Feb  4 06:24:43 2006
@@ -516,7 +516,141 @@
         return sql;
     }
 
-    /**
+	/**
+     * {@inheritDoc}
+     */
+	public void alterTables(String catalog, String schema, String[] tableTypes, Database desiredModel, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException
+	{
+        Connection connection = borrowConnection();
+
+        try
+        {
+            alterTables(connection, catalog, schema, tableTypes, desiredModel, doDrops, modifyColumns, continueOnError);
+        }
+        finally
+        {
+            returnConnection(connection);
+        }
+	}
+
+	/**
+     * {@inheritDoc}
+     */
+	public String getAlterTablesSql(String catalog, String schema, String[] tableTypes, Database desiredModel, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException
+	{
+        Connection connection = borrowConnection();
+
+        try
+        {
+            return getAlterTablesSql(connection, catalog, schema, tableTypes, desiredModel, doDrops, modifyColumns, continueOnError);
+        }
+        finally
+        {
+            returnConnection(connection);
+        }
+	}
+
+	/**
+     * {@inheritDoc}
+     */
+	public void alterTables(String catalog, String schema, String[] tableTypes, Database desiredModel, CreationParameters params, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException
+	{
+        Connection connection = borrowConnection();
+
+        try
+        {
+            alterTables(connection, catalog, schema, tableTypes, desiredModel, params, doDrops, modifyColumns, continueOnError);
+        }
+        finally
+        {
+            returnConnection(connection);
+        }
+	}
+
+	/**
+     * {@inheritDoc}
+     */
+    public String getAlterTablesSql(String catalog, String schema, String[] tableTypes, Database desiredModel, CreationParameters params, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException
+    {
+        Connection connection = borrowConnection();
+
+        try
+        {
+            return getAlterTablesSql(connection, catalog, schema, tableTypes, desiredModel, params, doDrops, modifyColumns, continueOnError);
+        }
+        finally
+        {
+            returnConnection(connection);
+        }
+	}
+
+	/**
+     * {@inheritDoc}
+     */
+	public void alterTables(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredModel, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException
+    {
+        String sql = getAlterTablesSql(connection, catalog, schema, tableTypes, desiredModel, doDrops, modifyColumns, continueOnError);
+
+        evaluateBatch(connection, sql, continueOnError);
+	}
+
+	/**
+     * {@inheritDoc}
+     */
+	public String getAlterTablesSql(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredModel, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException
+	{
+        String   sql          = null;
+        Database currentModel = readModelFromDatabase(connection, desiredModel.getName(), catalog, schema, tableTypes);
+
+        try
+        {
+            StringWriter buffer = new StringWriter();
+
+            getSqlBuilder().setWriter(buffer);
+            getSqlBuilder().alterDatabase(currentModel, desiredModel, doDrops, modifyColumns);
+            sql = buffer.toString();
+        }
+        catch (IOException ex)
+        {
+            // won't happen because we're using a string writer
+        }
+        return sql;
+	}
+
+	/**
+     * {@inheritDoc}
+     */
+	public void alterTables(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredModel, CreationParameters params, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException
+	{
+        String sql = getAlterTablesSql(connection, catalog, schema, tableTypes, desiredModel, params, doDrops, modifyColumns, continueOnError);
+
+        evaluateBatch(connection, sql, continueOnError);
+	}
+
+	/**
+     * {@inheritDoc}
+     */
+	public String getAlterTablesSql(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredModel, CreationParameters params, boolean doDrops, boolean modifyColumns, boolean continueOnError) throws DynaSqlException
+	{
+        String   sql          = null;
+        Database currentModel = readModelFromDatabase(connection, desiredModel.getName(), catalog, schema, tableTypes);
+
+        try
+        {
+            StringWriter buffer = new StringWriter();
+
+            getSqlBuilder().setWriter(buffer);
+            getSqlBuilder().alterDatabase(currentModel, desiredModel, params, doDrops, modifyColumns);
+            sql = buffer.toString();
+        }
+        catch (IOException ex)
+        {
+            // won't happen because we're using a string writer
+        }
+        return sql;
+	}
+
+	/**
      * {@inheritDoc}
      */
     public void dropTables(Database model, boolean continueOnError) throws DynaSqlException