db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r279651 - in /db/ddlutils/trunk: ToDo.txt src/java/org/apache/ddlutils/io/JdbcModelReader.java
Date Thu, 08 Sep 2005 21:52:59 GMT
Author: tomdz
Date: Thu Sep  8 14:52:53 2005
New Revision: 279651

URL: http://svn.apache.org/viewcvs?rev=279651&view=rev
Log:
Fix for DDLUTILS-12: database metadata is now only read once per usage of JdbcModelReader#getDatabase
Reduced public interface of JdbcModelReader, only the relevant methods are public anymore

Modified:
    db/ddlutils/trunk/ToDo.txt
    db/ddlutils/trunk/src/java/org/apache/ddlutils/io/JdbcModelReader.java

Modified: db/ddlutils/trunk/ToDo.txt
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/ToDo.txt?rev=279651&r1=279650&r2=279651&view=diff
==============================================================================
--- db/ddlutils/trunk/ToDo.txt (original)
+++ db/ddlutils/trunk/ToDo.txt Thu Sep  8 14:52:53 2005
@@ -4,23 +4,19 @@
 * Enhance doc:
     - The Ant task
     - How to use DdlUtils in code
-* Update commons-betwixt replace .betwixt files with a multi-mapping
-* Remove DDL subpackage and jelly-dependency which is not used anymore anyway
 * Separate generation of alter statements for an existing databases from the reading
   of the model from the existing database to allow for alter statement generation with two
   database models without having to connect to the database and thus allow for testing the
   alter statement generation without an actual live database
 * Add unit tests for:
-    - Model reading
     - SQL generation (including alteration)
     - Roundtrip (database specific)
+* Replace usage of java.util.regex with some alternative that is Java 1.3 (1.2 ?) compatible
 * Add support for chosing the character set (ASCII, UNICODE) if the database supports it
   (perhaps a more generic configuration mechanism for overriding defaults)
 * Add the ability to configure the datatype mapping (ant task, API)
 * Replace System.out/System.err writes with logging statements
 * Extract interfaces from the model classes and inroduce a factory for creating the concrete
model objects
-* Make associations in the model (foreignkey, indices) stonger-typed by referencing the columns
instead
-  of using only their names
 * Add functionality and ant tasks to dump data from the database
 * Add integration with DbUnit to allow DbUnit to use the schema and data files
 * Add proper handling of names (table, column, ...) that contain whitespaces and similar
(-> escaping)

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/io/JdbcModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/JdbcModelReader.java?rev=279651&r1=279650&r2=279651&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/io/JdbcModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/io/JdbcModelReader.java Thu Sep  8 14:52:53
2005
@@ -17,6 +17,7 @@
  */
 
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
@@ -66,7 +67,7 @@
     private String schema = "%";
     /** The table types to recognize */
     private String[] tableTypes = { "TABLE" };
-    /** The patern to recognize when parsing a default value */
+    /** The pattern to recognize when parsing a default value */
     private Pattern defaultPattern = Pattern.compile("\\(\\'?(.*?)\\'?\\)");
 
     /**
@@ -144,13 +145,15 @@
      * 
      * @return The list of tables
      */
