String where = null;
try {
where = this.buildCondition(filters, parameters);
} catch (ContextServiceException e) {
throw new DatabaseQueryException(e);
}
countParameters.addAll(parameters);
if (!where.equals("")) {
query += " WHERE i.in_archive=true AND " + where;
countQuery += " WHERE i.in_archive=true AND " + where;
} else {
query += " WHERE i.in_archive=true";
countQuery += " WHERE i.in_archive=true";
}
query += " ORDER BY i.item_id";
boolean postgres = ! DatabaseManager.isOracle();
if (postgres)
{
query += " OFFSET ? LIMIT ?";
}
else
{
// Oracle
query = "SELECT * FROM (" + query
+ ") WHERE ROWNUM BETWEEN ? AND ?";
length = length + offset;
}
parameters.add(offset);
parameters.add(length);
try {
return new DatabaseQuery(contextService.getContext())
.withCountQuery(countQuery, countParameters)
.withQuery(query)
.withParameters(parameters);
} catch (ContextServiceException e) {
throw new DatabaseQueryException(e);
}
}