Tag: cws_src680_qiq
User: fs      
Date: 2006/06/29 03:17:18

Modified:
   dba/connectivity/qa/connectivity/tools/HsqlDatabase.java

Log:
 support for foreign keys

File Changes:

Directory: /dba/connectivity/qa/connectivity/tools/
===================================================

File [changed]: HsqlDatabase.java
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/qa/connectivity/tools/HsqlDatabase.java?r1=1.2.54.3&r2=1.2.54.4
Delta lines:  +47 -7
--------------------
--- HsqlDatabase.java   27 Jun 2006 20:14:11 -0000      1.2.54.3
+++ HsqlDatabase.java   29 Jun 2006 10:17:15 -0000      1.2.54.4
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: HsqlDatabase.java,v $
  *
- *  $Revision: 1.2.54.3 $
+ *  $Revision: 1.2.54.4 $
  *
- *  last change: $Author: fs $ $Date: 2006/06/27 20:14:11 $
+ *  last change: $Author: fs $ $Date: 2006/06/29 10:17:15 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -51,6 +51,9 @@
 import java.io.File;
 
 import com.sun.star.util.CloseVetoException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
 
 /**
  *
@@ -206,23 +209,43 @@
 
         String primaryKeyList = "";
 
+        HashMap foreignKeys = new HashMap();
+        HashMap foreignKeyRefs = new HashMap();
+
         HsqlColumnDescriptor[] columns = _tableDesc.getColumns();
         for ( int i=0; i<columns.length; ++i )
         {
             if ( i > 0 )
                 createStatement += ", ";
 
-            createStatement += "\"" + columns[i].Name;
-            createStatement += "\" " + columns[i].TypeName;
+            createStatement += "\"" + columns[i].getName();
+            createStatement += "\" " + columns[i].getTypeName();
 
-            if ( columns[i].NotNull )
+            if ( columns[i].isRequired() )
                 createStatement += " NOT NULL";
 
-            if ( columns[i].PrimaryKey )
+            if ( columns[i].isPrimaryKey() )
             {
                 if ( primaryKeyList.length() > 0 )
                     primaryKeyList += ", ";
-                primaryKeyList += "\"" + columns[i].Name + "\"";
+                primaryKeyList += "\"" + columns[i].getName() + "\"";
+            }
+
+            if ( columns[i].isForeignKey() )
+            {
+                String foreignTable = columns[i].getForeignTable();
+
+                String foreignKeysForTable = foreignKeys.containsKey( 
foreignTable ) ? (String)foreignKeys.get( foreignTable ) : "";
+                if ( foreignKeysForTable.length() > 0 )
+                    foreignKeysForTable += ", ";
+                foreignKeysForTable += "\"" + columns[i].getName() + "\"";
+                foreignKeys.put( foreignTable, foreignKeysForTable );
+
+                String foreignKeyRefsForTable = foreignKeyRefs.containsKey( 
foreignTable ) ? (String)foreignKeyRefs.get( foreignTable ) : "";
+                if ( foreignKeyRefsForTable.length() > 0 )
+                    foreignKeyRefsForTable += ", ";
+                foreignKeyRefsForTable += "\"" + columns[i].getForeignColumn() 
+ "\"";
+                foreignKeyRefs.put( foreignTable, foreignKeyRefsForTable );
             }
         }
 
@@ -233,8 +256,25 @@
             createStatement += ")";
         }
 
+        Set foreignKeyTables = foreignKeys.keySet();
+        for (   Iterator foreignKey = foreignKeyTables.iterator();
+                foreignKey.hasNext();
+            )
+        {
+            String foreignTable = (String)foreignKey.next();
+
+            createStatement += ", FOREIGN KEY (";
+            createStatement += (String)foreignKeys.get(foreignTable);
+            createStatement += ") REFERENCES \"";
+            createStatement += foreignTable;
+            createStatement += "\"(";
+            createStatement += (String)foreignKeyRefs.get(foreignTable);
+            createStatement += ")";
+        }
+
         createStatement += ")";
 
+        //System.err.println( createStatement );
         executeSQL( createStatement );
     }
 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to