empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1291318 - in /empire-db/trunk/empire-db/src/main/java/org/apache/empire/db: DBIndex.java DBTable.java oracle/DBCommandOracle.java
Date Mon, 20 Feb 2012 15:41:15 GMT
Author: doebele
Date: Mon Feb 20 15:41:15 2012
New Revision: 1291318

URL: http://svn.apache.org/viewvc?rev=1291318&view=rev
Log:
EMPIREDB-126
Add index table property

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBIndex.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTable.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBIndex.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBIndex.java?rev=1291318&r1=1291317&r2=1291318&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBIndex.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBIndex.java Mon Feb 20 15:41:15
2012
@@ -18,6 +18,8 @@
  */
 package org.apache.empire.db;
 
+import org.apache.empire.exceptions.InvalidArgumentException;
+
 /**
  * This class handles the primary key for the tables.
  * The primary key contains one or more columns.
@@ -30,7 +32,6 @@ public class DBIndex extends DBObject
     private final static long serialVersionUID = 1L;
   
     // Index Types
-    // TODO convert to an enum?
     /**
      * SQL Standard index
      */
@@ -49,6 +50,7 @@ public class DBIndex extends DBObject
     private String          name;
     private int             type;
     private DBColumn[]      columns;
+    private DBTable         table;
 
     /**
      * Constructs a DBIndex object set the specified parameters to this object.
@@ -64,10 +66,33 @@ public class DBIndex extends DBObject
         this.columns = columns;
     }
 
+    /** 
+     * returns the table this index belongs to.
+     * Valid only if the index has been added to a table (DBTable.addIndex)
+     * @return the corresponding table
+     */
+    public DBTable getTable()
+    {
+        return table;
+    }
+
+    /** 
+     * internally used to set the table for this index.
+     * The table must be added to the table's index list beforehand 
+     * @param table
+     */
+    protected void setTable(DBTable table)
+    {
+        if (table==null || !table.getIndexes().contains(this))
+            throw new InvalidArgumentException("table", table);
+        // table
+        this.table = table;
+    }
+
     @Override
     public DBDatabase getDatabase()
     {
-        return columns[0].getDatabase();
+        return (table!=null) ? table.getDatabase() : null;
     }
 
     /**

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=1291318&r1=1291317&r2=1291318&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 Mon Feb 20 15:41:15
2012
@@ -347,6 +347,7 @@ public class DBTable extends DBRowSet im
         }        
         // add Index now
         indexes.add(index);
+        index.setTable(this);
     }
 
     /**
@@ -358,12 +359,14 @@ public class DBTable extends DBRowSet im
      * 
      * @return true on success
      */
-    public void addIndex(String name, boolean unique, DBColumn[] columns)
+    public DBIndex addIndex(String name, boolean unique, DBColumn[] columns)
     {
         if (name==null || columns==null || columns.length==0)
             throw new InvalidArgumentException("name|columns", null);
         // add Index now
-        addIndex(new DBIndex(name, (unique) ? DBIndex.UNIQUE : DBIndex.STANDARD, columns));
+        DBIndex index = new DBIndex(name, (unique) ? DBIndex.UNIQUE : DBIndex.STANDARD, columns);
+        addIndex(index);
+        return index;
     }
 
     /**

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java?rev=1291318&r1=1291317&r2=1291318&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
Mon Feb 20 15:41:15 2012
@@ -21,8 +21,10 @@ package org.apache.empire.db.oracle;
 // Imports
 import org.apache.empire.db.DBCommand;
 import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBIndex;
 import org.apache.empire.db.DBTable;
 import org.apache.empire.db.expr.compare.DBCompareExpr;
+import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.ObjectNotValidException;
 
 /**
@@ -63,6 +65,16 @@ public class DBCommandOracle extends DBC
         this.optimizerHint = optimizerHint;
     }
 
+    public void setOptimizerIndexHint(DBIndex index)
+    {
+        if (index==null || index.getTable()==null)
+            throw new InvalidArgumentException("index", index);
+        // Set Index Hint
+        String tableAlias = index.getTable().getAlias();
+        String indexName  = index.getName();
+        this.optimizerHint = "INDEX ("+tableAlias+" "+indexName+")";
+    }
+
     /**
      * @see DBCommand#clear()
      */



Mime
View raw message