You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2011/09/13 11:23:38 UTC

svn commit: r1170098 - in /incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db: ./ mysql/ postgresql/ sqlserver/

Author: doebele
Date: Tue Sep 13 09:23:37 2011
New Revision: 1170098

URL: http://svn.apache.org/viewvc?rev=1170098&view=rev
Log:
EMPIREDB-115

Modified:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java?rev=1170098&r1=1170097&r2=1170098&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java Tue Sep 13 09:23:37 2011
@@ -129,9 +129,10 @@ public class DBCombinedCmd extends DBCom
    {
       // the left part
       left.clearOrderBy();
+      buf.append( "(" );
       left.getSelect(buf);
       // concat keyword     
-      buf.append( " " );
+      buf.append( ") " );
       buf.append( keyWord );
       buf.append( " (" );
       // the right part

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java?rev=1170098&r1=1170097&r2=1170098&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java Tue Sep 13 09:23:37 2011
@@ -33,7 +33,6 @@ import org.apache.empire.db.expr.join.DB
 import org.apache.empire.db.expr.join.DBJoinExprEx;
 import org.apache.empire.db.expr.set.DBSetExpr;
 import org.apache.empire.exceptions.MiscellaneousErrorException;
-import org.apache.empire.exceptions.NotSupportedException;
 import org.apache.empire.exceptions.ObjectNotValidException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -128,7 +127,6 @@ public abstract class DBCommand extends 
     }
 
     // Logger
-    @SuppressWarnings("hiding")
     protected static final Logger log = LoggerFactory.getLogger(DBCommand.class);
     // Distinct Select
     protected boolean                selectDistinct = false;
@@ -666,36 +664,6 @@ public abstract class DBCommand extends 
                 groupBy.add(expr);
         }
     }
