db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r359646 - /db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DumpMetadataTask.java
Date Wed, 28 Dec 2005 21:54:09 GMT
Author: tomdz
Date: Wed Dec 28 13:54:04 2005
New Revision: 359646

URL: http://svn.apache.org/viewcvs?rev=359646&view=rev
Log:
Added ability to specify the patterns (catalog, schema, tables, procedures, columns)

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DumpMetadataTask.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DumpMetadataTask.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DumpMetadataTask.java?rev=359646&r1=359645&r2=359646&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DumpMetadataTask.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DumpMetadataTask.java Wed Dec 28 13:54:04
2005
@@ -55,6 +55,16 @@
     private BasicDataSource _dataSource;
     /** The file to write the dump to. */
     private File _outputFile = null;
+    /** The database catalog(s) to read. */
+    private String _catalogPattern = "%";
+    /** The database schema(s) to read. */
+    private String _schemaPattern = "%";
+    /** The pattern for reading all tables. */
+    private String _tablePattern = "%";
+    /** The pattern for reading all procedures. */
+    private String _procedurePattern = "%";
+    /** The pattern for reading all columns. */
+    private String _columnPattern = "%";
 
     /**
      * Adds the data source to use for accessing the database.
@@ -77,6 +87,56 @@
     }
 
     /**
+     * Sets the catalog pattern.
+     *
+     * @param catalogPattern The catalog pattern
+     */
+    public void setCatalogPattern(String catalogPattern)
+    {
+        _catalogPattern = ((catalogPattern == null) || (catalogPattern.length() == 0) ? null
: catalogPattern);
+    }
+
+    /**
+     * Sets the schema pattern.
+     *
+     * @param schemaPattern The schema pattern
+     */
+    public void setSchemaPattern(String schemaPattern)
+    {
+        _schemaPattern = ((schemaPattern == null) || (schemaPattern.length() == 0) ? null
: schemaPattern);
+    }
+
+    /**
+     * Sets the table pattern.
+     *
+     * @param tablePattern The table pattern
+     */
+    public void setTablePattern(String tablePattern)
+    {
+        _tablePattern = ((tablePattern == null) || (tablePattern.length() == 0) ? null :
tablePattern);
+    }
+
+    /**
+     * Sets the procedure pattern.
+     *
+     * @param procedurePattern The procedure pattern
+     */
+    public void setProcedurePattern(String procedurePattern)
+    {
+        _procedurePattern = ((procedurePattern == null) || (procedurePattern.length() ==
0) ? null : procedurePattern);
+    }
+
+    /**
+     * Sets the column pattern.
+     *
+     * @param columnPattern The column pattern
+     */
+    public void setColumnPattern(String columnPattern)
+    {
+        _columnPattern = ((columnPattern == null) || (columnPattern.length() == 0) ? null
: columnPattern);
+    }
+
+    /**
      * {@inheritDoc}
      */
     public void execute() throws BuildException
@@ -370,7 +430,7 @@
      */
     private void dumpTables(Element parent, DatabaseMetaData metaData, String[] tableTypes)
throws SQLException
     {
-        ResultSet result     = metaData.getTables("%", "%", "%", tableTypes);
+        ResultSet result     = metaData.getTables(_catalogPattern, _schemaPattern, _tablePattern,
tableTypes);
         Element   tablesElem = parent.addElement("tables");
         Set       columns    = getColumnsInResultSet(result);
 
@@ -396,11 +456,11 @@
             addStringAttribute(result, columns, "SELF_REFERENCING_COL_NAME", tableElem, "identifierColumn");
             addStringAttribute(result, columns, "REF_GENERATION", tableElem, "identifierGeneration");
 
-            dumpColumns(tableElem, metaData, "%", "%", tableName);
-            dumpPKs(tableElem, metaData, "%", "%", tableName);
-            dumpVersionColumns(tableElem, metaData, "%", "%", tableName);
-            dumpFKs(tableElem, metaData, "%", "%", tableName);
-            dumpIndices(tableElem, metaData, "%", "%", tableName);
+            dumpColumns(tableElem, metaData, _catalogPattern, _schemaPattern, tableName);
+            dumpPKs(tableElem, metaData, _catalogPattern, _schemaPattern, tableName);
+            dumpVersionColumns(tableElem, metaData, _catalogPattern, _schemaPattern, tableName);
+            dumpFKs(tableElem, metaData, _catalogPattern, _schemaPattern, tableName);
+            dumpIndices(tableElem, metaData, _catalogPattern, _schemaPattern, tableName);
         }
     }
 
@@ -414,7 +474,7 @@
      */
     private void dumpColumns(Element tableElem, DatabaseMetaData metaData, String catalogName,
String schemaName, String tableName) throws SQLException
     {
-        ResultSet result  = metaData.getColumns(catalogName, schemaName, tableName, "%");
+        ResultSet result  = metaData.getColumns(catalogName, schemaName, tableName, _columnPattern);
         Set       columns = getColumnsInResultSet(result);
 
         while (result.next())
@@ -718,7 +778,7 @@
      */
     private void dumpProcedures(Element parent, DatabaseMetaData metaData) throws SQLException
     {
-        ResultSet result         = metaData.getProcedures("%", "%", "%");
+        ResultSet result         = metaData.getProcedures(_catalogPattern, _schemaPattern,
_procedurePattern);
         Element   proceduresElem = parent.addElement("procedures");
         Set       columns        = getColumnsInResultSet(result);
 
@@ -770,7 +830,7 @@
      */
     private void dumpProcedure(Element procedureElem, DatabaseMetaData metaData, String catalogName,
String schemaName, String procedureName) throws SQLException
     {
-        ResultSet result  = metaData.getProcedureColumns(catalogName, schemaName, procedureName,
"%");
+        ResultSet result  = metaData.getProcedureColumns(catalogName, schemaName, procedureName,
_columnPattern);
         Set       columns = getColumnsInResultSet(result);
 
         while (result.next())



Mime
View raw message