mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 14:03:17 +00:00
Fix passing parameters LIMIT/OFFSET to sql query in the findAll()
This commit is contained in:
@@ -28,6 +28,7 @@ import org.dspace.workflow.WorkflowItem;
|
|||||||
import org.dspace.xmlworkflow.storedcomponents.CollectionRole;
|
import org.dspace.xmlworkflow.storedcomponents.CollectionRole;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@@ -294,31 +295,48 @@ public class Collection extends DSpaceObject
|
|||||||
* @return the collections in the system
|
* @return the collections in the system
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public static Collection[] findAll(Context context) throws SQLException {
|
public static Collection[] findAll(Context context) throws SQLException
|
||||||
|
{
|
||||||
TableRowIterator tri = null;
|
TableRowIterator tri = null;
|
||||||
try {
|
List<Collection> collections = null;
|
||||||
String query = "SELECT c.* FROM collection c " +
|
List<Serializable> params = new ArrayList<Serializable>();
|
||||||
"LEFT JOIN metadatavalue m on (m.resource_id = c.collection_id and m.resource_type_id = ? and m.metadata_field_id = ?) ";
|
StringBuffer query = new StringBuffer(
|
||||||
if(DatabaseManager.isOracle()){
|
"SELECT c.*" +
|
||||||
query += " ORDER BY cast(m.text_value as varchar2(128))";
|
"FROM collection c " +
|
||||||
}else{
|
"LEFT JOIN metadatavalue m ON (" +
|
||||||
query += " ORDER BY m.text_value";
|
"m.resource_id = c.collection_id AND " +
|
||||||
}
|
"m.resource_type_id = ? AND " +
|
||||||
|
"m.metadata_field_id = ?" +
|
||||||
tri = DatabaseManager.query(context,
|
")"
|
||||||
query,
|
|
||||||
Constants.COLLECTION,
|
|
||||||
MetadataField.findByElement(context, MetadataSchema.find(context, MetadataSchema.DC_SCHEMA).getSchemaID(), "title", null).getFieldID()
|
|
||||||
);
|
);
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("Find all Collections - ",e);
|
if (DatabaseManager.isOracle())
|
||||||
throw e;
|
{
|
||||||
|
query.append(" ORDER BY cast(m.text_value as varchar2(128))");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
query.append(" ORDER BY m.text_value");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Collection> collections = new ArrayList<Collection>();
|
params.add(Constants.COLLECTION);
|
||||||
|
params.add(
|
||||||
|
MetadataField.findByElement(
|
||||||
|
context,
|
||||||
|
MetadataSchema.find(context, MetadataSchema.DC_SCHEMA).getSchemaID(),
|
||||||
|
"title",
|
||||||
|
null
|
||||||
|
).getFieldID()
|
||||||
|
);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
tri = DatabaseManager.query(
|
||||||
|
context, query.toString(), params.toArray()
|
||||||
|
);
|
||||||
|
|
||||||
|
collections = new ArrayList<Collection>();
|
||||||
|
|
||||||
while (tri.hasNext())
|
while (tri.hasNext())
|
||||||
{
|
{
|
||||||
TableRow row = tri.next();
|
TableRow row = tri.next();
|
||||||
@@ -337,6 +355,11 @@ public class Collection extends DSpaceObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
log.error("Find all Collections - ", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// close the TableRowIterator to free up resources
|
// close the TableRowIterator to free up resources
|
||||||
@@ -363,31 +386,47 @@ public class Collection extends DSpaceObject
|
|||||||
public static Collection[] findAll(Context context, Integer limit, Integer offset) throws SQLException
|
public static Collection[] findAll(Context context, Integer limit, Integer offset) throws SQLException
|
||||||
{
|
{
|
||||||
TableRowIterator tri = null;
|
TableRowIterator tri = null;
|
||||||
try{
|
List<Collection> collections = null;
|
||||||
String query = "SELECT c.* FROM collection c " +
|
List<Serializable> params = new ArrayList<Serializable>();
|
||||||
"LEFT JOIN metadatavalue m on (m.resource_id = c.collection_id and m.resource_type_id = ? and m.metadata_field_id = ?) ";
|
StringBuffer query = new StringBuffer(
|
||||||
|
"SELECT c.*" +
|
||||||
if(DatabaseManager.isOracle()){
|
"FROM collection c " +
|
||||||
query += " ORDER BY cast(m.text_value as varchar2(128))";
|
"LEFT JOIN metadatavalue m ON (" +
|
||||||
}else{
|
"m.resource_id = c.collection_id AND " +
|
||||||
query += " ORDER BY m.text_value";
|
"m.resource_type_id = ? AND " +
|
||||||
}
|
"m.metadata_field_id = ?" +
|
||||||
query += " limit ? offset ?";
|
")"
|
||||||
tri = DatabaseManager.query(context,
|
|
||||||
query,
|
|
||||||
Constants.COLLECTION,
|
|
||||||
MetadataField.findByElement(context, MetadataSchema.find(context, MetadataSchema.DC_SCHEMA).getSchemaID(), "title", null).getFieldID(),
|
|
||||||
limit,
|
|
||||||
offset
|
|
||||||
);
|
);
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("Find all Collections offset/limit - ",e);
|
if (DatabaseManager.isOracle())
|
||||||
throw e;
|
{
|
||||||
|
query.append(" ORDER BY cast(m.text_value as varchar2(128))");
|
||||||
}
|
}
|
||||||
List<Collection> collections = new ArrayList<Collection>();
|
else
|
||||||
|
{
|
||||||
|
query.append(" ORDER BY m.text_value");
|
||||||
|
}
|
||||||
|
|
||||||
|
params.add(Constants.COLLECTION);
|
||||||
|
params.add(
|
||||||
|
MetadataField.findByElement(
|
||||||
|
context,
|
||||||
|
MetadataSchema.find(context, MetadataSchema.DC_SCHEMA).getSchemaID(),
|
||||||
|
"title",
|
||||||
|
null
|
||||||
|
).getFieldID()
|
||||||
|
);
|
||||||
|
|
||||||
|
DatabaseManager.applyOffsetAndLimit(query, params, offset, limit);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
tri = DatabaseManager.query(
|
||||||
|
context, query.toString(), params.toArray()
|
||||||
|
);
|
||||||
|
|
||||||
|
collections = new ArrayList<Collection>();
|
||||||
|
|
||||||
while (tri.hasNext())
|
while (tri.hasNext())
|
||||||
{
|
{
|
||||||
TableRow row = tri.next();
|
TableRow row = tri.next();
|
||||||
@@ -406,6 +445,11 @@ public class Collection extends DSpaceObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
log.error("Find all Collections offset/limit - ", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// close the TableRowIterator to free up resources
|
// close the TableRowIterator to free up resources
|
||||||
|
Reference in New Issue
Block a user