-    public List getTables() throws SQLException
+    private List getTables() throws SQLException
     {
         ResultSet tableData = null;
 
         try
         {
-            tableData = connection.getMetaData().getTables(catalog, schema, "%", tableTypes);
+            DatabaseMetaData metaData = connection.getMetaData();
+
+            tableData = metaData.getTables(catalog, schema, "%", tableTypes);
             
             Set  availableColumns = determineAvailableColumns(tableData);
             List tables           = new ArrayList();
@@ -176,15 +179,15 @@
             {
                 Table table = (Table)it.next();
 
-                for (Iterator columnIt = getColumnsForTable(table.getName()).iterator();
columnIt.hasNext();)
+                for (Iterator columnIt = getColumnsForTable(metaData, table.getName()).iterator();
columnIt.hasNext();)
                 {
                     table.addColumn((Column)columnIt.next());
                 }
-                for (Iterator fkIt = getForeignKeysForTable(table.getName()).iterator();
fkIt.hasNext();)
+                for (Iterator fkIt = getForeignKeysForTable(metaData, table.getName()).iterator();
fkIt.hasNext();)
                 {
                     table.addForeignKey((ForeignKey)fkIt.next());
                 }
-                for (Iterator idxIt = getIndicesForTable(table.getName()).iterator(); idxIt.hasNext();)
+                for (Iterator idxIt = getIndicesForTable(metaData, table.getName()).iterator();
idxIt.hasNext();)
                 {
                     table.addIndex((Index)idxIt.next());
                 }
@@ -203,20 +206,21 @@
     /**
      * Returns a list of {@link Column} instances for the indicated table.
      * 
+     * @param metaData  The database meta data
      * @param tableName The name of the table
      * @return The list of columns
      */
-    private List getColumnsForTable(String tableName) throws SQLException
+    private List getColumnsForTable(DatabaseMetaData metaData, String tableName) throws SQLException
     {
         ResultSet columnData = null;
 
         try
         {
-            columnData = connection.getMetaData().getColumns(catalog, schema, tableName,
null);
+            columnData = metaData.getColumns(catalog, schema, tableName, null);
 
             Set  availableColumns = determineAvailableColumns(columnData);
             List columns          = new ArrayList();
-            List primaryKeys      = getPrimaryKeysForTable(tableName);
+            List primaryKeys      = getPrimaryKeysForTable(metaData, tableName);
 
             while (columnData.next())
             {
@@ -269,17 +273,18 @@
      * Retrieves a list of the columns composing the primary key for a given
      * table.
      *
+     * @param metaData  The database meta data
      * @param tableName The name of the table from which to retrieve PK information
      * @return The list of the primary key column names
      */
-    public List getPrimaryKeysForTable(String tableName) throws SQLException
+    private List getPrimaryKeysForTable(DatabaseMetaData metaData, String tableName) throws
SQLException
     {
         List      pks   = new ArrayList();
         ResultSet pkData = null;
 
         try
         {
-            pkData = connection.getMetaData().getPrimaryKeys(catalog, schema, tableName);
+            pkData = metaData.getPrimaryKeys(catalog, schema, tableName);
             while (pkData.next())
             {
                 pks.add(pkData.getString("COLUMN_NAME"));
@@ -302,17 +307,18 @@
     /**
      * Retrieves a list of the foreign keys of the indicated table.
      *
+     * @param metaData  The database meta data
      * @param tableName The name of the table from which to retrieve FK information
      * @return The list of foreign keys
      */
-    public List getForeignKeysForTable(String tableName) throws SQLException
+    private List getForeignKeysForTable(DatabaseMetaData metaData, String tableName) throws
SQLException
     {
         List      fks    = new ArrayList();
         ResultSet fkData = null;
 
         try
         {
-            fkData = connection.getMetaData().getImportedKeys(catalog, schema, tableName);
+            fkData = metaData.getImportedKeys(catalog, schema, tableName);
 
             Set        availableColumns = determineAvailableColumns(fkData);
             String     prevPkTable      = null;
@@ -363,17 +369,18 @@
     /**
      * Determines the indices for the indicated table.
      * 
+     * @param metaData  The database meta data
      * @param tableName The name of the table
      * @return The list of indices
      */
-    private List getIndicesForTable(String tableName) throws SQLException
+    private List getIndicesForTable(DatabaseMetaData metaData, String tableName) throws SQLException
     {
         ResultSet indexData = null;
         List      indices   = new ArrayList();
 
         try 
         {
-            indexData = connection.getMetaData().getIndexInfo(catalog, schema, tableName,
false, false);
+            indexData = metaData.getIndexInfo(catalog, schema, tableName, false, false);
 
             Set availableColumns = determineAvailableColumns(indexData);
             Map indicesByName    = new LinkedMap();



Mime
View raw message