empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r980781 - in /incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db: ./ h2/ hsql/ mysql/ oracle/ postgresql/ sqlserver/
Date Fri, 30 Jul 2010 13:21:50 GMT
Author: doebele
Date: Fri Jul 30 13:21:50 2010
New Revision: 980781

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

Modified:
    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/DBDatabase.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDriverFeature.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.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/oracle/DBDatabaseDriverOracle.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/DBCommand.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java?rev=980781&r1=980780&r2=980781&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
Fri Jul 30 13:21:50 2010
@@ -557,10 +557,35 @@ public abstract class DBCommand extends 
     }
 
     /**
-     * Returns true if the command has constaints or false if not.
+     * set the maximum number of rows to return when executing a query command
+     * A negative value will remove the limit.
      * 
-     * @return true if constraints have been set on the command
+     * @return true if the database supports a limit or false otherwise
      */
+    public boolean limitRows(int numRows)
+    {
+        return error(Errors.NotSupported, "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 boolean skipRows(int numRows)
+    {
+        return error(Errors.NotSupported, "skipRows");
+    }
+    
+    /**
+     * Clears a limit or offset set by calling limit() or offset()
+     */
+    public void clearLimit()
+    {
+        // Nothing to do!
+    }
+    
     public boolean hasSelectExpr()
     {
         return (select!=null && select.size()>0);
@@ -674,6 +699,7 @@ public abstract class DBCommand extends 
         clearHaving();
         clearGroupBy();
         clearOrderBy();
+        clearLimit();
         cmdParams = null;
     }
 

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java?rev=980781&r1=980780&r2=980781&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
Fri Jul 30 13:21:50 2010
@@ -1113,11 +1113,12 @@ public abstract class DBDatabase extends
     public boolean commit(Connection conn)
     {
         try
-        {   // Check arguement
+        {   // Check argument
             if (conn==null)
                 return error(Errors.InvalidArg, null, "conn");
             // Commit
-            conn.commit();
+            if (conn.getAutoCommit()==false)
+                conn.commit();
             return true;
         } catch (SQLException sqle) 
         { 
@@ -1144,7 +1145,7 @@ public abstract class DBDatabase extends
             // Rollback
             log.info("Database rollback issued!");
             conn.rollback();
-            return true;
+            return success();
         } catch (SQLException sqle) 
         {
             return error(sqle);

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDriverFeature.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDriverFeature.java?rev=980781&r1=980780&r2=980781&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDriverFeature.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDriverFeature.java
Fri Jul 30 13:21:50 2010
@@ -26,5 +26,7 @@ package org.apache.empire.db;
 public enum DBDriverFeature {
     // Support Flags used by DBDatabaseDriver::isSupported()
     CREATE_SCHEMA,
-    SEQUENCES,    
+    SEQUENCES,
+    QUERY_LIMIT_ROWS,
+    QUERY_SKIP_ROWS
 }

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java?rev=980781&r1=980780&r2=980781&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
Fri Jul 30 13:21:50 2010
@@ -160,8 +160,10 @@ public class DBDatabaseDriverH2 extends 
         {   // return support info 
             case CREATE_SCHEMA: return true;
             case SEQUENCES:     return useSequenceTable;    
+            default:
+                // All other features are not supported by default
+                return false;
         }
-        return false;
     }
     
     /**

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java?rev=980781&r1=980780&r2=980781&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
Fri Jul 30 13:21:50 2010
@@ -99,8 +99,10 @@ public class DBDatabaseDriverHSql extend
         {   // return support info 
             case CREATE_SCHEMA: return false;
             case SEQUENCES:     return true;    
+            default:
+                // All other features are not supported by default
+                return false;
         }
-        return false;
     }
     
     /**

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=980781&r1=980780&r2=980781&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
Fri Jul 30 13:21:50 2010
@@ -55,10 +55,53 @@ public class DBDatabaseDriverMySQL exten
      */ 
     public static class DBCommandMySQL extends DBCommand
     {
+        protected int limit = -1;
+        protected int skip  = -1;
+        
         public DBCommandMySQL(DBDatabase db)
         {
             super(db);
         }
+        
+        @Override
+        public boolean limitRows(int numRows)
+        {
+            limit = numRows;
+            return success();
+        }
+
+        @Override
+        public boolean skipRows(int numRows)
+        {
+            skip = numRows;
+            return success();
+        }
+         
+        @Override
+        public void clearLimit()
+        {
+            limit = -1;
+            skip  = -1;
+        }
+        
+        @Override
+        public boolean getSelect(StringBuilder buf)
+        {   // call base class
+            if (super.getSelect(buf)==false)
+                return false;
+            // 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));
+                }    
+            }
+            // done
+            return success();
+        }
     }
     
     // Properties
@@ -204,10 +247,14 @@ public class DBDatabaseDriverMySQL exten
     {
         switch (type)
         {   // return support info 
-            case CREATE_SCHEMA: return true;
-            case SEQUENCES:     return useSequenceTable;    
+            case CREATE_SCHEMA:     return true;
+            case SEQUENCES:         return useSequenceTable;
+            case QUERY_LIMIT_ROWS:  return true;
+            case QUERY_SKIP_ROWS:   return true;
+            default:
+                // All other features are not supported by default
+                return false;
         }
-        return false;
     }
     
     /**

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java?rev=980781&r1=980780&r2=980781&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
Fri Jul 30 13:21:50 2010
@@ -94,9 +94,11 @@ public class DBDatabaseDriverOracle exte
         switch (type)
         {   // return support info 
             case CREATE_SCHEMA: return false;
-            case SEQUENCES:     return true;    
+            case SEQUENCES:     return true;
+            default:
+                // All other features are not supported by default
+                return false;
         }
-        return false;
     }
 
     /**

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=980781&r1=980780&r2=980781&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
Fri Jul 30 13:21:50 2010
@@ -268,8 +268,10 @@ public class DBDatabaseDriverPostgreSQL 
         {   // return support info 
             case CREATE_SCHEMA: return true;
             case SEQUENCES:     return true;    
+            default:
+                // All other features are not supported by default
+                return false;
         }
-        return false;
     }
     
     /**

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=980781&r1=980780&r2=980781&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
Fri Jul 30 13:21:50 2010
@@ -57,10 +57,43 @@ public class DBDatabaseDriverMSSQL exten
      */ 
     public static class DBCommandMSSQL extends DBCommand
     {
-    	public DBCommandMSSQL(DBDatabase db)
+        protected int limit = -1;
+
+        public DBCommandMSSQL(DBDatabase db)
     	{
     		super(db);
     	}
+        
+        @Override
+        public boolean limitRows(int numRows)
+        {
+            limit = numRows;
+            return success();
+        }
+         
+        @Override
+        public void clearLimit()
+        {
+            limit = -1;
+        }
+        
+        @Override
+        protected void addSelect(StringBuilder buf)
+        {   
+            // Prepares statement
+            buf.append("SELECT ");
+            if (selectDistinct)
+                buf.append("DISTINCT ");
+            // Add limit
+            if (limit>=0)
+            {   // Limit
+                buf.append("TOP ");
+                buf.append(String.valueOf(limit));
+                buf.append(" ");
+            }
+            // Add Select Expressions
+            addListExpr(buf, select, CTX_ALL, ", ");
+        }
     }
 	
     // Properties
@@ -194,10 +227,14 @@ public class DBDatabaseDriverMSSQL exten
     {
         switch (type)
         {   // return support info 
-            case CREATE_SCHEMA: return true;
-            case SEQUENCES:     return useSequenceTable;    
+            case CREATE_SCHEMA:     return true;
+            case SEQUENCES:         return useSequenceTable;    
+            case QUERY_LIMIT_ROWS:  return true;
+            case QUERY_SKIP_ROWS:   return false;
+            default:
+                // All other features are not supported by default
+                return false;
         }
-        return false;
     }
 
     /**



Mime
View raw message