con = getPooledCon();
stmt = con.createStatement();
// counting rows
- if (theAdaptor.hasLimit()) {
- rs = executeSql(stmt, countSql.toString());
- if (rs != null) {
- if (rs.next())
- count = rs.getInt(1);
- rs.close();
- //nothing in the table: return null
- if(count<=0){
- freeConnection(con, stmt);
- return null;
- }
- } else {
- theLog.printError("Could not count: " + countSql);
- }
- }
+
+ /** @todo select count(*) should be optimized:
+ * 1. it should take place after select statement because in some
+ * cases it is not necessary anymore.
+ * 2. it is only needed if entitylist needs information about how
+ * many datasets there are overall
+ *
+ * optimization:
+ *
+ * if we manage to have the full information about allData already
+ * with the select statement, then we set it in entitylist, other
+ * wise we fetch it. /rk
+ * */
+
+
// hier select
rs = executeSql(stmt, selectSql.toString());
}
rs.close();
}
- // making entitylist
- if (!(theAdaptor.hasLimit()))
- count = offsetCount;
+
+ // making entitylist infos
+ if (!(theAdaptor.hasLimit())) count = offsetCount;
+
if (theReturnList != null) {
+ // now we decide if we have to know an overall count...
+ count=offsetCount;
+ if (limit > -1 && offset > -1) {
+ if (offsetCount==limit) {
+ rs = executeSql(stmt, countSql.toString());
+ if (rs != null) {
+ if ( rs.next() ) count = rs.getInt(1);
+ rs.close();
+ }
+ else theLog.printError("Could not count: " + countSql);
+ }
+ }
+
theReturnList.setCount(count);
+
theReturnList.setOffset(offset);
theReturnList.setWhere(wc);
theReturnList.setOrder(ob);
if (offset + offsetCount < count) {
theReturnList.setNextBatch(offset + limit);
}
+
+
+
}
} catch (SQLException sqe) {
throwSQLException(sqe, "selectByWhereClause");
return theReturnList;
}
+
/**
* Bastelt aus einer Zeile der Datenbank ein EntityObjekt.
*
* @return Entity Die Entity.
*/
- public Entity makeEntityFromResultSet (ResultSet rs) throws StorageObjectException {
+ private Entity makeEntityFromResultSet (ResultSet rs) throws StorageObjectException {
HashMap theResultHash = new HashMap();
String theResult = null;
int theType;
try {
con = getPooledCon();
} catch (Exception e) {
- throw new StorageObjectException(e.toString());
+ throw new StorageObjectException(e.toString());
}
try {
stmt = con.createStatement();
}
} catch (Exception e) {
theLog.printError("getPopupData: "+e.toString());
- throw new StorageObjectException(e.toString());
+ throw new StorageObjectException(e.toString());
} finally {
freeConnection(con, stmt);
}
}
catch (SQLException e)
{
- theLog.printDebugInfo("Failed: " + (new java.util.Date().getTime()
+ theLog.printDebugInfo("Failed: " + (new java.util.Date().getTime()
- startTime) + "ms. for: "+ sql);
throw e;
}
}
}
-
+
public Connection getPooledCon() throws StorageObjectException {
/* @todo , doublecheck but I'm pretty sure that this is unnecessary. -mh
try{
}
return con;
}
-
+
public void freeConnection (Connection con, Statement stmt)
throws StorageObjectException {
SQLManager.getInstance().closeStatement(stmt);
}
/**
- * Loggt Fehlermeldung mit dem Parameter Message und wirft dannach
+ * Loggt Fehlermeldung mit dem Parameter Message und wirft dannach
* eine StorageObjectException
* @param message Nachricht mit dem Fehler
* @exception StorageObjectException