Merged "Open PHP Declaration" and "Open Include File" into one action "Open Declarati...
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / model / EntityImpl.java
index 966329a..41ffad2 100644 (file)
@@ -48,12 +48,17 @@ abstract class EntityImpl implements Entity {
     private String type;
     private Bookmark bookmark;
     private Boolean exists = Boolean.TRUE;
+    private boolean isSynonym = false; // Tells if its a synonym or not
+    // Columns will be cached in this array, as sometimes asking for them to the JDBC driver is very costy
+    // (for example in Oracle when synonyms and remarks are asked for )
+    private Column[] columns = null; 
     
-    public EntityImpl(Bookmark bookmark, String schema, String name, String type) {
+    public EntityImpl(Bookmark bookmark, String schema, String name, String type, boolean isSynonym) {
         this.schema = schema;
         this.name = name;
         this.type = type;
         this.bookmark = bookmark;
+        this.isSynonym = isSynonym;
     }
     public Bookmark getBookmark() {
         return this.bookmark;
@@ -73,26 +78,28 @@ abstract class EntityImpl implements Entity {
     }
     public Column getColumn(String columnName) throws NotConnectedException, SQLException  {
         Column column = null;
-        Column[] columns = getColumns();
-        for (int i = 0, length = (columns == null) ? 0 : columns.length;
+        if (this.columns == null) this.columns = getColumns();
+        for (int i = 0, length = (this.columns == null) ? 0 : this.columns.length;
             column == null && i < length;
             i++) {
-            if (columnName != null && columnName.equals(columns[i].getName())) {
-                column = columns[i];
+            if (columnName != null && columnName.equals(this.columns[i].getName())) {
+                column = this.columns[i];
             }
         }
         return column;
     }
     public Column[] getColumns() throws NotConnectedException, SQLException {
-        
+        if (this.columns != null) return this.columns;
         Connection connection = this.bookmark.getConnection();
         try {
-               return getColumnsFromMetaData(connection);
+               this.columns = getColumnsFromMetaData(connection);
+               return this.columns;
         } catch (SQLException e) {
                if (SQLStates.ODBC_DRIVER_NOT_CAPABLE.equals(e.getSQLState()) 
                                && AdapterFactory.JDBC_ODBC_BRIDGE.equals(
                                                getBookmark().getJDBCDriver().getType())) {
-                       return getColumnsFromQuery(connection);
+                       this.columns = getColumnsFromQuery(connection);
+                       return this.columns;
                } else {
                        throw e;
                }
@@ -120,10 +127,7 @@ abstract class EntityImpl implements Entity {
                            resultSet.getInt(COLUMN_METADATA_DECIMAL_DIGITS),
                            "YES".equalsIgnoreCase(resultSet.getString(COLUMN_METADATA_IS_NULLABLE)),
                            resultSet.getInt(COLUMN_METADATA_ORDINAL_POSITION),
-                                       getComments(
-                                                       resultSet.getString(COLUMN_METADATA_REMARKS),
-                                                       getQualifiedName(), 
-                                                       resultSet.getString(COLUMN_METADATA_COLUMN_NAME))
+                                       resultSet.getString(COLUMN_METADATA_REMARKS)
                            );
                        temp.put(column.getName(), column);
                    }
@@ -173,7 +177,7 @@ abstract class EntityImpl implements Entity {
                            (String) rows[i].get(1),
                            (String) rows[i].get(2),
                            ((Integer) rows[i].get(7)).intValue(),
-                           ((Integer) rows[i].get(3)).intValue(),
+                           ((Long) rows[i].get(3)).longValue(),
                            ((Integer) rows[i].get(4)).intValue(),
                            "Nullable".equalsIgnoreCase((String) rows[i].get(5)),
                            i+1, "");
@@ -187,6 +191,11 @@ abstract class EntityImpl implements Entity {
         * @param iniComment The already got comment
         * @param tableName The fully qualified table name
         * @param columnName The column name
+        * 
+        *  NO LONGER USED, there is a parameter (remarksReporting) in the JDBC connection that makes ORACLE return the
+        * remarks for tables and columns. Is slower, so an option will be used.
+        * 
+        * The function is kept in case other JDBC drivers have the same problem
         */
        private String getComments( String iniComment, String tableName, String columnName) {
                if (iniComment != null && iniComment.length() > 0) 
@@ -298,4 +307,12 @@ abstract class EntityImpl implements Entity {
                        return this.getQualifiedName().compareTo(that.getQualifiedName());
                }
        }
+    
+    /**
+        * @return Returns the isSynonym.
+        */
+       public boolean isSynonym() {
+               return isSynonym;
+       }
+       
 }
\ No newline at end of file