*** empty log message ***
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / model / Database.java
index 5637b55..cdc3501 100644 (file)
@@ -12,14 +12,32 @@ import java.util.Set;
 
 import com.quantum.adapters.DatabaseAdapter;
 import com.quantum.sql.MultiSQLServer;
-import com.quantum.sql.SQLResults;
+import com.quantum.sql.SQLResultSetResults;
 
 /**
  * @author BC
  */
 public class Database {
     
-    private DatabaseAdapter databaseAdapter;
+       private static final int TABLE_METADATA_TABLE_SCHEM = 2;
+       private static final int TABLE_METADATA_TABLE_NAME = 3;
+       
+       private static final int TABLE_TYPE_METADATA_TABLE_TYPE = 1;
+
+       private static final int FOREIGN_KEY_METADATA_PKTABLE_SCHEM = 2;
+       private static final int FOREIGN_KEY_METADATA_PKTABLE_NAME = 3;
+       private static final int FOREIGN_KEY_METADATA_PKCOLUMN_NAME = 4;
+       private static final int FOREIGN_KEY_METADATA_FKTABLE_SCHEM = 6;
+       private static final int FOREIGN_KEY_METADATA_FKTABLE_NAME = 7;
+       private static final int FOREIGN_KEY_METADATA_FKCOLUMN_NAME = 8;
+       private static final int FOREIGN_KEY_METADATA_KEY_SEQ = 9;
+       private static final int FOREIGN_KEY_METADATA_DELETE_RULE = 11;
+       private static final int FOREIGN_KEY_METADATA_FK_NAME = 12;
+       
+       private static final int TYPE_INFO_METADATA_TYPE_NAME = 1;
+       private static final int TYPE_INFO_METADATA_DATA_TYPE = 2;
+       
+       private DatabaseAdapter databaseAdapter;
     private Bookmark bookmark;
     
     public Database(Bookmark bookmark) {
@@ -80,7 +98,7 @@ public class Database {
         DatabaseMetaData metaData = connection.getMetaData();
         ResultSet resultSet = metaData.getTableTypes();
         while (resultSet.next()) {
-            String type = resultSet.getString("TABLE_TYPE");
+            String type = resultSet.getString(TABLE_TYPE_METADATA_TABLE_TYPE);
             if (type != null) {
                // Informix, in particular, pads this with extra spaces
                 type = type.trim();
@@ -149,9 +167,10 @@ public class Database {
 
         String sql = getSQL(bookmark, type, schema);
         List list = new ArrayList();
-        SQLResults results = null;
+        SQLResultSetResults results = null;
         if (sql != null) {
-            results = MultiSQLServer.getInstance().execute(connection, sql);
+            results = (SQLResultSetResults) MultiSQLServer.getInstance().execute(
+                       bookmark, connection, sql, Integer.MAX_VALUE);
             for (int i = 1, size = (results == null) ? 0 : results.getRowCount(); i <= size; i++) {
                 String schemaName = results.getColumnCount() == 1 
                     ? schema.getName() : results.getElement(1, i).toString();
@@ -173,15 +192,16 @@ public class Database {
         DatabaseMetaData metaData = connection.getMetaData();
         // getTables needs a null schema to get all the schemas. So we don't pass a "" schema, but a null one
                ResultSet set = null;
-               if (metaData.supportsSchemasInTableDefinitions())
+               if (metaData.supportsSchemasInTableDefinitions()) {
                set = metaData.getTables(null, (schema != null) ? schema.getName() : null, "%", new String[] { type });
-           else
+               } else {
                        set = metaData.getTables(null, null, "%", new String[] { type });
+               }
            
         while (set.next()) {
-            String tempSchema = set.getString("TABLE_SCHEM");
+            String tempSchema = set.getString(TABLE_METADATA_TABLE_SCHEM);
             tempSchema = (tempSchema == null) ? "" : tempSchema.trim();
-            String tableName = set.getString("TABLE_NAME");
+            String tableName = set.getString(TABLE_METADATA_TABLE_NAME);
             tableName = (tableName == null) ? "" : tableName.trim();
 
             if (tableName != null && tableName.length() > 0) {
@@ -201,8 +221,8 @@ public class Database {
        ResultSet results = metaData.getTypeInfo();
        try {
                while (results.next()) {
-                       String name = results.getString("TYPE_NAME");
-                       int type = results.getInt("DATA_TYPE");
+                       String name = results.getString(TYPE_INFO_METADATA_TYPE_NAME);
+                       int type = results.getInt(TYPE_INFO_METADATA_DATA_TYPE);
                        list.add(new DataType(type, name));
                }
        } finally {
@@ -261,23 +281,23 @@ public class Database {
                int lowestKeySequence = Integer.MAX_VALUE;
                try {
                        while (resultSet.next()) {
-                               int keySequence = resultSet.getInt("KEY_SEQ");
+                               int keySequence = resultSet.getInt(FOREIGN_KEY_METADATA_KEY_SEQ);
                                lowestKeySequence = Math.min(lowestKeySequence, keySequence);
                                
                                if (keySequence == lowestKeySequence || foreignKey == null) {
                                        foreignKey = new ForeignKeyImpl();
                                        list.add(foreignKey);
-                                       foreignKey.setName(resultSet.getString("FK_NAME"));
-                                       foreignKey.setDeleteRule(resultSet.getShort("DELETE_RULE"));
-                                       foreignKey.setForeignEntitySchema(resultSet.getString("FKTABLE_SCHEM"));
-                                       foreignKey.setForeignEntityName(resultSet.getString("FKTABLE_NAME"));
-                                       foreignKey.setLocalEntitySchema(resultSet.getString("PKTABLE_SCHEM"));
-                                       foreignKey.setLocalEntityName(resultSet.getString("PKTABLE_NAME"));
+                                       foreignKey.setName(resultSet.getString(FOREIGN_KEY_METADATA_FK_NAME));
+                                       foreignKey.setDeleteRule(resultSet.getShort(FOREIGN_KEY_METADATA_DELETE_RULE));
+                                       foreignKey.setForeignEntitySchema(resultSet.getString(FOREIGN_KEY_METADATA_FKTABLE_SCHEM));
+                                       foreignKey.setForeignEntityName(resultSet.getString(FOREIGN_KEY_METADATA_FKTABLE_NAME));
+                                       foreignKey.setLocalEntitySchema(resultSet.getString(FOREIGN_KEY_METADATA_PKTABLE_SCHEM));
+                                       foreignKey.setLocalEntityName(resultSet.getString(FOREIGN_KEY_METADATA_PKTABLE_NAME));
                                }
                                
                                foreignKey.addColumns(
-                                               resultSet.getString("PKCOLUMN_NAME"), 
-                                               resultSet.getString("FKCOLUMN_NAME"));
+                                               resultSet.getString(FOREIGN_KEY_METADATA_PKCOLUMN_NAME), 
+                                               resultSet.getString(FOREIGN_KEY_METADATA_FKCOLUMN_NAME));
                        }
                        return (ForeignKey[]) list.toArray(new ForeignKey[list.size()]);
                } finally {