empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1355345 - in /empire-db/trunk/empire-db/src/main/java/org/apache/empire/db: DBRelation.java DBTable.java
Date Fri, 29 Jun 2012 12:50:04 GMT
Author: doebele
Date: Fri Jun 29 12:50:03 2012
New Revision: 1355345

URL: http://svn.apache.org/viewvc?rev=1355345&view=rev
Log:
EMPIREDB-149
added method "getForeignKeyRelations" to DBTable

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRelation.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRelation.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRelation.java?rev=1355345&r1=1355344&r2=1355345&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRelation.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRelation.java Fri Jun 29
12:50:03 2012
@@ -140,6 +140,25 @@ public class DBRelation extends DBObject
     {
         return references;
     }
+    
+    /**
+     * Returns the table that is containing the foreign key (source table) 
+     * @return true if the relation's source table is the given table 
+     */
+    public DBTable getForeignKeyTable()
+    {
+        return (DBTable)references[0].getSourceColumn().getRowSet();
+    }
+
+    /**
+     * Returns the table that is referenced by this foreign key relation (target table)
+     * @return true if the relation's target table 
+     */
+    public DBTable getReferencedTable()
+    {
+        return (DBTable)references[0].getTargetColumn().getRowSet();
+    }
+    
 
     @Override
     public DBDatabase getDatabase()
@@ -192,5 +211,33 @@ public class DBRelation extends DBObject
     {
         setOnDeleteAction(DBCascadeAction.CASCADE_RECORDS);
     }
+    
+    @Override
+    public String toString()
+    {
+        StringBuilder b = new StringBuilder();
+        b.append("\"");
+        b.append(this.getForeignKeyTable().getName());
+        b.append("\" CONSTRAINT \"");
+        b.append(this.name);
+        b.append("\" FOREIGN KEY (");
+        for (int i=0; i<references.length; i++)
+        {
+            b.append((i>0) ? ", \"" : "\"");
+            b.append(references[i].getSourceColumn().getName());
+            b.append("\"");
+        }
+        b.append(") REFERENCES \"");
+        b.append(this.getReferencedTable().getName());
+        b.append("\" (");
+        for (int i=0; i<references.length; i++)
+        {
+            b.append((i>0) ? ", \"" : "\"");
+            b.append(references[i].getTargetColumn().getName());
+            b.append("\"");
+        }
+        b.append(")");
+        return b.toString();
+    }
 
 }
\ No newline at end of file

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java?rev=1355345&r1=1355344&r2=1355345&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java Fri Jun 29 12:50:03
2012
@@ -509,5 +509,20 @@ public class DBTable extends DBRowSet im
             throw new RecordUpdateInvalidException(this, key);
         }
     }
+    
+    /**
+     * Returns a list of all foreign key relations for this table
+     * @return the list of foreign key relations
+     */
+    public List<DBRelation> getForeignKeyRelations()
+    {
+        List<DBRelation> relations = new ArrayList<DBRelation>();
+        for (DBRelation r : getDatabase().getRelations())
+        {   // check relation
+            if (this.equals(r.getForeignKeyTable()))
+                relations.add(r);
+        }
+        return relations;
+    }
 
 }
\ No newline at end of file



Mime
View raw message