empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1532792 - /empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
Date Wed, 16 Oct 2013 15:21:46 GMT
Author: doebele
Date: Wed Oct 16 15:21:46 2013
New Revision: 1532792

URL: http://svn.apache.org/r1532792
Log:
EMPIREDB-196
limitRows and skipRows for H2 databsae - a contribution of Bimal Manukonda.

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java?rev=1532792&r1=1532791&r2=1532792&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/h2/DBDatabaseDriverH2.java
Wed Oct 16 15:21:46 2013
@@ -31,6 +31,7 @@ import org.apache.empire.db.DBDriverFeat
 import org.apache.empire.db.DBObject;
 import org.apache.empire.db.DBSQLScript;
 import org.apache.empire.db.DBTable;
+import org.apache.empire.exceptions.InvalidArgumentException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,10 +53,54 @@ public class DBDatabaseDriverH2 extends 
     {
         private final static long serialVersionUID = 1L;
       
+	    protected int limitRows = -1;
+	    protected int skipRows  =  0;
+        
         public DBCommandH2(DBDatabase db)
         {
             super(db);
         }
+    
+	    @Override
+	    public void limitRows(int limitRows)
+	    {
+	        // set limit
+	        this.limitRows = limitRows;
+	    }
+	
+	    @Override
+	    public void skipRows(int skipRows)
+	    {
+	        if (skipRows<0)
+	            throw new InvalidArgumentException("skipRows", skipRows);
+	        // set skip
+	        this.skipRows = skipRows; 
+	    }
+	     
+	    @Override
+	    public void clearLimit()
+	    {
+	    	// remove skip and limit
+	        this.limitRows = -1;
+	        this.skipRows  =  0;
+	    }
+        
+        @Override
+        public void getSelect(StringBuilder buf)
+        {   // Prepares statement
+        	super.getSelect(buf);
+            // add limit and offset
+            if (limitRows>=0)
+            {   buf.append("\r\nLIMIT ");
+                buf.append(String.valueOf(limitRows));
+                // Offset
+                if (skipRows>0) 
+                {   buf.append(" OFFSET ");
+                    buf.append(String.valueOf(skipRows));
+                }    
+            }
+        }
+        
     }
     
     // Properties
@@ -158,8 +203,10 @@ public class DBDatabaseDriverH2 extends 
     {
         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;



Mime
View raw message