db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From florianbruck...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb DBCatalog.java DBColumn.java DBMeta.java DBSchema.java DBTable.java
Date Tue, 28 Jan 2003 19:59:14 GMT
florianbruckner    2003/01/28 11:59:14

  Modified:    src/java/org/apache/ojb/tools/mapping/reversedb
                        DBCatalog.java DBColumn.java DBMeta.java
                        DBSchema.java DBTable.java
  Log:
  some updates to schema reading to make it a bit more compatible
  
  Revision  Changes    Path
  1.3       +85 -118   jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBCatalog.java
  
  Index: DBCatalog.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBCatalog.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DBCatalog.java	17 Jun 2002 19:34:33 -0000	1.2
  +++ DBCatalog.java	28 Jan 2003 19:59:14 -0000	1.3
  @@ -57,67 +57,9 @@
   import java.util.Iterator;
   import javax.swing.tree.TreeNode;
   
  -/*
  - * ====================================================================
  - * 
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowlegement may appear in the software itself,
  - *    if and wherever such third-party acknowlegements normally appear.
  - *
  - * 4. The names "The Jakarta Project", "Jakarta-Regexp", and "Apache Software
  - *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  - *    permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache"
  - *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache Group.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - *
  - */ 
  -
  -
   /**
    *
  - * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a> 
  + * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
    * @version $Id$
    */
   public class DBCatalog implements MetadataNodeInterface, TreeNode, org.apache.ojb.tools.mapping.reversedb.gui.PropertySheetModel
  @@ -130,14 +72,14 @@
     private String strCatalogName;
     private java.util.TreeMap hmSchemas = new java.util.TreeMap();
     /** Creates a new instance of DBCatalog */
  -  public DBCatalog (java.sql.DatabaseMetaData pdbMeta, DBMeta paMeta,
  -                    String pstrCatalogName)
  +  public DBCatalog(java.sql.DatabaseMetaData pdbMeta, DBMeta paMeta,
  +  String pstrCatalogName)
     {
       this.dbMeta = pdbMeta;
       this.parsedMetaData = paMeta;
       this.strCatalogName = pstrCatalogName;
     }
  -
  +  
     public boolean isEnabled()
     {
       return this.enabled;
  @@ -174,27 +116,45 @@
     }
     
     public void generateReferences()
  -    throws java.sql.SQLException
  +  throws java.sql.SQLException
     {
  +    // Set the catalog name of the connection before accessing the metadata object
  +    dbMeta.getConnection().setCatalog(this.getCatalogName());
       Iterator it = this.hmSchemas.values().iterator();
       while (it.hasNext())
       {
         ((DBSchema)it.next()).generateReferences();
  -    }    
  -  }  
  -
  +    }
  +  }
  +  
     public void read()
  -    throws java.sql.SQLException
  +  throws java.sql.SQLException
     {
  -    Iterator it = this.hmSchemas.values().iterator();
  -    while (it.hasNext())
  +    // Set the catalog name of the connection before accessing the metadata object
  +    java.sql.ResultSet rs = dbMeta.getSchemas();
  +    int count = 0;
  +    while (rs.next())
  +    {
  +      count++;
  +      String strSchemaName = rs.getString("TABLE_SCHEM");
  +      // Fix for IBM Informix JDBC 2.21JC2; Schema is padded with spaces, needs to be trimmed
  +      strSchemaName = strSchemaName.trim();
  +      this.hmSchemas.put(strSchemaName, new DBSchema(dbMeta, this, strSchemaName));
  +    }
  +    // Fix for MySQL: Create an empty schema
  +    if (count == 0)
       {
  -      ((DBSchema)it.next()).read();
  -    }    
  -  }  
  -
  +      this.hmSchemas.put("", new DBSchema(dbMeta, this, ""));
  +    }
  +    
  +    rs.close();
  +    Iterator it = hmSchemas.values().iterator();
  +    while (it.hasNext()) ((DBSchema)it.next()).read();
  +    
  +  }
  +  
     public void addTable(String strSchemaName, String strTableName, String strTableType)
  -    throws java.sql.SQLException
  +  throws java.sql.SQLException
     {
       DBSchema aDBSchema= this.getSchema(strSchemaName);
       if (aDBSchema == null)
  @@ -205,20 +165,20 @@
       }
       aDBSchema.addTable(strTableName, strTableType);
     }
  -
  +  
     public void addColumn(String strSchemaName, String strTableName, String strColumnName,
  -            int iDataType, String strTypeName, int iColumnSize, int iNullable)
  +  int iDataType, String strTypeName, int iColumnSize, int iNullable)
     {
       DBSchema aDBSchema = this.getSchema(strSchemaName);
       if (aDBSchema != null)
       {
         aDBSchema.addColumn(strTableName, strColumnName,
  -                          iDataType, strTypeName, iColumnSize, iNullable);
  +      iDataType, strTypeName, iColumnSize, iNullable);
       }
     }
     
  -  public void addPrimaryKeyColumn(String strSchemaName, String strTableName, 
  -                                  String strColumnName)
  +  public void addPrimaryKeyColumn(String strSchemaName, String strTableName,
  +  String strColumnName)
     {
       DBSchema aDBSchema = this.getSchema(strSchemaName);
       if (aDBSchema != null)
  @@ -228,12 +188,12 @@
     }
     
     
  -  public java.util.Enumeration children ()
  +  public java.util.Enumeration children()
     {
       return java.util.Collections.enumeration(this.hmSchemas.values());
     }
     
  -  public boolean getAllowsChildren ()
  +  public boolean getAllowsChildren()
     {
       return true;
     }
  @@ -244,7 +204,7 @@
       return tn;
     }
     
  -  public int getChildCount ()
  +  public int getChildCount()
     {
       return this.hmSchemas.size();
     }
  @@ -260,7 +220,7 @@
       return this.parsedMetaData;
     }
     
  -  public boolean isLeaf ()
  +  public boolean isLeaf()
     {
       return false;
     }
  @@ -272,7 +232,7 @@
       else return this.strCatalogName;
     }
     
  -  public Class getPropertySheetClass ()
  +  public Class getPropertySheetClass()
     {
       return org.apache.ojb.tools.mapping.reversedb.gui.DBCatalogPropertySheet.class;
     }
  @@ -288,59 +248,62 @@
       return strReturn;
     }
     
  -  public void generateJava (java.io.File aFile, String strHeader, String strFooter) throws java.io.IOException, java.io.FileNotFoundException
  +  public void generateJava(java.io.File aFile, String strHeader, String strFooter) throws java.io.IOException, java.io.FileNotFoundException
     {
       Iterator i = this.hmSchemas.values().iterator();
  -    while (i.hasNext()) ((DBSchema)i.next()).generateJava(aFile, strHeader, strFooter);    
  +    while (i.hasNext()) ((DBSchema)i.next()).generateJava(aFile, strHeader, strFooter);
     }
     
  -  public void setPackage (String packageName)
  +  public void setPackage(String packageName)
     {
       Iterator i = this.hmSchemas.values().iterator();
  -    while (i.hasNext()) ((DBSchema)i.next()).setPackage(packageName);        
  +    while (i.hasNext()) ((DBSchema)i.next()).setPackage(packageName);
     }
  -
  +  
     public void disableClassesWithRegex(org.apache.regexp.RE aRegexp)
     {
       Iterator it = this.hmSchemas.values().iterator();
  -    while (it.hasNext()) ((DBSchema)it.next()).disableClassesWithRegex(aRegexp);        
  +    while (it.hasNext()) ((DBSchema)it.next()).disableClassesWithRegex(aRegexp);
     }
     
   }
   
   
   /***************************** Changelog *****************************
  -// $Log$
  -// Revision 1.2  2002/06/17 19:34:33  jvanzyl
  -// Correcting all the package references.
  -// PR:
  -// Obtained from:
  -// Submitted by:
  -// Reviewed by:
  -//
  -// Revision 1.1.1.1  2002/06/17 18:16:51  jvanzyl
  -// Initial OJB import
  -//
  -// Revision 1.3  2002/05/16 11:47:09  florianbruckner
  -// fix CR/LF issue, change license to ASL
  -//
  -// Revision 1.2  2002/05/16 10:43:59  florianbruckner
  -// use jakarta-regexp instead of gnu-regexp due to the move to jakarta.
  -//
  -// Revision 1.1  2002/04/18 11:44:16  mpoeschl
  -//
  -// move files to new location
  -//
  -// Revision 1.3  2002/04/07 09:05:16  thma
  -// *** empty log message ***
  -//
  -// Revision 1.2  2002/03/11 17:36:04  florianbruckner
  -// fix line break issue for these files that were previously checked in with -kb
  -//
  -// Revision 1.1  2002/03/04 17:19:32  thma
  -// initial checking for Florians Reverse engineering tool
  -//
  -// Revision 1.1.1.1  2002/02/20 13:35:25  Administrator
  -// initial import
  -//
  -/***************************** Changelog *****************************/
  + * // $Log$
  + * // Revision 1.3  2003/01/28 19:59:14  florianbruckner
  + * // some updates to schema reading to make it a bit more compatible
  + * //
  + * // Revision 1.2  2002/06/17 19:34:33  jvanzyl
  + * // Correcting all the package references.
  + * // PR:
  + * // Obtained from:
  + * // Submitted by:
  + * // Reviewed by:
  + * //
  + * // Revision 1.1.1.1  2002/06/17 18:16:51  jvanzyl
  + * // Initial OJB import
  + * //
  + * // Revision 1.3  2002/05/16 11:47:09  florianbruckner
  + * // fix CR/LF issue, change license to ASL
  + * //
  + * // Revision 1.2  2002/05/16 10:43:59  florianbruckner
  + * // use jakarta-regexp instead of gnu-regexp due to the move to jakarta.
  + * //
  + * // Revision 1.1  2002/04/18 11:44:16  mpoeschl
  + * //
  + * // move files to new location
  + * //
  + * // Revision 1.3  2002/04/07 09:05:16  thma
  + * // *** empty log message ***
  + * //
  + * // Revision 1.2  2002/03/11 17:36:04  florianbruckner
  + * // fix line break issue for these files that were previously checked in with -kb
  + * //
  + * // Revision 1.1  2002/03/04 17:19:32  thma
  + * // initial checking for Florians Reverse engineering tool
  + * //
  + * // Revision 1.1.1.1  2002/02/20 13:35:25  Administrator
  + * // initial import
  + * //
  + * /***************************** Changelog *****************************/
  
  
  
  1.3       +8 -58     jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBColumn.java
  
  Index: DBColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBColumn.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DBColumn.java	17 Jun 2002 19:34:33 -0000	1.2
  +++ DBColumn.java	28 Jan 2003 19:59:14 -0000	1.3
  @@ -54,63 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -/*
  - * ====================================================================
  - * 
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowlegement may appear in the software itself,
  - *    if and wherever such third-party acknowlegements normally appear.
  - *
  - * 4. The names "The Jakarta Project", "Jakarta-Regexp", and "Apache Software
  - *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  - *    permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache"
  - *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache Group.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - *
  - */ 
  -
   /**
    *
    * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a> 
  @@ -370,6 +313,9 @@
   
   /***************************** Changelog *****************************
   // $Log$
  +// Revision 1.3  2003/01/28 19:59:14  florianbruckner
  +// some updates to schema reading to make it a bit more compatible
  +//
   // Revision 1.2  2002/06/17 19:34:33  jvanzyl
   // Correcting all the package references.
   // PR:
  
  
  
  1.3       +38 -126   jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBMeta.java
  
  Index: DBMeta.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBMeta.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DBMeta.java	17 Jun 2002 19:34:33 -0000	1.2
  +++ DBMeta.java	28 Jan 2003 19:59:14 -0000	1.3
  @@ -57,64 +57,6 @@
   import java.util.Iterator;
   import javax.swing.tree.TreeNode;
   
  -/*
  - * ====================================================================
  - * 
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowlegement may appear in the software itself,
  - *    if and wherever such third-party acknowlegements normally appear.
  - *
  - * 4. The names "The Jakarta Project", "Jakarta-Regexp", and "Apache Software
  - *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  - *    permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache"
  - *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache Group.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - *
  - */ 
  -
  -
   /**
    *
    * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a> 
  @@ -125,7 +67,9 @@
     private boolean enabled = true;
     
     private java.sql.DatabaseMetaData dbMeta;
  -  private java.util.TreeMap hmCatalogs = new java.util.TreeMap();
  +  
  +  // private java.util.TreeMap hmCatalogs = new java.util.TreeMap();
  +  private java.util.HashMap hmCatalogs = new java.util.HashMap();
     private String catalogTerm;
     private String catalogSeparator;
     private boolean isCatalogAtStart;
  @@ -136,15 +80,26 @@
     private boolean supportsCatalogsInTableDefinitions;
     private String schemaTerm;
     
  +  private String catalogPattern;
  +  private String schemaPattern;
  +  
     private String databaseProductName = null;
     private String databaseProductVersion = null;
     
     
     /** Creates a new instance of DBSchema */
  -  public DBMeta (java.sql.DatabaseMetaData pdbMeta) throws java.sql.SQLException
  +  public DBMeta (String pCatalogPattern, String pSchemaPattern, java.sql.DatabaseMetaData pDbMeta) throws java.sql.SQLException
     {
       super();
  -    dbMeta = pdbMeta;
  +    this.dbMeta = pDbMeta;
  +    this.catalogPattern = pCatalogPattern;
  +    this.schemaPattern  = pSchemaPattern;
  +    System.err.println("Using " + dbMeta.getDriverName() + " "  + dbMeta.getDriverVersion());
  +  }
  +  
  +  public DBMeta (java.sql.DatabaseMetaData pDbMeta) throws java.sql.SQLException
  +  {
  +      this(null, null, pDbMeta);
     }
     
     public boolean isEnabled()
  @@ -232,67 +187,25 @@
       supportsCatalogsInTableDefinitions = dbMeta.supportsCatalogsInTableDefinitions();
       schemaTerm = dbMeta.getSchemaTerm();
       
  -    
  -    java.sql.ResultSet rs = dbMeta.getTables("%", "%", "%", null);
  -    while (rs.next())
  +    java.sql.ResultSet rs = dbMeta.getCatalogs();
  +    int count = 0;
  +    while(rs.next())
       {
  -      String strCatalogName = rs.getString("TABLE_CAT");
  -      if (strCatalogName == null) strCatalogName = "";
  -      String strSchemaName = rs.getString("TABLE_SCHEM");
  -      if (strSchemaName == null) strSchemaName = "";
  -      String strTableName = rs.getString("TABLE_NAME");
  -      String strTableType = rs.getString("TABLE_TYPE");
  -      
  -      DBCatalog aDBCatalog = (DBCatalog)this.hmCatalogs.get(strCatalogName);
  -      if (aDBCatalog == null)
  -      {
  -        aDBCatalog = new DBCatalog(dbMeta, this, strCatalogName);
  +        count++;
  +        String strCatalogName = rs.getString("TABLE_CAT");
  +        DBCatalog aDBCatalog = new DBCatalog(dbMeta, this, strCatalogName);
           this.hmCatalogs.put(strCatalogName, aDBCatalog);
  -      }
  -      aDBCatalog.addTable(strSchemaName, strTableName, strTableType);      
       }
       rs.close();
  -    
  -    rs = dbMeta.getColumns("%", "%", "%", "%");
  -    while (rs.next())
  -    {
  -      String strCatalogName = rs.getString("TABLE_CAT");
  -      if (strCatalogName == null) strCatalogName = "";
  -      String strSchemaName = rs.getString("TABLE_SCHEM");
  -      if (strSchemaName == null) strSchemaName = "";
  -      String strTableName = rs.getString("TABLE_NAME");
  -      String strColumnName = rs.getString("COLUMN_NAME");
  -      int iDataType = rs.getInt("DATA_TYPE");
  -      String strTypeName = rs.getString("TYPE_NAME");
  -      int iColumnSize = rs.getInt("COLUMN_SIZE");
  -      int iNullable = rs.getInt("NULLABLE");
  -      
  -      DBCatalog aDBCatalog = (DBCatalog)this.hmCatalogs.get(strCatalogName);
  -      if (aDBCatalog != null)
  -      {
  -        aDBCatalog.addColumn(strSchemaName, strTableName, strColumnName,
  -                             iDataType, strTypeName, iColumnSize, iNullable);
  -      }
  -    }     
  -    rs.close();
  -    
  -    rs = this.dbMeta.getPrimaryKeys(null, null, null);
  -    while (rs.next())
  +    if (count==0)
       {
  -      String strCatalogName = rs.getString("TABLE_CAT");
  -      if (strCatalogName == null) strCatalogName = "";
  -      String strSchemaName = rs.getString("TABLE_SCHEM");
  -      if (strSchemaName == null) strSchemaName = "";
  -      String strTableName = rs.getString("TABLE_NAME");
  -      String strColumnName = rs.getString("COLUMN_NAME");
  -
  -      DBCatalog aDBCatalog = (DBCatalog)this.hmCatalogs.get(strCatalogName);
  -      if (aDBCatalog != null)
  -      {
  -        aDBCatalog.addPrimaryKeyColumn(strSchemaName, strTableName, strColumnName);
  -      }      
  +        DBCatalog aDBCatalog = new DBCatalog(dbMeta, this, null);
  +        this.hmCatalogs.put(null, aDBCatalog); 
       }
  -    rs.close();
  +    
  +    // Read after closing recordset.
  +    Iterator it = hmCatalogs.values().iterator();
  +    while (it.hasNext()) ((DBCatalog)it.next()).read();
     }
     
     public void generateReferences()
  @@ -303,19 +216,11 @@
       {
         ((DBCatalog)it.next()).generateReferences();
       }    
  -    
  -    
  -    
     }
     
     public void debug()
     {
  -/*    
  -    java.util.Iterator i = this.hmCatalogs.values().iterator();
  -    while (i.hasNext()) System.out.println(i.next());
  -    i = this.hmCatalogs.keySet().iterator();
  -    while (i.hasNext()) System.out.println(i.next());
  - */
  +
     }
     
     public java.util.Enumeration children ()
  @@ -409,6 +314,9 @@
   
   /***************************** Changelog *****************************
   // $Log$
  +// Revision 1.3  2003/01/28 19:59:14  florianbruckner
  +// some updates to schema reading to make it a bit more compatible
  +//
   // Revision 1.2  2002/06/17 19:34:33  jvanzyl
   // Correcting all the package references.
   // PR:
  
  
  
  1.3       +37 -59    jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java
  
  Index: DBSchema.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DBSchema.java	17 Jun 2002 19:34:33 -0000	1.2
  +++ DBSchema.java	28 Jan 2003 19:59:14 -0000	1.3
  @@ -57,64 +57,6 @@
   import java.util.Iterator;
   import javax.swing.tree.TreeNode;
   
  -/*
  - * ====================================================================
  - * 
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowlegement may appear in the software itself,
  - *    if and wherever such third-party acknowlegements normally appear.
  - *
  - * 4. The names "The Jakarta Project", "Jakarta-Regexp", and "Apache Software
  - *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  - *    permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache"
  - *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache Group.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - *
  - */ 
  -
  -
   /**
    *
    * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a> 
  @@ -172,6 +114,35 @@
     public void read()
       throws java.sql.SQLException
     {
  +    java.sql.ResultSet rs = dbMeta.getTables(this.getDBCatalog().getCatalogName(), this.getSchemaName(), "%", null);
  +    while (rs.next())
  +    {
  +      String strTableCat = rs.getString("TABLE_CAT");
  +      String strSchemaName = rs.getString("TABLE_SCHEM");
  +      String strTableName = rs.getString("TABLE_NAME");
  +      String strTableType = rs.getString("TABLE_TYPE");
  +      if (
  +             (strTableCat == null && this.getDBCatalog().getCatalogName() == null || strTableCat.equals(this.getDBCatalog().getCatalogName()))
  +           &&(strSchemaName == null && this.getSchemaName() == null || strSchemaName.equals(this.getSchemaName()))
  +         )
  +        this.addTable(strTableName, strTableType);
  +    }
  +    rs.close();
  +    
  +    rs = dbMeta.getColumns(this.getDBCatalog().getCatalogName(), this.getSchemaName(), "%", "%");
  +    while (rs.next())
  +    {
  +      String strSchemaName = rs.getString("TABLE_SCHEM");
  +      String strTableName = rs.getString("TABLE_NAME");
  +      String strColumnName = rs.getString("COLUMN_NAME");
  +      int iDataType = rs.getInt("DATA_TYPE");
  +      String strTypeName = rs.getString("TYPE_NAME");
  +      int iColumnSize = rs.getInt("COLUMN_SIZE");
  +      int iNullable = rs.getInt("NULLABLE");
  +      this.addColumn(strTableName, strColumnName,
  +      iDataType, strTypeName, iColumnSize, iNullable);
  +    }
  +    rs.close();    
     }
     
     public void addTable(String strTableName, String strTableType)
  @@ -300,6 +271,9 @@
   
   /***************************** Changelog *****************************
   // $Log$
  +// Revision 1.3  2003/01/28 19:59:14  florianbruckner
  +// some updates to schema reading to make it a bit more compatible
  +//
   // Revision 1.2  2002/06/17 19:34:33  jvanzyl
   // Correcting all the package references.
   // PR:
  
  
  
  1.3       +156 -215  jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBTable.java
  
  Index: DBTable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBTable.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DBTable.java	17 Jun 2002 19:34:33 -0000	1.2
  +++ DBTable.java	28 Jan 2003 19:59:14 -0000	1.3
  @@ -58,64 +58,6 @@
   import java.sql.SQLException;
   import java.io.File;
   
  -/*
  - * ====================================================================
  - * 
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowlegement may appear in the software itself,
  - *    if and wherever such third-party acknowlegements normally appear.
  - *
  - * 4. The names "The Jakarta Project", "Jakarta-Regexp", and "Apache Software
  - *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  - *    permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache"
  - *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache Group.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - *
  - */ 
  -
  -
   /**
    *
    * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a> 
  @@ -149,6 +91,7 @@
       id = IdGeneratorSingleton.getId(this.getClass().getName(), this.getClass().getName());
       aSchema = paSchema;
       dbMeta = pdbMeta;
  +    System.err.println(System.currentTimeMillis() + ": >> New Table " + this.getDBSchema().getDBCatalog().getCatalogName() + ":" + this.getDBSchema().getSchemaName() + ":" + this.getTableName());    
     }
     
     public boolean hasDynamicProxy()
  @@ -263,32 +206,7 @@
     
     public void read() throws SQLException
     {
  -/*    
  -    // Query for all Schemas because the Informix JDBC driver is too stupid
  -    // to return columns if the schema name is set.....
  -    java.sql.ResultSet rs = dbMeta.getColumns("%", "%", strTableName, "%");
  -    while (rs.next())
  -    {
  -      String strCatalogName = rs.getString("TABLE_CAT");
  -      if (strCatalogName == null) strCatalogName = "";
  -      String strSchemaName = rs.getString("TABLE_SCHEM");
  -      if (strSchemaName == null) strSchemaName = "";
  -      if (strSchemaName.equals(aSchema.getSchemaName()) && 
  -          strCatalogName.equals(aSchema.getDBCatalog().getCatalogName()))
  -      {
  -        int iColumnType      = rs.getInt("DATA_TYPE");
  -        String strColumnTypeName = rs.getString("TYPE_NAME");
  -        String strColumnName = rs.getString("COLUMN_NAME");
  -        DBColumn col = new DBColumn(dbMeta, this, strColumnName, iColumnType, 
  -          strColumnTypeName);
  -        tmColumns.put (strColumnName, col);
  -//        System.out.println("      " + strColumnName + " " 
  -//          + Utilities.getTypeNameFromJDBCType(iColumnType) + " " + strColumnTypeName);
  -        col.read();        
  -      }
  -    }
  -    rs.close();
  - */
  +
     }
     
     public void addColumn(String strColumnName,
  @@ -309,7 +227,6 @@
     
     public void generateReferences() throws SQLException
     {
  -
       // Check if primary keys for this table have already been set. If not, do it now...
       // This is necessary because Oracle doesn't return the Primary Keys for all tables
       // and for Informix it speeds up things significantly if we do it onve for all tables.
  @@ -326,30 +243,6 @@
       vSubTreeNodes.addAll(this.hmReferences.values());
     }    
     
  -/*  private void readPrimaryKeys()
  -  {
  -    rs = this.dbMeta.getPrimaryKeys(null, null, this.getTableName());
  -    while (rs.next())
  -    {
  -      String strCatalogName = rs.getString("TABLE_CAT");
  -      if (strCatalogName == null) strCatalogName = "";
  -      String strSchemaName = rs.getString("TABLE_SCHEM");
  -      if (strSchemaName == null) strSchemaName = "";
  -      String strTableName = rs.getString("TABLE_NAME");
  -      String strColumnName = rs.getString("COLUMN_NAME");
  -
  -      
  -      if (strCatalogName.equals(this.getDBSchema().getDBCatalog().getCatalogName()) 
  -          && strSchemaName.equals(this.getDBSchema().getSchemaName())
  -          && strTableName.equals(this.getTableName()))
  -      {
  -        this.addPrimaryKeyColumn(strColumnName);
  -      }
  -    }
  -    rs.close();    
  -  }
  - */
  -  
     public java.util.Enumeration children ()
     {
       return vSubTreeNodes.elements();
  @@ -396,148 +289,189 @@
     
     private void readPrimaryKeys() throws SQLException
     {
  -    // Now get the primary keys for this table
  -    java.sql.ResultSet rs = dbMeta.getPrimaryKeys("%", "%", this.strTableName);
  -    while (rs.next())
  -    {
  -      String strCatalogName = rs.getString("TABLE_CAT");
  -      if (strCatalogName == null) strCatalogName = "";
  -      String strSchemaName = rs.getString("TABLE_SCHEM");
  -      if (strSchemaName == null) strSchemaName = "";
  -      if (strSchemaName.equals(this.aSchema.getSchemaName()) &&
  -          strCatalogName.equals(this.aSchema.getDBCatalog().getCatalogName()))
  -      {
  -        String strColumnName = rs.getString("COLUMN_NAME");
  -        String pkName = rs.getString("PK_NAME");
  -//        System.out.println("      PK:" + strColumnName + " " + pkName);
  -        DBColumn dbcol = (DBColumn)tmColumns.get(strColumnName);
  -        if (dbcol != null) dbcol.setPrimaryKeyPart(true);
  +    // Now get the primary keys for this table. Ignore any exceptions thrown here as
  +    // primary keys are not absolutely necessary for reverse engineering
  +    java.sql.ResultSet rs = null;
  +    try
  +    {
  +      rs = dbMeta.getPrimaryKeys(null, 
  +                                  this.getDBSchema().getSchemaName(), this.strTableName);
  +      while (rs.next())
  +      {
  +        String strCatalogName = rs.getString("TABLE_CAT");
  +        String strSchemaName = rs.getString("TABLE_SCHEM");
  +        if ( (strSchemaName == null && this.aSchema.getSchemaName() == null || strSchemaName.equals(this.aSchema.getSchemaName())) 
  +             &&
  +             (strCatalogName == null && this.aSchema.getDBCatalog().getCatalogName() == null 
  +              || strCatalogName.equals(this.aSchema.getDBCatalog().getCatalogName())))
  +        {
  +          String strColumnName = rs.getString("COLUMN_NAME");
  +          String pkName = rs.getString("PK_NAME");
  +          DBColumn dbcol = (DBColumn)tmColumns.get(strColumnName);
  +          if (dbcol != null) dbcol.setPrimaryKeyPart(true);
  +        }
         }
       }
  -    rs.close();    
  +    catch (SQLException sqlEx)
  +    {
  +      // Ignore excpetions here.
  +    }
  +    finally
  +    {
  +      try
  +      {
  +        rs.close();    
  +      }
  +      catch (Throwable t)
  +      {} // Ignore this exception
  +    }
     }
   
     private void generateFKReferences() throws SQLException
     {
       // References, points from this class to another class using attributes
       // of this class
  -    java.sql.ResultSet rs = dbMeta.getImportedKeys(null, null, strTableName);
  -    while (rs.next())
  +    // Ignore any exceptions thrown here.
  +    java.sql.ResultSet rs = null;
  +    try
       {
  -      String strFKSchemaName = rs.getString("FKTABLE_SCHEM");
  -      if (strFKSchemaName == null) strFKSchemaName = "";
  -      String strFKCatalogName = rs.getString("FKTABLE_CAT");
  -      if (strFKCatalogName == null) strFKCatalogName = "";
  -      
  -      if (   strFKCatalogName.equals(this.aSchema.getDBCatalog().getCatalogName())
  -          && strFKSchemaName.equals(this.aSchema.getSchemaName()))
  +      rs = dbMeta.getImportedKeys(this.getDBSchema().getDBCatalog().getCatalogName(), 
  +                                                     this.getDBSchema().getSchemaName(), strTableName);
  +      while (rs.next())
         {
  -        String strPKCatalogName = rs.getString("PKTABLE_CAT");
  -        if (strPKCatalogName == null) strPKCatalogName = "";
  -        String strPKSchemaName = rs.getString("PKTABLE_SCHEM");
  -        if (strPKSchemaName == null) strPKSchemaName = "";
  -        String strPKTableName  = rs.getString("PKTABLE_NAME");
  -        String strPKColumnName = rs.getString("PKCOLUMN_NAME");
  -        String strFKTableName  = rs.getString("FKTABLE_NAME");
  -        String strFKColumnName = rs.getString("FKCOLUMN_NAME");
  -        
  -        // Resolove the primaryKey column
  -        DBCatalog dbPKCatalog = this.aSchema.getDBCatalog().getDBMeta().getCatalog(strPKCatalogName);
  -        if (dbPKCatalog != null)
  +        String strFKSchemaName = rs.getString("FKTABLE_SCHEM");
  +        String strFKCatalogName = rs.getString("FKTABLE_CAT");
  +
  +        if (   (strFKCatalogName == null && this.aSchema.getDBCatalog().getCatalogName() == null || strFKCatalogName.equals(this.aSchema.getDBCatalog().getCatalogName()))
  +            && (strFKSchemaName  == null && this.aSchema.getSchemaName() == null || strFKSchemaName.equals(this.aSchema.getSchemaName())))
           {
  -          DBSchema dbPKSchem = (DBSchema)dbPKCatalog.getSchema(strPKSchemaName);
  -          if (dbPKSchem != null)
  +          String strPKCatalogName = rs.getString("PKTABLE_CAT");
  +          String strPKSchemaName = rs.getString("PKTABLE_SCHEM");
  +          String strPKTableName  = rs.getString("PKTABLE_NAME");
  +          String strPKColumnName = rs.getString("PKCOLUMN_NAME");
  +          String strFKTableName  = rs.getString("FKTABLE_NAME");
  +          String strFKColumnName = rs.getString("FKCOLUMN_NAME");
  +
  +          // Resolove the primaryKey column
  +          DBCatalog dbPKCatalog = this.aSchema.getDBCatalog().getDBMeta().getCatalog(strPKCatalogName);
  +          if (dbPKCatalog != null)
             {
  -            DBTable dbPKTable = dbPKSchem.getTable(strPKTableName);
  -            if (dbPKTable != null)
  +            DBSchema dbPKSchem = (DBSchema)dbPKCatalog.getSchema(strPKSchemaName);
  +            if (dbPKSchem != null)
               {
  -              DBColumn dbPKColumn = dbPKTable.getColumn(strPKColumnName);
  -              // The FK column is always from this table.
  -              DBColumn dbFKColumn = getColumn(strFKColumnName);
  -
  -              // Now retrieve the FKReference to this table from the collection
  -              DBFKRelation aFKRef = 
  -                (DBFKRelation)this.hmReferences.get(dbPKSchem.getSchemaName() 
  -                  + "." + dbPKTable.getTableName());
  -              if (aFKRef == null)
  +              DBTable dbPKTable = dbPKSchem.getTable(strPKTableName);
  +              if (dbPKTable != null)
                 {
  -                aFKRef = new DBFKRelation(dbPKTable, this, false);
  -                this.hmReferences.put(dbPKSchem.getSchemaName() 
  -                  + "." + dbPKTable.getTableName(), aFKRef);
  +                DBColumn dbPKColumn = dbPKTable.getColumn(strPKColumnName);
  +                // The FK column is always from this table.
  +                DBColumn dbFKColumn = getColumn(strFKColumnName);
  +
  +                // Now retrieve the FKReference to this table from the collection
  +                DBFKRelation aFKRef = 
  +                  (DBFKRelation)this.hmReferences.get(dbPKSchem.getSchemaName() 
  +                    + "." + dbPKTable.getTableName());
  +                if (aFKRef == null)
  +                {
  +                  aFKRef = new DBFKRelation(dbPKTable, this, false);
  +                  this.hmReferences.put(dbPKSchem.getSchemaName() 
  +                    + "." + dbPKTable.getTableName(), aFKRef);
  +                }
  +                aFKRef.addColumnPair(dbPKColumn, dbFKColumn);
                 }
  -              aFKRef.addColumnPair(dbPKColumn, dbFKColumn);
               }
             }
           }
         }
       }
  -    rs.close();    
  +    catch (SQLException sqlEx)
  +    {
  +      // sqlEx.printStackTrace();
  +    }
  +    try
  +    {
  +      rs.close();    
  +    }
  +    catch (Throwable t) {}
     }
     
     private void generateFKCollections() throws SQLException
     {
       // Collections, points from this class to a collection of objects using
       // attributes from the referenced class
  -    java.sql.ResultSet rs = dbMeta.getCrossReference(null, null, strTableName, null, null, null);
  -    while (rs.next())
  +    // Ignore any exceptions thrown here
  +    java.sql.ResultSet rs = null;
  +    try
       {
  -      String strPKSchemaName = rs.getString("PKTABLE_SCHEM");
  -      if (strPKSchemaName == null) strPKSchemaName = "";
  -      String strPKCatalogName = rs.getString("PKTABLE_CAT");
  -      if (strPKCatalogName == null) strPKCatalogName = "";
  -      
  -      if ( strPKSchemaName.equals(this.aSchema.getSchemaName())
  -         &&strPKCatalogName.equals(this.aSchema.getDBCatalog().getCatalogName()))
  -      {
  -        String strPKTableName  = rs.getString("PKTABLE_NAME");
  -        String strPKColumnName = rs.getString("PKCOLUMN_NAME");
  -        String strFKCatalogName= rs.getString("FKTABLE_CAT");
  -        if (strFKCatalogName == null) strFKCatalogName = "";
  -        String strFKTableName  = rs.getString("FKTABLE_NAME");
  -        String strFKColumnName = rs.getString("FKCOLUMN_NAME");
  -        String strFKSchemaName = rs.getString("FKTABLE_SCHEM");        
  -        if (strFKSchemaName == null) strFKSchemaName = "";
  -        // Resolve the FK column. If catalog is supported in the index
  -        // definition, resolve the catalog of the FK column, otherwise
  -        // assume the current catalog (Note: This is needed for Informix,
  -        // because the driver reports null for the catalog in this case.
  -        DBCatalog dbFKCatalog = null;
  -        if (this.aSchema.getDBCatalog().getDBMeta().getSupportsCatalogsInIndexDefinitions())
  -        {
  -          dbFKCatalog = this.aSchema.getDBCatalog().getDBMeta().getCatalog(strFKCatalogName);
  -        }
  -        else
  -        {
  -          dbFKCatalog = this.aSchema.getDBCatalog();
  -        }
  -        if (dbFKCatalog != null)
  +      rs = dbMeta.getExportedKeys(this.getDBSchema().getDBCatalog().getCatalogName(), 
  +                                                       this.getDBSchema().getSchemaName(), strTableName);
  +      while (rs.next())
  +      {
  +        String strPKSchemaName = rs.getString("PKTABLE_SCHEM");
  +        String strPKCatalogName = rs.getString("PKTABLE_CAT");
  +
  +        if (    (strPKSchemaName == null && this.aSchema.getSchemaName()==null || strPKSchemaName.equals(this.aSchema.getSchemaName()))
  +             && (strPKCatalogName == null && this.aSchema.getDBCatalog().getCatalogName() == null 
  +                 || strPKCatalogName.equals(this.aSchema.getDBCatalog().getCatalogName())))
           {
  -          DBSchema dbFKSchema = dbFKCatalog.getSchema(strFKSchemaName);
  -          if (dbFKSchema != null)
  +          String strPKTableName  = rs.getString("PKTABLE_NAME");
  +          String strPKColumnName = rs.getString("PKCOLUMN_NAME");
  +          String strFKCatalogName= rs.getString("FKTABLE_CAT");
  +          String strFKTableName  = rs.getString("FKTABLE_NAME");
  +          String strFKColumnName = rs.getString("FKCOLUMN_NAME");
  +          String strFKSchemaName = rs.getString("FKTABLE_SCHEM");        
  +
  +          // Resolve the FK column. If catalog is supported in the index
  +          // definition, resolve the catalog of the FK column, otherwise
  +          // assume the current catalog (Note: This is needed for Informix,
  +          // because the driver reports null for the catalog in this case.
  +          DBCatalog dbFKCatalog = null;
  +          if (this.aSchema.getDBCatalog().getDBMeta().getSupportsCatalogsInIndexDefinitions())
  +          {
  +            dbFKCatalog = this.aSchema.getDBCatalog().getDBMeta().getCatalog(strFKCatalogName);
  +          }
  +          else
             {
  -            DBTable dbFKTable = dbFKSchema.getTable(strFKTableName);
  -            if (dbFKTable != null)
  +            dbFKCatalog = this.aSchema.getDBCatalog();
  +          }
  +          if (dbFKCatalog != null)
  +          {
  +            DBSchema dbFKSchema = dbFKCatalog.getSchema(strFKSchemaName);
  +            if (dbFKSchema != null)
               {
  -              DBColumn dbFKColumn = dbFKTable.getColumn(strFKColumnName);
  -              // The PK column is always from this table
  -              DBColumn dbPKColumn = getColumn(strPKColumnName);
  -              //Retrieve the FK Reference for the FK Table
  -              DBFKRelation aFKRef = 
  -                (DBFKRelation)this.hmCollections.get(dbFKSchema.getSchemaName() 
  -                  + "." + dbFKTable.getTableName());
  -              if (aFKRef == null)
  +              DBTable dbFKTable = dbFKSchema.getTable(strFKTableName);
  +              if (dbFKTable != null)
                 {
  -                aFKRef = new DBFKRelation(this, dbFKTable, true);
  -                this.hmCollections.put(dbFKSchema.getSchemaName() 
  -                  + "." + dbFKTable.getTableName(), aFKRef);
  +                DBColumn dbFKColumn = dbFKTable.getColumn(strFKColumnName);
  +                // The PK column is always from this table
  +                DBColumn dbPKColumn = getColumn(strPKColumnName);
  +                //Retrieve the FK Reference for the FK Table
  +                DBFKRelation aFKRef = 
  +                  (DBFKRelation)this.hmCollections.get(dbFKSchema.getSchemaName() 
  +                    + "." + dbFKTable.getTableName());
  +                if (aFKRef == null)
  +                {
  +                  aFKRef = new DBFKRelation(this, dbFKTable, true);
  +                  this.hmCollections.put(dbFKSchema.getSchemaName() 
  +                    + "." + dbFKTable.getTableName(), aFKRef);
  +                }
  +                aFKRef.addColumnPair(dbPKColumn, dbFKColumn);
                 }
  -              aFKRef.addColumnPair(dbPKColumn, dbFKColumn);
               }
             }
           }
         }
       }
  -    rs.close();    
  +    catch (SQLException sqlEx)
  +    {
  +      // sqlEx.printStackTrace();
  +    }
  +    try
  +    {
  +      rs.close();    
  +    }
  +    catch (Throwable t)
  +    {
  +    }
     }
     
     
  @@ -692,6 +626,9 @@
   
   /***************************** Changelog *****************************
   // $Log$
  +// Revision 1.3  2003/01/28 19:59:14  florianbruckner
  +// some updates to schema reading to make it a bit more compatible
  +//
   // Revision 1.2  2002/06/17 19:34:33  jvanzyl
   // Correcting all the package references.
   // PR:
  
  
  

Mime
View raw message