-
-    /**
-     * set the maximum number of rows to return when executing a query command
-     * A negative value will remove the limit.
-     * 
-     * @return true if the database supports a limit or false otherwise
-     */
-    public void limitRows(int numRows)
-    {
-        throw new NotSupportedException(this, "limitRows");
-    }
-
-    /**
-     * sets the offset of the first row to return when executing a query command.
-     * A negative value will remove the offset.
-     * 
-     * @return true if the database supports an offset or false otherwise
-     */
-    public void skipRows(int numRows)
-    {
-        throw new NotSupportedException(this, "skipRows");
-    }
-    
-    /**
-     * Clears a limit or offset set by calling limit() or offset()
-     */
-    public void clearLimit()
-    {
-        // Nothing to do!
-    }
     
     public boolean hasSelectExpr()
     {

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java?rev=1170098&r1=1170097&r2=1170098&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java Tue Sep 13 09:23:37 2011
@@ -383,13 +383,13 @@ public abstract class DBCommandExpr exte
      * the key word= "UNION" and the selected DBCommandExpr.
      * 
      * @see org.apache.empire.db.DBCombinedCmd
-     * @param other the secend DBCommandExpr
+     * @param other the second DBCommandExpr
      * @return the new DBCombinedCmd object
      */
-    // Combinations
     public DBCommandExpr union(DBCommandExpr other)
-    {
-        return new DBCombinedCmd(this, "UNION", other);
+    {   // give driver a chance to subclass DBCombinedCmd
+    	DBDatabaseDriver driver = getDatabase().getDriver();
+    	return driver.createCombinedCommand(this, "UNION", other);
     }
 
     /**
@@ -400,8 +400,9 @@ public abstract class DBCommandExpr exte
      * @return the new DBCombinedCmd object
      */
     public DBCommandExpr intersect(DBCommandExpr other)
-    {
-        return new DBCombinedCmd(this, "INTERSECT", other);
+    {   // give driver a chance to subclass DBCombinedCmd
+    	DBDatabaseDriver driver = getDatabase().getDriver();
+    	return driver.createCombinedCommand(this, "INTERSECT", other);
     }
 
     /**
@@ -431,6 +432,36 @@ public abstract class DBCommandExpr exte
     }
 
     /**
+     * set the maximum number of rows to return when executing a query command
+     * A negative value will remove the limit.
+     * 
+     * @return true if the database supports a limit or false otherwise
+     */
+    public void limitRows(int numRows)
+    {
+        throw new NotSupportedException(this, "limitRows");
+    }
+
+    /**
+     * sets the offset of the first row to return when executing a query command.
+     * A negative value will remove the offset.
+     * 
+     * @return true if the database supports an offset or false otherwise
+     */
+    public void skipRows(int numRows)
+    {
+        throw new NotSupportedException(this, "skipRows");
+    }
+    
+    /**
+     * Clears a limit or offset set by calling limit() or offset()
+     */
+    public void clearLimit()
+    {
+        // Nothing to do!
+    }
+
+    /**
      * Adds a list of columns to the orderBy clause in ascending order
      * 
      * @param exprs vararg of column expressions

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java?rev=1170098&r1=1170097&r2=1170098&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java Tue Sep 13 09:23:37 2011
@@ -254,6 +254,19 @@ public abstract class DBDatabaseDriver i
     public abstract DBCommand createCommand(DBDatabase db);
 
     /**
+     * This function gives the driver a chance to provide a custom implementation 
+     * for a combined command such as UNION or INTERSECT 
+     * @param left the left command
+     * @param keyWord the key word (either "UNION" or "INTERSECT")
+     * @param left the right command
+     * @return a DBCommandExpr object
+     */
+    public DBCommandExpr createCombinedCommand(DBCommandExpr left, String keyWord, DBCommandExpr right)
+    {
+    	return new DBCombinedCmd(left, keyWord, right);
+    }
+
+    /**
      * Returns whether or not a particular feature is supported by this driver
      * @param type type of requested feature. @see DBDriverFeature
      * @return true if the features is supported or false otherwise

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java?rev=1170098&r1=1170097&r2=1170098&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBReader.java Tue Sep 13 09:23:37 2011
@@ -223,7 +223,6 @@ public class DBReader extends DBRecordDa
     }
 
     // Logger
-    @SuppressWarnings("hiding")
     protected static final Logger    log               = LoggerFactory.getLogger(DBReader.class);
     
     /**

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java?rev=1170098&r1=1170097&r2=1170098&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRecord.java Tue Sep 13 09:23:37 2011
@@ -59,8 +59,7 @@ public class DBRecord extends DBRecordDa
     public static final int REC_MODIFIED = 2;
     public static final int REC_NEW      = 3;
 
-    @SuppressWarnings("hiding")
-    protected static final Logger     log          = LoggerFactory.getLogger(DBRecord.class);
+    protected static final Logger log    = LoggerFactory.getLogger(DBRecord.class);
 
     // This is the record data
     private int             state;

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java?rev=1170098&r1=1170097&r2=1170098&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java Tue Sep 13 09:23:37 2011
@@ -79,7 +79,6 @@ public abstract class DBRowSet extends D
     }
     
     // Logger
-    @SuppressWarnings("hiding")
     protected static final Logger log = LoggerFactory.getLogger(DBRowSet.class);
     // Members
     protected final DBDatabase db;

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java?rev=1170098&r1=1170097&r2=1170098&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java Tue Sep 13 09:23:37 2011
@@ -27,6 +27,7 @@ import org.apache.empire.commons.StringU
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBCmdType;
 import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBCombinedCmd;
 import org.apache.empire.db.DBCommand;
 import org.apache.empire.db.DBCommandExpr;
 import org.apache.empire.db.DBDatabase;
@@ -42,9 +43,9 @@ import org.apache.empire.db.DBTableColum
 import org.apache.empire.db.DBView;
 import org.apache.empire.db.exceptions.InternalSQLException;
 import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.InvalidPropertyException;
 import org.apache.empire.exceptions.NotImplementedException;
 import org.apache.empire.exceptions.NotSupportedException;
-import org.apache.empire.exceptions.InvalidPropertyException;
 
 
 /**
@@ -240,6 +241,55 @@ public class DBDatabaseDriverMySQL exten
         return new DBCommandMySQL(db);
     }
 
+    @Override
+    /**
+     * Creates a combined command that supports limit() and skip()
+	 * @param left the first DBCommandExpr object
+	 * @param keyWord the key word between the two DBCommandExpr objects
+	 * @param right the second DBCommandExpr object
+     * @return the new DBCommandExpr object
+     */
+    public DBCommandExpr createCombinedCommand(DBCommandExpr left, String keyWord, DBCommandExpr right)
+    {
+    	// Override CombinedCmd
+    	return new DBCombinedCmd(left, keyWord, right) {
+			private static final long serialVersionUID = 1L;
+			protected int limit = -1;
+            protected int skip  = -1;
+            @Override
+            public void limitRows(int numRows)
+            {
+                limit = numRows;
+            }
+            @Override
+            public void skipRows(int numRows)
+            {
+                skip = numRows;
+            }
+            @Override
+            public void clearLimit()
+            {
+                limit = -1;
+                skip  = -1;
+            }
+            @Override
+            public void getSelect(StringBuilder buf)
+            {   // Prepares statement
+            	super.getSelect(buf);
+                // add limit and offset
+                if (limit>=0)
+                {   buf.append("\r\nLIMIT ");
+                    buf.append(String.valueOf(limit));
+                    // Offset
+                    if (skip>=0) 
+                    {   buf.append(" OFFSET ");
+                        buf.append(String.valueOf(skip));
+                    }    
+                }
+            }
+    	};
+    }
+
     /**
      * Returns whether or not a particular feature is supported by this driver
      * @param type type of requested feature. @see DBDriverFeature

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java?rev=1170098&r1=1170097&r2=1170098&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java Tue Sep 13 09:23:37 2011
@@ -57,7 +57,6 @@ public class DBDatabaseDriverPostgreSQL 
 {
     private final static long serialVersionUID = 1L;
   
-    @SuppressWarnings("hiding")
     private static final Logger log = LoggerFactory.getLogger(DBDatabaseDriverPostgreSQL.class);
     
     private static final String CREATE_REVERSE_FUNCTION =

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java?rev=1170098&r1=1170097&r2=1170098&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java (original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java Tue Sep 13 09:23:37 2011
@@ -43,9 +43,9 @@ import org.apache.empire.db.DBTableColum
 import org.apache.empire.db.DBView;
 import org.apache.empire.db.exceptions.InternalSQLException;
 import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.InvalidPropertyException;
 import org.apache.empire.exceptions.NotImplementedException;
 import org.apache.empire.exceptions.NotSupportedException;
-import org.apache.empire.exceptions.InvalidPropertyException;
 
 
 /**
@@ -101,7 +101,7 @@ public class DBDatabaseDriverMSSQL exten
             addListExpr(buf, select, CTX_ALL, ", ");
         }
     }
-	
+    
     // Properties
     private String databaseName = null;
     private String objectOwner = "dbo";
@@ -221,7 +221,7 @@ public class DBDatabaseDriverMSSQL exten
 
     /**
      * Returns whether or not a particular feature is supported by this driver
-     * @param type type of requrested feature. @see DBDriverFeature
+     * @param type type of requested feature. @see DBDriverFeature
      * @return true if the features is supported or false otherwise
      */
     @Override