added perspective shortcuts for debug and resource to php perspective
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / model / Database.java
index 058c48d..29d1993 100644 (file)
@@ -167,6 +167,8 @@ public class Database {
             
         for (int i = 0; i < types.length; i++) {
             list.addAll(getEntitiesList(bookmark, connection, types[i], schema));
+            // TODO: This should be polished so that synonyms can be shown with different icons as regular Entities
+            list.addAll(getSynonymsList(bookmark, connection, types[i], schema));
         }
 
         return (Entity[]) list.toArray(new Entity[list.size()]);
@@ -193,7 +195,7 @@ public class Database {
             tableName = (tableName == null) ? "" : tableName.trim();
 
             if (tableName != null && tableName.length() > 0) {
-                Entity entity = EntityFactory.getInstance().create(bookmark, tempSchema, tableName, type);
+                Entity entity = EntityFactory.getInstance().create(bookmark, tempSchema, tableName, type, false);
                 if (entity != null) {
                     list.add(entity);
                 }
@@ -225,7 +227,7 @@ public class Database {
                     : results.getElement(2, i).toString();
                 if (tableName != null && tableName.length() > 0) {
                     Entity entity = EntityFactory.getInstance().create(
-                        bookmark, schemaName, tableName, type);
+                        bookmark, schemaName, tableName, type, false);
                     if (entity != null) {
                         list.add(entity);
                     }
@@ -234,6 +236,48 @@ public class Database {
         }
         return list;
     }
+    /**
+     * Returns a list with the synonym objects of the given type, using a query  
+     * @param bookmark
+     * @param connection
+     * @param type
+     * @param schema
+     * @return
+     * @throws SQLException
+     */
+    protected List getSynonymsList(Bookmark bookmark, Connection connection, String type, Schema schema)
+    throws SQLException {
+
+    List list = new ArrayList();
+    //      We try first the JDBC driver
+    DatabaseMetaData metaData = connection.getMetaData();
+    SQLResultSetResults results = null;
+    // Get the proper sql query to the appropiate type of entity
+    String sql = this.databaseAdapter.getShowSynonymsQuery(schema.getName(), type);
+    // If nothing returned, too bad, it seems there is no sql query for that database and entity type
+    if (sql != null) {
+        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();
+            if (schemaName != null) {
+               schemaName = schemaName.trim();
+            }
+            String tableName = results.getColumnCount() == 1 
+                ? results.getElement(1, i).toString() 
+                : results.getElement(2, i).toString();
+            if (tableName != null && tableName.length() > 0) {
+                Entity entity = EntityFactory.getInstance().create(
+                    bookmark, schemaName, tableName, type, true);
+                if (entity != null) {
+                    list.add(entity);
+                }
+            }
+        }
+    }
+    return list;
+}
     
     public DataType[] getTypes() throws NotConnectedException, SQLException {
        DatabaseMetaData metaData = getMetaData();
@@ -244,7 +288,7 @@ public class Database {
                        list.add(new DataType(
                                        results.getInt(TYPE_INFO_METADATA_DATA_TYPE),
                                        results.getString(TYPE_INFO_METADATA_TYPE_NAME),
-                                               results.getInt(TYPE_INFO_METADATA_PRECISION),
+                                               results.getLong(TYPE_INFO_METADATA_PRECISION),
                                                results.getString(TYPE_INFO_METADATA_LITERAL_PREFIX),
                                                results.getString(TYPE_INFO_METADATA_LITERAL_SUFFIX),
                                                results.getString(TYPE_INFO_METADATA_CREATE_PARMS)