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 2013/09/13 15:55:24 UTC
svn commit: r1522932 - in /empire-db/trunk:
empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/
empire-db/src/main/java/org/apache/empire/db/
empire-db/src/main/java/org/apache/empire/db/oracle/
Author: doebele
Date: Fri Sep 13 13:55:23 2013
New Revision: 1522932
URL: http://svn.apache.org/r1522932
Log:
EMPIREDB-192
set support for QUERY_SKIP_ROWS
Modified:
empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java?rev=1522932&r1=1522931&r2=1522932&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java Fri Sep 13 13:55:23 2013
@@ -32,6 +32,8 @@ import org.apache.empire.data.DataType;
import org.apache.empire.db.DBColumn;
import org.apache.empire.db.DBColumnExpr;
import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBDatabaseDriver;
+import org.apache.empire.db.DBDriverFeature;
import org.apache.empire.db.DBReader;
import org.apache.empire.db.DBRecordData;
import org.apache.empire.db.DBRowSet;
@@ -71,6 +73,8 @@ public class BeanListPageElement<T> exte
protected DBOrderByExpr secondarySortOrder = null;
+ protected int maxItemCount = 1000;
+
/**
* Extended ListTableInfo
*/
@@ -258,7 +262,11 @@ public class BeanListPageElement<T> exte
return (noQueryResult!=null) ? ObjectUtils.getBoolean( noQueryResult ) : false;
}
- private void loadItems(boolean initScrollbar)
+ /**
+ * loads all visible list items from the database
+ * @param initScrollbar
+ */
+ protected void loadItems(boolean initScrollbar)
{
// DBReader
BeanListTableInfo lti = (BeanListTableInfo) getTableInfo();
@@ -277,32 +285,44 @@ public class BeanListPageElement<T> exte
setOrderBy(queryCmd);
lti.setSortOrderChanged(false);
}
-
- // DBReader.open immer nur innerhalb eines try {} finally {} blocks!
- r.open(queryCmd, getConnection(queryCmd));
-
- // get position from the session
+
int position = 0;
- int maxItems = 1000;
+ int skipRows = 0;
+ int maxItems = maxItemCount;
if (loadPageFromPosition)
- {
+ { // detect position
position = lti.getPosition();
- if (position < 0)
- { // position < 0 is not possible, set to 0
- position = 0;
- }
if (position > lti.getItemCount() - lti.getPageSize())
{ // position > count of entries is not possible, set to max
position = lti.getItemCount() - lti.getPageSize();
}
- if (position > 0)
- { // we are not at position 0, "skipping" entries
- r.skipRows(position);
- }
- else
+ if (position < 0)
+ { // position < 0 is not possible, set to 0
position = 0;
+ }
// maxItems
maxItems = lti.getPageSize();
+ skipRows = position;
+ // constraint
+ DBDatabaseDriver driver = queryCmd.getDatabase().getDriver();
+ if (driver.isSupported(DBDriverFeature.QUERY_LIMIT_ROWS))
+ { // let the database limit the rows
+ if (skipRows>0 && driver.isSupported(DBDriverFeature.QUERY_SKIP_ROWS))
+ { // let the database skip the rows
+ queryCmd.skipRows(skipRows);
+ skipRows = 0;
+ }
+ queryCmd.limitRows(skipRows+maxItems);
+ }
+ }
+
+ // DBReader.open immer nur innerhalb eines try {} finally {} blocks!
+ r.open(queryCmd, getConnection(queryCmd));
+
+ // get position from the session
+ if (skipRows>0)
+ { // we are not at position 0, "skipping" entries
+ r.skipRows(skipRows);
}
// Read all Items
Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java?rev=1522932&r1=1522931&r2=1522932&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java Fri Sep 13 13:55:23 2013
@@ -508,6 +508,41 @@ public abstract class DBCommand extends
}
/**
+ * Returns true if the command has a constraint on the given table or false otherwise.
+ *
+ * @param rowset rowset table or view to join
+ *
+ * @return true if the command has a join on the given table or false otherwise
+ */
+ public boolean hasConstraintOn(DBRowSet rowset)
+ {
+ if (where==null && having==null)
+ return false;
+ // Examine all constraints
+ int i = 0;
+ Set<DBColumn> columns = new HashSet<DBColumn>();
+ for (i = 0; where != null && i < where.size(); i++)
+ ((DBExpr) where.get(i)).addReferencedColumns(columns);
+ /*
+ for (i = 0; groupBy != null && i < groupBy.size(); i++)
+ ((DBExpr) groupBy.get(i)).addReferencedColumns(columns);
+ */
+ for (i = 0; having != null && i < having.size(); i++)
+ ((DBExpr) having.get(i)).addReferencedColumns(columns);
+ // now we have all columns
+ Iterator<DBColumn> iterator = columns.iterator();
+ while (iterator.hasNext())
+ { // get the table
+ DBColumn col = iterator.next();
+ DBRowSet table = col.getRowSet();
+ if (table.equals(rowset))
+ return true;
+ }
+ // not found
+ return false;
+ }
+
+ /**
* Returns true if the command has a join on the given column or false otherwise.
*
* @param column the column to test
@@ -855,7 +890,7 @@ public abstract class DBCommand extends
*
* @return list of all rowsets (tables or views) used by the query
*/
- protected List<DBRowSet> getTableList()
+ protected List<DBRowSet> getRowSetList()
{
// Check all tables
int i = 0;
@@ -1059,14 +1094,12 @@ public abstract class DBCommand extends
buf.append("\r\nFROM ");
// Join
boolean sep = false;
- List<DBRowSet> tables = getTableList();
+ List<DBRowSet> tables = getRowSetList();
if (joins!=null && joins.size()>0)
{ // Join
List<DBRowSet> joinTables = new ArrayList<DBRowSet>();
-// for (int i=0;i<joins.size();i++)
-// buf.append("(");
- for (int i=0;i<joins.size();i++)
- { // Joins zusammenbauen
+ for (int i=0; i<joins.size(); i++)
+ { // append join
long context;
DBJoinExpr join = joins.get(i);
if (i<1)
@@ -1091,7 +1124,7 @@ public abstract class DBCommand extends
buf.append( "\t" );
}
join.addSQL(buf, context);
-// buf.append(")");
+ // add CRLF
if( i!=joins.size()-1 )
buf.append("\r\n");
}
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=1522932&r1=1522931&r2=1522932&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 Fri Sep 13 13:55:23 2013
@@ -315,7 +315,10 @@ public class DBCommandOracle extends DBC
if (val instanceof DBColumnExpr)
inner.select(((DBColumnExpr)val));
}
- inner.removeJoinsOn(table);
+ // remove join (if not necessary)
+ if (inner.hasConstraintOn(table)==false)
+ inner.removeJoinsOn(table);
+ // add SQL for inner statement
inner.addSQL(buf, CTX_DEFAULT);
// find the source table
DBColumnExpr left = updateJoin.getLeft();
Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java?rev=1522932&r1=1522931&r2=1522932&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java Fri Sep 13 13:55:23 2013
@@ -110,7 +110,7 @@ public class DBDatabaseDriverOracle exte
case CREATE_SCHEMA: return false;
case SEQUENCES: return true;
case QUERY_LIMIT_ROWS: return true;
- case QUERY_SKIP_ROWS: return false;
+ case QUERY_SKIP_ROWS: return true;
default:
// All other features are not supported by default
return false;