Fix pagination issues by using offsets

git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@2678 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Graham Triggs
2008-02-14 22:46:41 +00:00
parent e0db2d669a
commit 4829eda0b7
11 changed files with 2351 additions and 2220 deletions

View File

@@ -46,348 +46,370 @@ import java.util.List;
* Read Only operations. If you wish to modify the contents of the browse indices
* or create and destroy index tables you should look at implementations for
* BrowseCreateDAO.
*
*
* If you implement this class, and you wish it to be loaded via the BrowseDAOFactory
* you must supply a constructor of the form:
*
*
* public BrowseDAOImpl(Context context) {}
*
*
* Where Context is the DSpace Context object
*
*
* Where tables are referred to in this class, they can be obtained from the BrowseIndex
* class, which will answer queries given the context of the request on which table
* is the relevant target.
*
*
* @author Richard Jones
*
*/
public interface BrowseDAO
{
// Objects implementing this interface should also include
// a constructor which takes the DSpace Context as an argument
//
// public BrowseDAOImpl(Context context) ...
/**
* This executes a query which will count the number of results for the
* parameters you set.
*
* @return the integer value of the number of results found
* @throws BrowseException
*/
public int doCountQuery() throws BrowseException;
/**
* This executes a query which returns a List object containing String
* values which represent the results of a single value browse (for
* example, the list of all subject headings). This is most
* commonly used with a Distinct browse type.
*
* @return List of Strings representing the single value query results
* @throws BrowseException
*/
public List doValueQuery() throws BrowseException;
/**
* This executes a query which returns a List object containing BrowseItem objects
* represening the results of a full item browse.
*
* @return List of BrowseItem objects
* @throws BrowseException
*/
public List doQuery() throws BrowseException;
/**
* This executes a query which returns the value of the "highest" (max) value
* in the given table's column for the given item id.
*
* @param column the column to interrogate
* @param table the table to query
* @param itemID the item id
* @return String representing the max value in the given column
* @throws BrowseException
*/
public String doMaxQuery(String column, String table, int itemID) throws BrowseException;
/**
* Does the query use the equals comparator when doing less than or greater than
* comparisons. @see setEqualsComparator
*
* Default value is true
*
* @return true if using it, false if not
*/
public boolean useEqualsComparator();
// Objects implementing this interface should also include
// a constructor which takes the DSpace Context as an argument
//
// public BrowseDAOImpl(Context context) ...
/**
* Set whether the query should use an equals comparator when doing less than or
* greater than comparisons. That is, if true then comparisons will be made
* using the equivalent of "<=" and ">=", while if false it will use the
* equivalent of "<" and ">"
*
* @param equalsComparator true to use, false to not.
*/
public void setEqualsComparator(boolean equalsComparator);
/**
* This executes a query which will count the number of results for the
* parameters you set.
*
* @return the integer value of the number of results found
* @throws BrowseException
*/
public int doCountQuery() throws BrowseException;
/**
* Is the sort order ascending or descending?
*
* Default value is true
*
* @return true for ascending, false for descending
*/
public boolean isAscending();
/**
* Set whether the results should be sorted in ascending order (on the given sort column)
* or descending order.
*
* @param ascending true to ascend, false to descend
*/
public void setAscending(boolean ascending);
/**
* Get the database ID of the container object. The container object will be a
* Community or a Collection.
*
* @return the database id of the container, or -1 if none is set
*/
public int getContainerID();
/**
* This executes a query which returns a List object containing String
* values which represent the results of a single value browse (for
* example, the list of all subject headings). This is most
* commonly used with a Distinct browse type.
*
* @return List of Strings representing the single value query results
* @throws BrowseException
*/
public List doValueQuery() throws BrowseException;
/**
* Set the database id of the container object. This should be the id of a
* Community or Collection. This will constrain the results of the browse
* to only items or values within items that appear in the given container.
*
* @param containerID
*/
public void setContainerID(int containerID);
/**
* get the name of the field in which to look for the container id. This is
* principally for use internal to the DAO.
*
* @return the name of the container id field. For example "collection_id" or
* "community_id"
*/
public String getContainerIDField();
/**
* set the name of the field in which to look for the container id.
*
* @param containerIDField the name of the container id field.
* For example "collection_id" or "community_id"
*/
public void setContainerIDField(String containerIDField);
/**
* Get the field in which we will match a focus value from which to start
* the browse. This will either be the "sort_value" field or one of the
* additional sort fields defined by configuration
*
* @return the name of the focus field
*/
public String getJumpToField();
/**
* Set the focus field upon which we will match a value from which to start
* the browse. This will either be the "sort_value" field or one of the
* additional sort fields defined by configuration
*
* param focusField the name of the focus field
*/
public void setJumpToField(String focusField);
/**
* Get the value at which the browse will start. The value supplied here will
* be the top result on the page of results.
*
* @return the value to start browsing on
*/
public String getJumpToValue();
/**
* Set the value upon which to start the browse from. The value supplied here
* will be the top result on the page of results
*
* @param focusValue the value in the focus field on which to start browsing
*/
public void setJumpToValue(String focusValue);
/**
* get the integer number which is the limit of the results that will be returned
* by any query. The default is -1, which means unlimited results.
*
* @return the maximum possible number of results allowed to be returned
*/
public int getLimit();
/**
* Set the limit for how many results should be returned. This is generally
* for use in paging or limiting the number of items be be displayed. The default
* is -1, meaning unlimited results. Note that if the number of results of the
* query is less than this number, the size of the result set will be smaller
* than this limit.
*
* @param limit the maximum number of results to return.
*/
public void setLimit(int limit);
/**
* Get the offset from the first result from which to return results. This
* functionality is present for backwards compatibility, but is ill advised. All
* normal browse operations can be completed without it. The default is -1, which
* means do not offset.
*
* @return the offset
*/
public int getOffset();
/**
* Get the offset from the first result from which to return results. This
* functionality is present for backwards compatibility, but is ill advised. All
* normal browse operations can be completed without it. The default is -1, which
* means do not offset.
*
* @param offset
*/
public void setOffset(int offset);
/**
* Get the database field which will be used to do the sorting of result sets on.
*
* @return the field by which results will be sorted
*/
public String getOrderField();
/**
* Set the database field which will be used to sort result sets on
*
* @param orderField the field by which results will be sorted
*/
public void setOrderField(String orderField);
/**
* Get the array of values that we will be selecting on. The default is
* to select all of the values from a given table
*
* @return an array of values to select on
*/
public String[] getSelectValues();
/**
* Set the array of values to select on. This should be a list of the columns
* available in the target table, or the SQL wildcards. The default is
* single element array with the standard wildcard (*)
*
* @param selectValues the values to select on
*/
public void setSelectValues(String[] selectValues);
/**
* Get the array of fields that we will be counting on.
*
* @return an array of fields to be counted over
*/
public String[] getCountValues();
/**
* Set the array of columns that we will be counting over. In general, the
* wildcard (*) will suffice
*
* @param fields an array of fields to be counted over
*/
public void setCountValues(String[] fields);
/**
* get the name of the table that we are querying
*
* @return the name of the table
*/
public String getTable();
/**
* Set the name of the table to query
*
* @param table the name of the table
*/
public void setTable(String table);
/**
* This executes a query which returns a List object containing BrowseItem objects
* represening the results of a full item browse.
*
* @return List of BrowseItem objects
* @throws BrowseException
*/
public List doQuery() throws BrowseException;
/**
* Set the name of the mapping tables to use for filtering
* @param tableDis the name of the table holding the distinct values
* @param tableMap the name of the table holding the mappings
*/
/**
* This executes a query which returns the value of the "highest" (max) value
* in the given table's column for the given item id.
*
* @param column the column to interrogate
* @param table the table to query
* @param itemID the item id
* @return String representing the max value in the given column
* @throws BrowseException
*/
public String doMaxQuery(String column, String table, int itemID) throws BrowseException;
/**
* This executes a query which returns the offset where the value (or nearest greater
* equivalent) can be found in the specified table ordered by the column.
*
* @param column the column to interrogate
* @param value the item id
* @return the offset into the table
* @throws BrowseException
*/
public int doOffsetQuery(String column, String value) throws BrowseException;
/**
* This executes a query which returns the offset where the value (or nearest greater
* equivalent) can be found in the specified table ordered by the column.
*
* @param column the column to interrogate
* @param value the item id
* @return the offset into the table
* @throws BrowseException
*/
public int doDistinctOffsetQuery(String column, String value) throws BrowseException;
/**
* Does the query use the equals comparator when doing less than or greater than
* comparisons. @see setEqualsComparator
*
* Default value is true
*
* @return true if using it, false if not
*/
public boolean useEqualsComparator();
/**
* Set whether the query should use an equals comparator when doing less than or
* greater than comparisons. That is, if true then comparisons will be made
* using the equivalent of "<=" and ">=", while if false it will use the
* equivalent of "<" and ">"
*
* @param equalsComparator true to use, false to not.
*/
public void setEqualsComparator(boolean equalsComparator);
/**
* Is the sort order ascending or descending?
*
* Default value is true
*
* @return true for ascending, false for descending
*/
public boolean isAscending();
/**
* Set whether the results should be sorted in ascending order (on the given sort column)
* or descending order.
*
* @param ascending true to ascend, false to descend
*/
public void setAscending(boolean ascending);
/**
* Get the database ID of the container object. The container object will be a
* Community or a Collection.
*
* @return the database id of the container, or -1 if none is set
*/
public int getContainerID();
/**
* Set the database id of the container object. This should be the id of a
* Community or Collection. This will constrain the results of the browse
* to only items or values within items that appear in the given container.
*
* @param containerID
*/
public void setContainerID(int containerID);
/**
* get the name of the field in which to look for the container id. This is
* principally for use internal to the DAO.
*
* @return the name of the container id field. For example "collection_id" or
* "community_id"
*/
public String getContainerIDField();
/**
* set the name of the field in which to look for the container id.
*
* @param containerIDField the name of the container id field.
* For example "collection_id" or "community_id"
*/
public void setContainerIDField(String containerIDField);
/**
* Get the field in which we will match a focus value from which to start
* the browse. This will either be the "sort_value" field or one of the
* additional sort fields defined by configuration
*
* @return the name of the focus field
*/
public String getJumpToField();
/**
* Set the focus field upon which we will match a value from which to start
* the browse. This will either be the "sort_value" field or one of the
* additional sort fields defined by configuration
*
* param focusField the name of the focus field
*/
public void setJumpToField(String focusField);
/**
* Get the value at which the browse will start. The value supplied here will
* be the top result on the page of results.
*
* @return the value to start browsing on
*/
public String getJumpToValue();
/**
* Set the value upon which to start the browse from. The value supplied here
* will be the top result on the page of results
*
* @param focusValue the value in the focus field on which to start browsing
*/
public void setJumpToValue(String focusValue);
/**
* get the integer number which is the limit of the results that will be returned
* by any query. The default is -1, which means unlimited results.
*
* @return the maximum possible number of results allowed to be returned
*/
public int getLimit();
/**
* Set the limit for how many results should be returned. This is generally
* for use in paging or limiting the number of items be be displayed. The default
* is -1, meaning unlimited results. Note that if the number of results of the
* query is less than this number, the size of the result set will be smaller
* than this limit.
*
* @param limit the maximum number of results to return.
*/
public void setLimit(int limit);
/**
* Get the offset from the first result from which to return results. This
* functionality is present for backwards compatibility, but is ill advised. All
* normal browse operations can be completed without it. The default is -1, which
* means do not offset.
*
* @return the offset
*/
public int getOffset();
/**
* Get the offset from the first result from which to return results. This
* functionality is present for backwards compatibility, but is ill advised. All
* normal browse operations can be completed without it. The default is -1, which
* means do not offset.
*
* @param offset
*/
public void setOffset(int offset);
/**
* Get the database field which will be used to do the sorting of result sets on.
*
* @return the field by which results will be sorted
*/
public String getOrderField();
/**
* Set the database field which will be used to sort result sets on
*
* @param orderField the field by which results will be sorted
*/
public void setOrderField(String orderField);
/**
* Get the array of values that we will be selecting on. The default is
* to select all of the values from a given table
*
* @return an array of values to select on
*/
public String[] getSelectValues();
/**
* Set the array of values to select on. This should be a list of the columns
* available in the target table, or the SQL wildcards. The default is
* single element array with the standard wildcard (*)
*
* @param selectValues the values to select on
*/
public void setSelectValues(String[] selectValues);
/**
* Get the array of fields that we will be counting on.
*
* @return an array of fields to be counted over
*/
public String[] getCountValues();
/**
* Set the array of columns that we will be counting over. In general, the
* wildcard (*) will suffice
*
* @param fields an array of fields to be counted over
*/
public void setCountValues(String[] fields);
/**
* get the name of the table that we are querying
*
* @return the name of the table
*/
public String getTable();
/**
* Set the name of the table to query
*
* @param table the name of the table
*/
public void setTable(String table);
/**
* Set the name of the mapping tables to use for filtering
* @param tableDis the name of the table holding the distinct values
* @param tableMap the name of the table holding the mappings
*/
public void setFilterMappingTables(String tableDis, String tableMap);
/**
* Get the value which we are constraining all our browse results to contain.
*
* @return the value to which to constrain results
*/
public String getFilterValue();
/**
* Set the value to which all our browse results should be constrained. For
* example, if you are listing all of the publications by a single author
* your value would be the author name.
*
* @param value the value to which to constrain results
*/
public void setFilterValue(String value);
/**
* Sets whether we will treat the filter value as partial (like match), or exact
*
* @param part true if partial, false if exact
*/
public void setFilterValuePartial(boolean part);
/**
* Get the name of the field in which the value to constrain results is
* contained
*
* @return the name of the field
*/
public String getFilterValueField();
/**
* Set he name of the field in which the value to constrain results is
* contained
*
* @param valueField the name of the field
*/
public void setFilterValueField(String valueField);
/**
* Set whether this is a distinct value browse or not
*
* @param bool true if distinct value, false if not
*/
public void setDistinct(boolean bool);
/**
* Is this a distinct value browse?
*
* @return true if distinct, false if not
*/
public boolean isDistinct();
/**
* If we have specified a container id and container field, we must also specify
* a container table. This is the name of the table that maps the item onto
* the distinct value. Since we are in a container, this value will actually be
* the view which allows us to select only items which are within a given container
*
* @param containerTable the name of the container table mapping
*/
public void setContainerTable(String containerTable);
/**
* Get the name of the container table that is being used to map items to distinct
* values when in a container constrained browse
*
* @return the name of the table
*/
public String getContainerTable();
/**
* Get the value which we are constraining all our browse results to contain.
*
* @return the value to which to constrain results
*/
public String getFilterValue();
/**
* Set the value to which all our browse results should be constrained. For
* example, if you are listing all of the publications by a single author
* your value would be the author name.
*
* @param value the value to which to constrain results
*/
public void setFilterValue(String value);
/**
* Sets whether we will treat the filter value as partial (like match), or exact
*
* @param part true if partial, false if exact
*/
public void setFilterValuePartial(boolean part);
/**
* Get the name of the field in which the value to constrain results is
* contained
*
* @return the name of the field
*/
public String getFilterValueField();
/**
* Set he name of the field in which the value to constrain results is
* contained
*
* @param valueField the name of the field
*/
public void setFilterValueField(String valueField);
/**
* Set whether this is a distinct value browse or not
*
* @param bool true if distinct value, false if not
*/
public void setDistinct(boolean bool);
/**
* Is this a distinct value browse?
*
* @return true if distinct, false if not
*/
public boolean isDistinct();
/**
* If we have specified a container id and container field, we must also specify
* a container table. This is the name of the table that maps the item onto
* the distinct value. Since we are in a container, this value will actually be
* the view which allows us to select only items which are within a given container
*
* @param containerTable the name of the container table mapping
*/
public void setContainerTable(String containerTable);
/**
* Get the name of the container table that is being used to map items to distinct
* values when in a container constrained browse
*
* @return the name of the table
*/
public String getContainerTable();
}

View File

@@ -54,89 +54,89 @@ import org.dspace.storage.rdbms.TableRowIterator;
* This class is the Oracle driver class for reading information from the Browse
* tables. It implements the BrowseDAO interface, and also has a constructor of
* the form:
*
*
* BrowseDAOOracle(Context context)
*
*
* As required by BrowseDAOFactory. This class should only ever be loaded by
* that Factory object.
*
*
* @author Graham Triggs
*
*
*/
public class BrowseDAOOracle implements BrowseDAO
{
/** Log4j log */
private static Logger log = Logger.getLogger(BrowseDAOOracle.class);
/** The DSpace context */
private Context context;
/** Database specific set of utils used when prepping the database */
private BrowseDAOUtils utils;
// SQL query related attributes for this class
/** the values to place in the SELECT --- FROM bit */
private String[] selectValues = { "*" };
/** the values to place in the SELECT COUNT(---) bit */
private String[] countValues;
/** table(s) to select from */
private String table = null;
private String tableDis = null;
private String tableMap = null;
/** field to look for focus value in */
private String focusField = null;
/** value to start browse from in focus field */
private String focusValue = null;
/** field to look for value in */
private String valueField = null;
/** value to restrict browse to (e.g. author name) */
private String value = null;
/** exact or partial matching of the value */
private boolean valuePartial = false;
/** the table that defines the mapping for the relevant container */
private String containerTable = null;
/** the name of the field which contains the container id (e.g. collection_id) */
private String containerIDField = null;
/** the database id of the container we are constraining to */
private int containerID = -1;
/** the column that we are sorting results by */
private String orderField = null;
/** whether to sort results ascending or descending */
private boolean ascending = true;
/** the limit of number of results to return */
private int limit = -1;
/** the offset of the start point (avoid using) */
private int offset = -1;
/** the offset of the start point */
private int offset = 0;
/** whether to use the equals comparator in value comparisons */
private boolean equalsComparator = true;
/** whether this is a distinct browse or not */
private boolean distinct = false;
// administrative attributes for this class
/** a cache of the actual query to be executed */
private String querySql = "";
private ArrayList queryParams = new ArrayList();
private String whereClauseOperator = "";
/** whether the query (above) needs to be regenerated */
private boolean rebuildQuery = true;
@@ -144,12 +144,12 @@ public class BrowseDAOOracle implements BrowseDAO
/** flags for what the items represent */
private boolean itemsInArchive = true;
private boolean itemsWithdrawn = false;
public BrowseDAOOracle(Context context)
throws BrowseException
throws BrowseException
{
this.context = context;
// obtain the relevant Utils for this class
utils = BrowseDAOFactory.getUtils(context);
}
@@ -161,19 +161,19 @@ public class BrowseDAOOracle implements BrowseDAO
{
String query = getQuery();
Object[] params = getQueryParams();
if (log.isDebugEnabled())
{
log.debug(LogManager.getHeader(context, "executing_count_query", "query=" + query));
}
TableRowIterator tri = null;
try
{
// now run the query
tri = DatabaseManager.query(context, query, params);
if (tri.hasNext())
{
TableRow row = tri.next();
@@ -205,14 +205,14 @@ public class BrowseDAOOracle implements BrowseDAO
throws BrowseException
{
TableRowIterator tri = null;
try
{
String query = "SELECT MAX(" + column + ") AS max_value FROM " + table + " WHERE item_id=?";
Object[] params = { new Integer(itemID) };
tri = DatabaseManager.query(context, query, params);
TableRow row;
if (tri.hasNext())
{
@@ -237,6 +237,108 @@ public class BrowseDAOOracle implements BrowseDAO
}
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#doOffsetQuery(java.lang.String, java.lang.String, java.lang.String)
*/
public int doOffsetQuery(String column, String value)
throws BrowseException
{
TableRowIterator tri = null;
try
{
List paramsList = new ArrayList();
StringBuffer queryBuf = new StringBuffer();
queryBuf.append("COUNT(").append(column).append(") AS offset ");
buildSelectStatement(queryBuf, paramsList);
queryBuf.append(" WHERE ").append(column).append("<?");
paramsList.add(value);
if (containerTable != null || (value != null && valueField != null && tableDis != null && tableMap != null))
{
queryBuf.append(" AND ").append("mappings.item_id=");
queryBuf.append(table).append(".item_id");
}
tri = DatabaseManager.query(context, queryBuf.toString(), paramsList.toArray());
TableRow row;
if (tri.hasNext())
{
row = tri.next();
return row.getIntColumn("offset");
}
else
{
return 0;
}
}
catch (SQLException e)
{
throw new BrowseException(e);
}
finally
{
if (tri != null)
{
tri.close();
}
}
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#doDistinctOffsetQuery(java.lang.String, java.lang.String, java.lang.String)
*/
public int doDistinctOffsetQuery(String column, String value)
throws BrowseException
{
TableRowIterator tri = null;
try
{
List paramsList = new ArrayList();
StringBuffer queryBuf = new StringBuffer();
queryBuf.append("COUNT(").append(column).append(") AS offset ");
buildSelectStatementDistinct(queryBuf, paramsList);
queryBuf.append(" WHERE ").append(column).append("<?");
paramsList.add(value);
if (containerTable != null && tableMap != null)
{
queryBuf.append(" AND ").append("mappings.distinct_id=");
queryBuf.append(table).append(".id");
}
tri = DatabaseManager.query(context, queryBuf.toString(), paramsList.toArray());
TableRow row;
if (tri.hasNext())
{
row = tri.next();
return row.getIntColumn("offset");
}
else
{
return 0;
}
}
catch (SQLException e)
{
throw new BrowseException(e);
}
finally
{
if (tri != null)
{
tri.close();
}
}
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#doQuery()
*/
@@ -244,18 +346,18 @@ public class BrowseDAOOracle implements BrowseDAO
{
String query = getQuery();
Object[] params = getQueryParams();
if (log.isDebugEnabled())
{
log.debug(LogManager.getHeader(context, "executing_full_query", "query=" + query));
}
TableRowIterator tri = null;
try
{
// now run the query
tri = DatabaseManager.query(context, query, params);
// go over the query results and process
List results = new ArrayList();
while (tri.hasNext())
@@ -266,7 +368,7 @@ public class BrowseDAOOracle implements BrowseDAO
itemsWithdrawn);
results.add(browseItem);
}
return results;
}
catch (SQLException e)
@@ -290,19 +392,19 @@ public class BrowseDAOOracle implements BrowseDAO
{
String query = getQuery();
Object[] params = getQueryParams();
if (log.isDebugEnabled())
{
log.debug(LogManager.getHeader(context, "executing_value_query", "query=" + query));
}
TableRowIterator tri = null;
try
{
// now run the query
tri = DatabaseManager.query(context, query, params);
// go over the query results and process
List results = new ArrayList();
while (tri.hasNext())
@@ -311,7 +413,7 @@ public class BrowseDAOOracle implements BrowseDAO
String stringResult = row.getStringColumn("value");
results.add(stringResult);
}
return results;
}
catch (SQLException e)
@@ -588,12 +690,12 @@ public class BrowseDAOOracle implements BrowseDAO
this.rebuildQuery = true;
}
public void setFilterMappingTables(String tableDis, String tableMap)
{
this.tableDis = tableDis;
this.tableMap = tableMap;
}
/* (non-Javadoc)
@@ -637,14 +739,14 @@ public class BrowseDAOOracle implements BrowseDAO
* Build the query that will be used for a distinct select. This incorporates
* only the parts of the parameters that are actually useful for this type
* of browse
*
*
* @return the query to be executed
* @throws BrowseException
*/
private String buildDistinctQuery(List params) throws BrowseException
{
StringBuffer queryBuf = new StringBuffer();
if (!buildSelectListCount(queryBuf))
{
if (!buildSelectListValues(queryBuf))
@@ -655,36 +757,36 @@ public class BrowseDAOOracle implements BrowseDAO
buildSelectStatementDistinct(queryBuf, params);
buildWhereClauseOpReset();
// assemble the focus clase if we are to have one
// it will look like one of the following, for example
// sort_value <= myvalue
// sort_1 >= myvalue
buildWhereClauseJumpTo(queryBuf, params);
// assemble the where clause out of the two possible value clauses
// and include container support
buildWhereClauseDistinctConstraints(queryBuf, params);
// assemble the order by field
buildOrderBy(queryBuf);
// prepare the LIMIT clause
buildRowLimit(queryBuf, params);
// prepare the limit and offset clauses
buildRowLimitAndOffset(queryBuf, params);
return queryBuf.toString();
}
/**
* Build the query that will be used for a full browse.
*
*
* @return the query to be executed
* @throws BrowseException
*/
private String buildQuery(List params) throws BrowseException
{
StringBuffer queryBuf = new StringBuffer();
if (!buildSelectListCount(queryBuf))
{
if (!buildSelectListValues(queryBuf))
@@ -695,36 +797,33 @@ public class BrowseDAOOracle implements BrowseDAO
buildSelectStatement(queryBuf, params);
buildWhereClauseOpReset();
// assemble the focus clase if we are to have one
// it will look like one of the following, for example
// sort_value <= myvalue
// sort_1 >= myvalue
buildWhereClauseJumpTo(queryBuf, params);
// assemble the value clause if we are to have one
buildWhereClauseFilterValue(queryBuf, params);
// assemble the where clause out of the two possible value clauses
// and include container support
buildWhereClauseFullConstraints(queryBuf, params);
// assemble the order by field
buildOrderBy(queryBuf);
// prepare the LIMIT clause
buildRowLimit(queryBuf, params);
// prepare the OFFSET clause
buildRowOffset(queryBuf, params);
// prepare the limit and offset clauses
buildRowLimitAndOffset(queryBuf, params);
return queryBuf.toString();
}
/**
* Get the clause to perform search result ordering. This will
* return something of the form:
*
*
* <code>
* ORDER BY [order field] (ASC | DESC)
* </code>
@@ -745,48 +844,37 @@ public class BrowseDAOOracle implements BrowseDAO
}
}
}
/**
* Get the limit clause to perform search result truncation. Will return
* something of the form:
*
*
* <code>
* LIMIT [limit]
* </code>
*/
private void buildRowLimit(StringBuffer queryBuf, List params)
private void buildRowLimitAndOffset(StringBuffer queryBuf, List params)
{
// prepare the LIMIT clause
if (limit != -1)
if (limit > 0 || offset > 0)
{
queryBuf.insert(0, "SELECT /*+ FIRST_ROWS(n) */ rec.*, ROWNUM rnum FROM (");
queryBuf.append(") rec WHERE rownum<=? ");
params.add(new Integer(limit));
queryBuf.append(")");
}
}
/**
* Get the offset clause to offset the start point of search results
*
* @return
* @deprecated
*/
private void buildRowOffset(StringBuffer queryBuf, List params)
{
// prepare the OFFSET clause
if (offset != -1)
{
if (limit == -1)
{
queryBuf.insert(0, "SELECT rec.*, ROWNUM rnum FROM (");
queryBuf.append(") rec");
}
if (limit > 0)
{
queryBuf.append("rec WHERE rownum<=? ");
if (offset > 0)
params.add(new Integer(limit + offset));
else
params.add(new Integer(limit));
}
if (offset > -1)
{
queryBuf.insert(0, "SELECT * FROM (");
queryBuf.append(") WHERE rnum>?");
params.add(new Integer(offset));
}
}
@@ -874,14 +962,14 @@ public class BrowseDAOOracle implements BrowseDAO
queryBuf.append(", ").append(tableDis);
}
}
/**
* Build a clause for counting results. Will return something of the form:
*
*
* <code>
* COUNT( [value 1], [value 2] ) AS number
* </code>
*
*
* @return the count clause
*/
private boolean buildSelectListCount(StringBuffer queryBuf)
@@ -897,7 +985,7 @@ public class BrowseDAOOracle implements BrowseDAO
{
queryBuf.append(table).append(".").append(countValues[0]);
}
for (int i = 1; i < countValues.length; i++)
{
queryBuf.append(", ");
@@ -914,18 +1002,18 @@ public class BrowseDAOOracle implements BrowseDAO
queryBuf.append(") AS num");
return true;
}
return false;
}
/**
* Prepare the list of values to be selected on. Will return something of the form:
*
*
* <code>
* [value 1], [value 2]
* </code>
*
*
* @return the select value list
*/
private boolean buildSelectListValues(StringBuffer queryBuf)
@@ -938,17 +1026,17 @@ public class BrowseDAOOracle implements BrowseDAO
queryBuf.append(", ");
queryBuf.append(table).append(".").append(selectValues[i]);
}
return true;
}
return false;
}
/**
* Prepare the select clause using the pre-prepared arguments. This will produce something
* of the form:
*
*
* <code>
* SELECT [arguments] FROM [table]
* </code>
@@ -957,7 +1045,7 @@ public class BrowseDAOOracle implements BrowseDAO
{
if (queryBuf.length() == 0)
throw new BrowseException("No arguments for SELECT statement");
if (table == null || "".equals(table))
throw new BrowseException("No table for SELECT statement");
@@ -980,7 +1068,7 @@ public class BrowseDAOOracle implements BrowseDAO
}
queryBuf.append(" ");
}
/**
* Prepare the select clause using the pre-prepared arguments. This will produce something
* of the form:
@@ -1011,21 +1099,30 @@ public class BrowseDAOOracle implements BrowseDAO
// Then append the table
queryBuf.append(" FROM ");
queryBuf.append(table);
if (containerTable != null && tableMap != null)
{
queryBuf.append(", (SELECT DISTINCT ").append(tableMap).append(".distinct_id ");
queryBuf.append(" FROM ");
buildFocusedSelectTables(queryBuf);
queryBuf.append(" WHERE ");
buildFocusedSelectClauses(queryBuf, params);
queryBuf.append(") mappings");
}
queryBuf.append(" ");
}
/**
* assemble a WHERE clause with the given constraints. This will return something
* of the form:
*
*
* <code>
* WHERE [focus clause] [AND] [value clause] [AND] [container constraint]
* </code>
*
* The container constraint is described in one of either getFullConstraint or
*
* The container constraint is described in one of either getFullConstraint or
* getDistinctConstraint, and the form of that section of the query can be
* found in their documentation.
*
*
* If either of focusClause or valueClause is null, they will be duly omitted from
* the WHERE clause.
*/
@@ -1036,27 +1133,22 @@ public class BrowseDAOOracle implements BrowseDAO
if (containerIDField != null && containerID != -1 && containerTable != null)
{
buildWhereClauseOpInsert(queryBuf);
queryBuf.append(" EXISTS (SELECT 1 FROM ");
buildFocusedSelectTables(queryBuf);
queryBuf.append(" WHERE ");
buildFocusedSelectClauses(queryBuf, params);
queryBuf.append(" AND distinct_id=" + table + ".id) ");
queryBuf.append(" ").append(table).append(".id=mappings.distinct_id ");
}
}
/**
* assemble a WHERE clause with the given constraints. This will return something
* of the form:
*
*
* <code>
* WHERE [focus clause] [AND] [value clause] [AND] [container constraint]
* </code>
*
* The container constraint is described in one of either getFullConstraint or
*
* The container constraint is described in one of either getFullConstraint or
* getDistinctConstraint, and the form of that section of the query can be
* found in their documentation.
*
*
* If either of focusClause or valueClause is null, they will be duly omitted from
* the WHERE clause.
*/
@@ -1077,13 +1169,13 @@ public class BrowseDAOOracle implements BrowseDAO
/**
* Get the clause to get the browse to start from a given focus value.
* Will return something of the form:
*
*
* <code>
* [field] (<[=] | >[=]) '[value]'
* </code>
*
*
* such as:
*
*
* <code>
* sort_value <= 'my text'
* </code>
@@ -1093,7 +1185,7 @@ public class BrowseDAOOracle implements BrowseDAO
// get the operator (<[=] | >[=]) which the focus of the browse will
// be matched using
String focusComparator = getFocusComparator();
// assemble the focus clase if we are to have one
// it will look like one of the following
// - sort_value <= myvalue
@@ -1116,17 +1208,17 @@ public class BrowseDAOOracle implements BrowseDAO
}
}
}
/**
* Return the clause to constrain the browse to a specific value.
* Will return something of the form:
*
*
* <code>
* [field] = '[value]'
* </code>
*
*
* such as:
*
*
* <code>
* sort_value = 'some author'
* </code>
@@ -1148,7 +1240,7 @@ public class BrowseDAOOracle implements BrowseDAO
if (valuePartial)
{
queryBuf.append(" LIKE ? ");
if (valueField.startsWith("sort_"))
{
params.add("%" + utils.truncateSortValue(value) + "%");
@@ -1161,7 +1253,7 @@ public class BrowseDAOOracle implements BrowseDAO
else
{
queryBuf.append("=? ");
if (valueField.startsWith("sort_"))
{
params.add(utils.truncateSortValue(value));
@@ -1170,11 +1262,11 @@ public class BrowseDAOOracle implements BrowseDAO
{
params.add(utils.truncateValue(value));
}
}
}
}
}
}
/**
* Insert an operator into the where clause, and reset to ' AND '
*/
@@ -1192,12 +1284,12 @@ public class BrowseDAOOracle implements BrowseDAO
// Use sneaky trick to insert the WHERE by defining it as the first operator
whereClauseOperator = " WHERE ";
}
/**
* Get the comparator which should be used to compare focus values
* with values in the database. This will return one of the 4 following
* possible values: <, >, <=, >=
*
*
* @return the focus comparator
*/
private String getFocusComparator()
@@ -1208,10 +1300,10 @@ public class BrowseDAOOracle implements BrowseDAO
{
equals = "";
}
// get the comparator for the match of the browsable index value
// the rule is: if the scope has a value, then the comparator is always "="
// if, the order is set to ascending then we want to use
// if, the order is set to ascending then we want to use
// WHERE sort_value > <the value>
// and when the order is descending then we want to use
// WHERE sort_value < <the value>
@@ -1224,14 +1316,14 @@ public class BrowseDAOOracle implements BrowseDAO
{
focusComparator = "<" + equals;
}
return focusComparator;
}
/**
* Return a string representation (the SQL) of the query that would be executed
* using one of doCountQuery, doValueQuery, doMaxQuery or doQuery
*
*
* @return String representation of the query (SQL)
* @throws BrowseException
*/
@@ -1253,10 +1345,10 @@ public class BrowseDAOOracle implements BrowseDAO
}
return querySql;
}
/**
* Return the parameters to be bound to the query
*
*
* @return Object[] query parameters
* @throws BrowseException
*/
@@ -1267,7 +1359,7 @@ public class BrowseDAOOracle implements BrowseDAO
{
getQuery();
}
return queryParams.toArray();
}
}

View File

@@ -54,12 +54,12 @@ import org.dspace.storage.rdbms.TableRowIterator;
* This class is the PostgreSQL driver class for reading information from the
* Browse tables. It implements the BrowseDAO interface, and also has a
* constructor of the form:
*
*
* BrowseDAOPostgres(Context context)
*
*
* As required by BrowseDAOFactory. This class should only ever be loaded by
* that Factory object.
*
*
* @author Richard Jones
* @author Graham Triggs
*/
@@ -67,77 +67,77 @@ public class BrowseDAOPostgres implements BrowseDAO
{
/** Log4j log */
private static Logger log = Logger.getLogger(BrowseDAOPostgres.class);
/** The DSpace context */
private Context context;
/** Database specific set of utils used when prepping the database */
private BrowseDAOUtils utils;
// SQL query related attributes for this class
/** the values to place in the SELECT --- FROM bit */
private String[] selectValues = { "*" };
/** the values to place in the SELECT COUNT(---) bit */
private String[] countValues;
/** table(s) to select from */
private String table = null;
private String tableDis = null;
private String tableMap = null;
/** field to look for focus value in */
private String focusField = null;
/** value to start browse from in focus field */
private String focusValue = null;
/** field to look for value in */
private String valueField = null;
/** value to restrict browse to (e.g. author name) */
private String value = null;
/** exact or partial matching of the value */
private boolean valuePartial = false;
/** the table that defines the mapping for the relevant container */
private String containerTable = null;
/** the name of the field which contains the container id (e.g. collection_id) */
private String containerIDField = null;
/** the database id of the container we are constraining to */
private int containerID = -1;
/** the column that we are sorting results by */
private String orderField = null;
/** whether to sort results ascending or descending */
private boolean ascending = true;
/** the limit of number of results to return */
private int limit = -1;
/** the offset of the start point (avoid using) */
private int offset = -1;
/** the offset of the start point */
private int offset = 0;
/** whether to use the equals comparator in value comparisons */
private boolean equalsComparator = true;
/** whether this is a distinct browse or not */
private boolean distinct = false;
// administrative attributes for this class
/** a cache of the actual query to be executed */
private String querySql = "";
private ArrayList queryParams = new ArrayList();
/** whether the query (above) needs to be regenerated */
private boolean rebuildQuery = true;
private String whereClauseOperator = "";
// FIXME Would be better to join to item table and get the correct values
@@ -146,15 +146,15 @@ public class BrowseDAOPostgres implements BrowseDAO
private boolean itemsWithdrawn = false;
/**
* Required constructor for use by BrowseDAOFactory
*
* Required constructor for use by BrowseDAOFactory
*
* @param context DSpace context
*/
public BrowseDAOPostgres(Context context)
throws BrowseException
throws BrowseException
{
this.context = context;
// obtain the relevant Utils for this class
utils = BrowseDAOFactory.getUtils(context);
}
@@ -167,19 +167,19 @@ public class BrowseDAOPostgres implements BrowseDAO
{
String query = getQuery();
Object[] params = getQueryParams();
if (log.isDebugEnabled())
{
log.debug(LogManager.getHeader(context, "executing_count_query", "query=" + query));
}
TableRowIterator tri = null;
try
{
// now run the query
tri = DatabaseManager.query(context, query, params);
if (tri.hasNext())
{
TableRow row = tri.next();
@@ -203,7 +203,7 @@ public class BrowseDAOPostgres implements BrowseDAO
}
}
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#doMaxQuery(java.lang.String, java.lang.String, int)
*/
@@ -211,14 +211,14 @@ public class BrowseDAOPostgres implements BrowseDAO
throws BrowseException
{
TableRowIterator tri = null;
try
{
String query = "SELECT max(" + column + ") FROM " + table + " WHERE item_id = ?";
Object[] params = { new Integer(itemID) };
tri = DatabaseManager.query(context, query, params);
TableRow row;
if (tri.hasNext())
{
@@ -242,7 +242,109 @@ public class BrowseDAOPostgres implements BrowseDAO
}
}
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#doOffsetQuery(java.lang.String, java.lang.String, java.lang.String)
*/
public int doOffsetQuery(String column, String value)
throws BrowseException
{
TableRowIterator tri = null;
try
{
List paramsList = new ArrayList();
StringBuffer queryBuf = new StringBuffer();
queryBuf.append("COUNT(").append(column).append(") AS offset ");
buildSelectStatement(queryBuf, paramsList);
queryBuf.append(" WHERE ").append(column).append("<?");
paramsList.add(value);
if (containerTable != null || (value != null && valueField != null && tableDis != null && tableMap != null))
{
queryBuf.append(" AND ").append("mappings.item_id=");
queryBuf.append(table).append(".item_id");
}
tri = DatabaseManager.query(context, queryBuf.toString(), paramsList.toArray());
TableRow row;
if (tri.hasNext())
{
row = tri.next();
return (int)row.getLongColumn("offset");
}
else
{
return 0;
}
}
catch (SQLException e)
{
throw new BrowseException(e);
}
finally
{
if (tri != null)
{
tri.close();
}
}
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#doDistinctOffsetQuery(java.lang.String, java.lang.String, java.lang.String)
*/
public int doDistinctOffsetQuery(String column, String value)
throws BrowseException
{
TableRowIterator tri = null;
try
{
List paramsList = new ArrayList();
StringBuffer queryBuf = new StringBuffer();
queryBuf.append("COUNT(").append(column).append(") AS offset ");
buildSelectStatementDistinct(queryBuf, paramsList);
queryBuf.append(" WHERE ").append(column).append("<?");
paramsList.add(value);
if (containerTable != null && tableMap != null)
{
queryBuf.append(" AND ").append("mappings.distinct_id=");
queryBuf.append(table).append(".id");
}
tri = DatabaseManager.query(context, queryBuf.toString(), paramsList.toArray());
TableRow row;
if (tri.hasNext())
{
row = tri.next();
return (int)row.getLongColumn("offset");
}
else
{
return 0;
}
}
catch (SQLException e)
{
throw new BrowseException(e);
}
finally
{
if (tri != null)
{
tri.close();
}
}
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#doQuery()
*/
@@ -251,18 +353,18 @@ public class BrowseDAOPostgres implements BrowseDAO
{
String query = getQuery();
Object[] params = getQueryParams();
if (log.isDebugEnabled())
{
log.debug(LogManager.getHeader(context, "executing_full_query", "query=" + query));
}
TableRowIterator tri = null;
try
{
// now run the query
tri = DatabaseManager.query(context, query, params);
// go over the query results and process
List results = new ArrayList();
while (tri.hasNext())
@@ -273,7 +375,7 @@ public class BrowseDAOPostgres implements BrowseDAO
itemsWithdrawn);
results.add(browseItem);
}
return results;
}
catch (SQLException e)
@@ -289,7 +391,7 @@ public class BrowseDAOPostgres implements BrowseDAO
}
}
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#doValueQuery()
*/
@@ -299,14 +401,14 @@ public class BrowseDAOPostgres implements BrowseDAO
String query = getQuery();
Object[] params = getQueryParams();
log.debug(LogManager.getHeader(context, "executing_value_query", "query=" + query));
TableRowIterator tri = null;
try
{
// now run the query
tri = DatabaseManager.query(context, query, params);
// go over the query results and process
List results = new ArrayList();
while (tri.hasNext())
@@ -315,7 +417,7 @@ public class BrowseDAOPostgres implements BrowseDAO
String stringResult = row.getStringColumn("value");
results.add(stringResult);
}
return results;
}
catch (SQLException e)
@@ -331,7 +433,7 @@ public class BrowseDAOPostgres implements BrowseDAO
}
}
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getContainerID()
*/
@@ -347,7 +449,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return containerIDField;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getContainerTable()
*/
@@ -355,7 +457,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return containerTable;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getCountValues()
*/
@@ -371,7 +473,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return focusField;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getFocusValue()
*/
@@ -379,7 +481,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return focusValue;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getLimit()
*/
@@ -387,7 +489,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return limit;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getOffset()
*/
@@ -395,7 +497,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return offset;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getOrderField()
*/
@@ -403,7 +505,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return orderField;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getSelectValues()
*/
@@ -411,7 +513,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return selectValues;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getTable()
*/
@@ -419,7 +521,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return table;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getValue()
*/
@@ -427,7 +529,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return value;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getValueField()
*/
@@ -435,7 +537,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return valueField;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#isAscending()
*/
@@ -443,7 +545,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
return ascending;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#isDistinct()
*/
@@ -460,7 +562,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.ascending = ascending;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setContainerID(int)
*/
@@ -469,7 +571,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.containerID = containerID;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setContainerIDField(java.lang.String)
*/
@@ -478,7 +580,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.containerIDField = containerIDField;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setContainerTable(java.lang.String)
*/
@@ -505,7 +607,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.distinct = bool;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setEqualsComparator(boolean)
*/
@@ -514,7 +616,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.equalsComparator = equalsComparator;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setFocusField(java.lang.String)
*/
@@ -523,7 +625,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.focusField = focusField;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setFocusValue(java.lang.String)
*/
@@ -532,7 +634,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.focusValue = focusValue;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setLimit(int)
*/
@@ -541,7 +643,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.limit = limit;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setOffset(int)
*/
@@ -550,7 +652,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.offset = offset;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setOrderField(java.lang.String)
*/
@@ -559,7 +661,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.orderField = orderField;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setSelectValues(java.lang.String[])
*/
@@ -568,7 +670,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.selectValues = selectValues;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setTable(java.lang.String)
*/
@@ -597,7 +699,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
this.tableDis = tableDis;
this.tableMap = tableMap;
}
/* (non-Javadoc)
@@ -617,7 +719,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.valuePartial = part;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#setValueField(java.lang.String)
*/
@@ -626,7 +728,7 @@ public class BrowseDAOPostgres implements BrowseDAO
this.valueField = valueField;
this.rebuildQuery = true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#useEqualsComparator()
*/
@@ -636,12 +738,12 @@ public class BrowseDAOPostgres implements BrowseDAO
}
// PRIVATE METHODS
/**
* Build the query that will be used for a distinct select. This incorporates
* only the parts of the parameters that are actually useful for this type
* of browse
*
*
* @return the query to be executed
* @throws BrowseException
*/
@@ -649,7 +751,7 @@ public class BrowseDAOPostgres implements BrowseDAO
throws BrowseException
{
StringBuffer queryBuf = new StringBuffer();
if (!buildSelectListCount(queryBuf))
{
if (!buildSelectListValues(queryBuf))
@@ -660,29 +762,29 @@ public class BrowseDAOPostgres implements BrowseDAO
buildSelectStatementDistinct(queryBuf, params);
buildWhereClauseOpReset();
// assemble the focus clase if we are to have one
// it will look like one of the following, for example
// sort_value <= myvalue
// sort_1 >= myvalue
buildWhereClauseJumpTo(queryBuf, params);
// assemble the where clause out of the two possible value clauses
// and include container support
buildWhereClauseDistinctConstraints(queryBuf, params);
// assemble the order by field
buildOrderBy(queryBuf);
// prepare the LIMIT clause
buildRowLimit(queryBuf, params);
// prepare the limit and offset clauses
buildRowLimitAndOffset(queryBuf, params);
return queryBuf.toString();
}
/**
* Build the query that will be used for a full browse.
*
*
* @return the query to be executed
* @throws BrowseException
*/
@@ -690,7 +792,7 @@ public class BrowseDAOPostgres implements BrowseDAO
throws BrowseException
{
StringBuffer queryBuf = new StringBuffer();
if (!buildSelectListCount(queryBuf))
{
if (!buildSelectListValues(queryBuf))
@@ -701,40 +803,37 @@ public class BrowseDAOPostgres implements BrowseDAO
buildSelectStatement(queryBuf, params);
buildWhereClauseOpReset();
// assemble the focus clase if we are to have one
// it will look like one of the following, for example
// sort_value <= myvalue
// sort_1 >= myvalue
buildWhereClauseJumpTo(queryBuf, params);
// assemble the value clause if we are to have one
buildWhereClauseFilterValue(queryBuf, params);
// assemble the where clause out of the two possible value clauses
// and include container support
buildWhereClauseFullConstraints(queryBuf, params);
// assemble the order by field
buildOrderBy(queryBuf);
// prepare the LIMIT clause
buildRowLimit(queryBuf, params);
// prepare the OFFSET clause
buildRowOffset(queryBuf, params);
// prepare the limit and offset clauses
buildRowLimitAndOffset(queryBuf, params);
return queryBuf.toString();
}
/**
* Get the clause to perform search result ordering. This will
* return something of the form:
*
*
* <code>
* ORDER BY [order field] (ASC | DESC)
* </code>
*
*
* @return the ORDER BY clause
*/
private void buildOrderBy(StringBuffer queryBuf)
@@ -753,41 +852,32 @@ public class BrowseDAOPostgres implements BrowseDAO
}
}
}
/**
* Get the limit clause to perform search result truncation. Will return
* something of the form:
*
*
* <code>
* LIMIT [limit]
* </code>
*
*
* @return the limit clause
*/
private void buildRowLimit(StringBuffer queryBuf, List params)
private void buildRowLimitAndOffset(StringBuffer queryBuf, List params)
{
// prepare the LIMIT clause
if (limit != -1)
if (limit > 0)
{
queryBuf.append(" LIMIT ? ");
params.add(new Integer(limit));
}
}
/**
* Get the offset clause to offset the start point of search results
*
* @return
* @deprecated
*/
private void buildRowOffset(StringBuffer queryBuf, List params)
{
// prepare the OFFSET clause
if (offset != -1)
if (offset > 0)
{
queryBuf.append(" OFFSET ?");
queryBuf.append(" OFFSET ? ");
params.add(new Integer(offset));
}
}
@@ -878,11 +968,11 @@ public class BrowseDAOPostgres implements BrowseDAO
/**
* Build a clause for counting results. Will return something of the form:
*
*
* <code>
* COUNT( [value 1], [value 2] ) AS number
* </code>
*
*
* @return the count clause
*/
private boolean buildSelectListCount(StringBuffer queryBuf)
@@ -915,17 +1005,17 @@ public class BrowseDAOPostgres implements BrowseDAO
queryBuf.append(") AS num");
return true;
}
return false;
}
/**
* Prepare the list of values to be selected on. Will return something of the form:
*
*
* <code>
* [value 1], [value 2]
* </code>
*
*
* @return the select value list
*/
private boolean buildSelectListValues(StringBuffer queryBuf)
@@ -938,21 +1028,21 @@ public class BrowseDAOPostgres implements BrowseDAO
queryBuf.append(", ");
queryBuf.append(table).append(".").append(selectValues[i]);
}
return true;
}
return false;
}
/**
* Prepare the select clause using the pre-prepared arguments. This will produce something
* of the form:
*
*
* <code>
* SELECT [arguments] FROM [table]
* </code>
*
*
* @param queryBuf the string value obtained from distinctClause, countClause or selectValues
* @return the SELECT part of the query
*/
@@ -962,7 +1052,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
throw new BrowseException("No arguments for SELECT statement");
}
if (table == null || "".equals(table))
{
throw new BrowseException("No table for SELECT statement");
@@ -1033,13 +1123,13 @@ public class BrowseDAOPostgres implements BrowseDAO
/**
* Get a sub-query to obtain the ids for a distinct browse within a given
* constraint. This will produce something of the form:
*
*
* <code>
* id IN (SELECT distinct_id FROM [container table] WHERE [container field] = [container id])
* </code>
*
*
* This is for use inside the overall WHERE clause only
*
*
* @return the sub-query
*/
private void buildWhereClauseDistinctConstraints(StringBuffer queryBuf, List params)
@@ -1052,21 +1142,21 @@ public class BrowseDAOPostgres implements BrowseDAO
queryBuf.append(" ").append(table).append(".id=mappings.distinct_id ");
}
}
/**
* Get the clause to get the browse to start from a given focus value.
* Will return something of the form:
*
*
* <code>
* [field] (<[=] | >[=]) '[value]'
* </code>
*
*
* such as:
*
*
* <code>
* sort_value <= 'my text'
* </code>
*
*
* @return the focus clause
*/
private void buildWhereClauseJumpTo(StringBuffer queryBuf, List params)
@@ -1074,7 +1164,7 @@ public class BrowseDAOPostgres implements BrowseDAO
// get the operator (<[=] | >[=]) which the focus of the browse will
// be matched using
String focusComparator = getFocusComparator();
// assemble the focus clase if we are to have one
// it will look like one of the following
// - sort_value <= myvalue
@@ -1097,17 +1187,17 @@ public class BrowseDAOPostgres implements BrowseDAO
}
}
}
/**
* Get a clause to obtain the ids for a full browse within a given
* constraint. This will produce something of the form:
*
*
* <code>
* [container field] = [container id]
* </code>
*
*
* This is for use inside the overall WHERE clause only
*
*
* @return the constraint clause
*/
private void buildWhereClauseFullConstraints(StringBuffer queryBuf, List params)
@@ -1123,21 +1213,21 @@ public class BrowseDAOPostgres implements BrowseDAO
}
}
}
/**
* Return the clause to constrain the browse to a specific value.
* Will return something of the form:
*
*
* <code>
* [field] = '[value]'
* </code>
*
*
* such as:
*
*
* <code>
* sort_value = 'some author'
* </code>
*
*
* @return the value clause
*/
private void buildWhereClauseFilterValue(StringBuffer queryBuf, List params)
@@ -1157,7 +1247,7 @@ public class BrowseDAOPostgres implements BrowseDAO
if (valuePartial)
{
queryBuf.append(" LIKE ? ");
if (valueField.startsWith("sort_"))
{
params.add("%" + utils.truncateSortValue(value) + "%");
@@ -1170,7 +1260,7 @@ public class BrowseDAOPostgres implements BrowseDAO
else
{
queryBuf.append("=? ");
if (valueField.startsWith("sort_"))
{
params.add(utils.truncateSortValue(value));
@@ -1201,12 +1291,12 @@ public class BrowseDAOPostgres implements BrowseDAO
// Use sneaky trick to insert the WHERE by defining it as the first operator
whereClauseOperator = " WHERE ";
}
/**
* Get the comparator which should be used to compare focus values
* with values in the database. This will return one of the 4 following
* possible values: <, >, <=, >=
*
*
* @return the focus comparator
*/
private String getFocusComparator()
@@ -1217,10 +1307,10 @@ public class BrowseDAOPostgres implements BrowseDAO
{
equals = "";
}
// get the comparator for the match of the browsable index value
// the rule is: if the scope has a value, then the comparator is always "="
// if, the order is set to ascending then we want to use
// if, the order is set to ascending then we want to use
// WHERE sort_value > <the value>
// and when the order is descending then we want to use
// WHERE sort_value < <the value>
@@ -1233,10 +1323,10 @@ public class BrowseDAOPostgres implements BrowseDAO
{
focusComparator = "<" + equals;
}
return focusComparator;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseDAO#getQuery()
*/
@@ -1259,10 +1349,10 @@ public class BrowseDAOPostgres implements BrowseDAO
}
return querySql;
}
/**
* Return the parameters to be bound to the query
*
*
* @return Object[] query parameters
* @throws BrowseException
*/
@@ -1273,7 +1363,7 @@ public class BrowseDAOPostgres implements BrowseDAO
{
getQuery();
}
return queryParams.toArray();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -56,7 +56,7 @@ import org.dspace.sort.SortOption;
* The results of a Browse, including all the contextual information about
* the query, as well as the results and associated information to create
* pagable navigation.
*
*
* @author Richard Jones
*/
public class BrowseInfo
@@ -90,55 +90,49 @@ public class BrowseInfo
/** the browse index to which this pertains */
private BrowseIndex browseIndex;
/** the sort option being used */
private SortOption sortOption;
/** is the browse ascending or descending */
private boolean ascending;
/** what level of browse are we in? full and single front pages are 0, single value browse is 1 */
private int level = 0;
/** the value browsed upon */
private String value;
/** is this a "starts_with" browse? */
private boolean startsWith = false;
/** Collection we are constrained to */
private Collection collection;
/** Community we are constrained to */
private Community community;
/** database id of the item at the top of the next page */
private int nextItem = -1;
/** string value of the value at the top of the next page */
private String nextValue;
/** database id of the item at the top of the previous page */
private int prevItem = -1;
/** string value of the value at the top of the previous page */
private String prevValue;
/** offset of the item at the top of the next page */
private int nextOffset = -1;
/** offset of the item at the top of the previous page */
private int prevOffset = -1;
/** the value upon which we are focussing */
private String focus;
/** number of resutls to display per page */
private int resultsPerPage = -1;
/** database id of the item upon which we are focussing */
private int focusItem = -1;
/** number of metadata elements to display before truncating using "et al" */
private int etAl = -1;
/**
* Constructor
*
*
* @param results
* A List of Browse results
* @param overallPosition
@@ -168,17 +162,17 @@ public class BrowseInfo
{
return etAl;
}
/**
* set the number of metadata fields at which to truncate with "et al"
*
*
* @param etAl
*/
public void setEtAl(int etAl)
{
this.etAl = etAl;
}
/**
* @return Returns the focusItem.
*/
@@ -194,11 +188,11 @@ public class BrowseInfo
{
this.focusItem = focusItem;
}
/**
* Does this browse have an item focus (as opposed to one of: no focus,
* Does this browse have an item focus (as opposed to one of: no focus,
* a value focus)
*
*
* @return true if item focus, false if not
*/
public boolean hasItemFocus()
@@ -209,7 +203,7 @@ public class BrowseInfo
}
return true;
}
/**
* @return Returns the resultsPerPage.
*/
@@ -217,7 +211,7 @@ public class BrowseInfo
{
return resultsPerPage;
}
/**
* @param resultsPerPage The resultsPerPage to set.
*/
@@ -228,7 +222,7 @@ public class BrowseInfo
/**
* Is there a value associated with this browse
*
*
* @return true if a value, false if not
*/
public boolean hasValue()
@@ -239,10 +233,10 @@ public class BrowseInfo
}
return false;
}
/**
* Are there results for this browse, or was the result set empty?
*
*
* @return true if results, false if not
*/
public boolean hasResults()
@@ -253,7 +247,7 @@ public class BrowseInfo
}
return false;
}
/**
* @param focus the value to focus the browse around
*/
@@ -261,7 +255,7 @@ public class BrowseInfo
{
this.focus = focus;
}
/**
* @return the value to focus the browse around
*/
@@ -269,12 +263,12 @@ public class BrowseInfo
{
return this.focus;
}
/**
* Set the DSpaceObject that is the container for this browse. If this
* is not of type Collection or Community, this method will throw an
* exception
*
*
* @param dso the container object; a Community or Collection
* @throws BrowseException
*/
@@ -294,11 +288,11 @@ public class BrowseInfo
throw new BrowseException("The container must be a community or a collection");
}
}
/**
* Obtain a DSpaceObject that represents the container object. This will be
* a Community or a Collection
*
*
* @return A DSpaceObject representing a Community or a Collection
*/
public DSpaceObject getBrowseContainer()
@@ -313,7 +307,7 @@ public class BrowseInfo
}
return null;
}
/**
* @param level the browse level
*/
@@ -321,7 +315,7 @@ public class BrowseInfo
{
this.level = level;
}
/**
* @return the browse level
*/
@@ -329,39 +323,23 @@ public class BrowseInfo
{
return this.level;
}
/**
* @param id the database id of the item at the top of the next page
*/
public void setNextItem(int id)
public void setNextOffset(int offset)
{
this.nextItem = id;
this.nextOffset = offset;
}
/**
* @return the database id of the item at the top of the next page
*/
public int getNextItem()
public int getNextOffset()
{
return this.nextItem;
return this.nextOffset;
}
/**
* @param value the string value of the value at the top of the next page
*/
public void setNextValue(String value)
{
this.nextValue = value;
}
/**
* @return the string value of the value at the top of the next page
*/
public String getNextValue()
{
return this.nextValue;
}
/**
* @return Returns the ascending.
*/
@@ -397,33 +375,17 @@ public class BrowseInfo
/**
* @return Returns the prevItem.
*/
public int getPrevItem()
public int getPrevOffset()
{
return prevItem;
return prevOffset > -1 ? prevOffset : 0;
}
/**
* @param prevItem The prevItem to set.
*/
public void setPrevItem(int prevItem)
public void setPrevOffset(int prevOffset)
{
this.prevItem = prevItem;
}
/**
* @return Returns the prevValue.
*/
public String getPrevValue()
{
return prevValue;
}
/**
* @param prevValue The prevValue to set.
*/
public void setPrevValue(String prevValue)
{
this.prevValue = prevValue;
this.prevOffset = prevOffset;
}
/**
@@ -478,7 +440,7 @@ public class BrowseInfo
* is this a top level (0) browse? Examples of this are a full item
* browse or a single browse. Other browse types are considered
* second level (1)
*
*
* @return true if top level, false if not
*/
public boolean isTopLevel()
@@ -489,11 +451,11 @@ public class BrowseInfo
}
return false;
}
/**
* Is this a second level (1) browse? Examples of this are a single
* value browse (e.g. all items by a given author)
*
*
* @return true if second level, false if not
*/
public boolean isSecondLevel()
@@ -504,12 +466,12 @@ public class BrowseInfo
}
return false;
}
/**
* The results of the Browse. Each member of the list is either a String
* (for the authors browse) or an {@link org.dspace.content.Item}(for the
* other browses).
*
*
* @return Result list. This list cannot be modified.
*/
public List getResults()
@@ -519,7 +481,7 @@ public class BrowseInfo
/**
* Return the results of the Browse as a String array.
*
*
* @return The results of the Browse as a String array.
*/
public String[] getStringResults()
@@ -535,10 +497,10 @@ public class BrowseInfo
{
return new Item[0];
}
/**
* Return the results of the Browse as an Item array.
*
*
* @return The results of the Browse as an Item array.
*/
public Item[] getItemResults(Context context)
@@ -562,17 +524,17 @@ public class BrowseInfo
/**
* Return the results of the Browse as a BrowseItem array
*
*
* @return the results of the browse as a BrowseItem array
*/
public BrowseItem[] getBrowseItemResults()
{
return (BrowseItem[]) results.toArray(new BrowseItem[results.size()]);
}
/**
* Return the number of results.
*
*
* @return The number of results.
*/
public int getResultCount()
@@ -583,7 +545,7 @@ public class BrowseInfo
/**
* Return the position of the results in index being browsed. This is 0 for
* the start of the index.
*
*
* @return The position of the results in index being browsed.
*/
public int getOverallPosition()
@@ -593,7 +555,7 @@ public class BrowseInfo
/**
* Return the total number of items in the index.
*
*
* @return The total number of items in the index.
*/
public int getTotal()
@@ -603,7 +565,7 @@ public class BrowseInfo
/**
* Return the position of the requested item or value in the set of results.
*
*
* @return The position of the requested item or value in the set of results
*/
public int getOffset()
@@ -613,7 +575,7 @@ public class BrowseInfo
/**
* True if there are no previous results from the browse.
*
*
* @return True if there are no previous results from the browse
*/
public boolean isFirst()
@@ -623,7 +585,7 @@ public class BrowseInfo
/**
* True if these are the last results from the browse.
*
*
* @return True if these are the last results from the browse
*/
public boolean isLast()
@@ -646,10 +608,10 @@ public class BrowseInfo
{
this.cached = cached;
}
/**
* are we browsing within a Community container?
*
*
* @return true if in community, false if not
*/
public boolean inCommunity()
@@ -660,10 +622,10 @@ public class BrowseInfo
}
return false;
}
/**
* are we browsing within a Collection container
*
*
* @return true if in collection, false if not
*/
public boolean inCollection()
@@ -674,46 +636,38 @@ public class BrowseInfo
}
return false;
}
/**
* Are there further results for the browse that haven't been returned yet?
*
*
* @return true if next page, false if not
*/
public boolean hasNextPage()
{
if (!"".equals(nextValue) && (nextValue != null))
{
return true;
}
if (nextItem != -1)
if (nextOffset > -1)
{
return true;
}
return false;
}
/**
* Are there results prior to these that haven't been returned here?
*
*
* @return true if previous page, false if not
*/
public boolean hasPrevPage()
{
if (!"".equals(prevValue) && (prevValue != null))
{
return true;
}
if (prevItem != -1)
if (offset > 0)
{
return true;
}
return false;
}
/**
* Does this browse have a focus?
*
*
* @return true if focus, false if not
*/
public boolean hasFocus()
@@ -724,29 +678,29 @@ public class BrowseInfo
}
return true;
}
/**
* Get an integer representing the number within the total set of results which
* marks the position of the first result in the current sub-set
*
*
* @return the start point of the browse page
*/
public int getStart()
{
return overallPosition + 1;
}
/**
* Get an integer representing the number within the total set of results which
* marks the poisition of the last result in the current sub-set
*
*
* @return the end point of the browse page
*/
public int getFinish()
{
return overallPosition + results.size();
}
/**
* Utility method for obtaining a string representation of the browse. This is
* useful only for debug
@@ -756,23 +710,23 @@ public class BrowseInfo
try
{
StringBuffer sb = new StringBuffer();
// calculate the range for display
String from = Integer.toString(overallPosition + 1);
String to = Integer.toString(overallPosition + results.size());
String of = Integer.toString(total);
// report on the positional information of the browse
sb.append("BrowseInfo String Representation: ");
sb.append("Browsing " + from + " to " + to + " of " + of + " ");
// insert the information about which index
sb.append("in index: " + browseIndex.getName() +
" (data type: " + browseIndex.getDataType() +
sb.append("in index: " + browseIndex.getName() +
" (data type: " + browseIndex.getDataType() +
", display type: " + browseIndex.getDisplayType() + ") ");
sb.append("||");
// report on the browse scope container
String container = "all of DSpace";
DSpaceObject theContainer = null;
@@ -786,19 +740,19 @@ public class BrowseInfo
container = "community";
theContainer = this.community;
}
String containerID = "no id available/necessary";
if (theContainer != null)
{
containerID = Integer.toString(theContainer.getID()) + " (" + theContainer.getHandle() + ")";
}
sb.append("Browsing in " + container + ": " + containerID);
sb.append("||");
// load the item list display configuration
ItemListConfig config = new ItemListConfig();
// some information about the columns to be displayed
if (browseIndex.isItemIndex())
{
@@ -812,12 +766,12 @@ public class BrowseInfo
String[] meta = config.getMetadata(k);
sb.append(meta[0] + "." + meta[1] + "." + meta[2]);
}
if (value != null)
{
sb.append(" on value: " + value);
}
if (isStartsWith())
{
sb.append(" sort column starting with: " + focus);
@@ -839,15 +793,15 @@ public class BrowseInfo
sb.append(" sort column focus: " + focus);
}
}
sb.append("||");
// some information about how the data is sorted
String direction = (ascending ? "ASC" : "DESC");
sb.append("Sorting by: " + sortOption.getMetadata() + " " + direction +
sb.append("Sorting by: " + sortOption.getMetadata() + " " + direction +
" (option " + Integer.toString(sortOption.getNumber()) + ")");
sb.append("||");
// output the results
if (browseIndex.isMetadataIndex() && !isSecondLevel())
{
@@ -857,47 +811,33 @@ public class BrowseInfo
{
sb.append(fullListingString(config));
}
sb.append("||");
// tell us what the next and previous values are going to be
sb.append("Top of next page: ");
if (hasNextPage())
{
if (browseIndex.isMetadataIndex() && !isSecondLevel())
{
sb.append(this.nextValue);
}
else if (browseIndex.isItemIndex() || isSecondLevel())
{
sb.append("Item ID: " + Integer.toString(this.nextItem));
}
sb.append("offset: " + Integer.toString(this.nextOffset));
}
else
{
sb.append("n/a");
}
sb.append(";");
sb.append("Top of previous page: ");
if (hasPrevPage())
{
if (browseIndex.isMetadataIndex() && !isSecondLevel())
{
sb.append(this.prevValue);
}
else if (browseIndex.isItemIndex() || isSecondLevel())
{
sb.append("Item ID: " + Integer.toString(this.prevItem));
}
sb.append("offset: " + Integer.toString(this.prevOffset));
}
else
{
sb.append("n/a");
}
sb.append("||");
return sb.toString();
}
catch (SQLException e)
@@ -909,11 +849,11 @@ public class BrowseInfo
return e.getMessage();
}
}
/**
* A utility method for generating a string to represent a single item's
* entry in the browse
*
*
* @param config
* @return
* @throws SQLException
@@ -923,7 +863,7 @@ public class BrowseInfo
{
// report on all the results contained herein
StringBuffer sb = new StringBuffer();
Iterator itr = results.iterator();
while (itr.hasNext())
{
@@ -934,7 +874,7 @@ public class BrowseInfo
break;
}
sb.append("{{Item ID: " + Integer.toString(bi.getID()) + " :: ");
for (int j = 1; j <= config.numCols(); j++)
{
String[] md = config.getMetadata(j);
@@ -963,23 +903,23 @@ public class BrowseInfo
String metadata = "[" + md[0] + "." + md[1] + "." + md[2] + ":" + value.toString() + "]";
sb.append(metadata);
}
sb.append("}}");
}
return sb.toString();
}
/**
* A utility method for representing a single value in the browse
*
*
* @return
*/
private String valueListingString()
{
// report on all the results contained herein
StringBuffer sb = new StringBuffer();
Iterator itr = results.iterator();
while (itr.hasNext())
{
@@ -991,7 +931,7 @@ public class BrowseInfo
}
sb.append("{{Value: " + theValue + "}}");
}
return sb.toString();
}
}

View File

@@ -1,6 +1,6 @@
/*
* BrowserScope.java
*
*
* Copyright (c) 2002-2007, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
@@ -47,7 +47,7 @@ import org.apache.log4j.Logger;
* A class which represents the initial request to the browse system.
* When passed into the BrowseEngine, this will cause the creation
* of a BrowseInfo object
*
*
* @author Richard Jones
*
*/
@@ -56,166 +56,170 @@ public class BrowserScope
/** the logger for this class */
private static Logger log = Logger.getLogger(BrowserScope.class);
/** the DSpace context */
private Context context;
/** the current browse index */
private BrowseIndex browseIndex;
/** the order in which to display results */
private String order;
/** the field upon which to sort */
private int sortBy;
/** the value to restrict the browse to */
private String filterValue;
/** the DSpace context */
private Context context;
/** the current browse index */
private BrowseIndex browseIndex;
/** the order in which to display results */
private String order;
/** the field upon which to sort */
private int sortBy;
/** the value to restrict the browse to */
private String filterValue;
/** exact or partial matching of the value */
private boolean filterValuePartial = false;
/** the language of the value to restrict the browse to */
private String filterValueLang;
/** the item id focus of the browse */
private int jumpItemId = -1;
/** the string value to start with */
private String startsWith;
/** the number of results per page to display */
private int resultsPerPage = 20;
/** the Collection to which to restrict */
private Collection collection;
/** the Community to which to restrict */
private Community community;
/** the sort option being used */
private SortOption sortOption;
/** the value upon which to focus */
private String jumpValue;
/** the item id focus of the browse */
private int jumpItemId = -1;
/** the string value to start with */
private String startsWith;
/** the number of results per page to display */
private int resultsPerPage = 20;
/** the Collection to which to restrict */
private Collection collection;
/** the Community to which to restrict */
private Community community;
/** the sort option being used */
private SortOption sortOption;
/** the value upon which to focus */
private String jumpValue;
/** the language of the value upon which to focus */
private String jumpValueLang;
/** the browse level */
private int level = 0;
/** the number of authors to display in the results */
private int etAl = 0;
/**
* Construct a new BrowserScope using the given Context
*
* @param context the DSpace Context
*/
public BrowserScope(Context context)
{
this.context = context;
}
/** the browse level */
private int level = 0;
/**
/** the number of authors to display in the results */
private int etAl = 0;
/** the number of items to offset into the result ie. 0 = 1st record */
private int offset = 0;
/**
* Construct a new BrowserScope using the given Context
*
* @param context the DSpace Context
*/
public BrowserScope(Context context)
{
this.context = context;
}
/**
* Set the DSpaceObject that is the container for this browse. If this
* is not of type Collection or Community, this method will throw an
* exception
*
* @param dso the container object; a Community or Collection
*
* @param dso the container object; a Community or Collection
* @throws BrowseException
*/
public void setBrowseContainer(DSpaceObject dso)
throws BrowseException
{
if (dso instanceof Collection)
{
this.collection = (Collection) dso;
}
else if (dso instanceof Community)
{
this.community = (Community) dso;
}
else
{
throw new BrowseException("The container must be a community or a collection");
}
}
/**
public void setBrowseContainer(DSpaceObject dso)
throws BrowseException
{
if (dso instanceof Collection)
{
this.collection = (Collection) dso;
}
else if (dso instanceof Community)
{
this.community = (Community) dso;
}
else
{
throw new BrowseException("The container must be a community or a collection");
}
}
/**
* Obtain a DSpaceObject that represents the container object. This will be
* a Community or a Collection
*
* @return A DSpaceObject representing a Community or a Collection
*
* @return A DSpaceObject representing a Community or a Collection
*/
public DSpaceObject getBrowseContainer()
{
if (this.collection != null)
{
return this.collection;
}
if (this.community != null)
{
return this.community;
}
return null;
}
/**
* @param level the browse level
*/
public void setBrowseLevel(int level)
{
this.level = level;
}
/**
* @return the browse level
*/
public int getBrowseLevel()
{
return this.level;
}
/**
* @return true if top level browse, false if not
*/
public boolean isTopLevel()
{
if (this.level == 0)
{
return true;
}
return false;
}
/**
* @return true if second level browse, false if not
*/
public boolean isSecondLevel()
{
if (this.level == 1)
{
return true;
}
return false;
}
/**
* @return Returns the browseIndex.
*/
public BrowseIndex getBrowseIndex()
{
return browseIndex;
}
public DSpaceObject getBrowseContainer()
{
if (this.collection != null)
{
return this.collection;
}
if (this.community != null)
{
return this.community;
}
return null;
}
/**
* @param browseIndex The browseIndex to set.
*/
public void setBrowseIndex(BrowseIndex browseIndex)
throws BrowseException
{
/**
* @param level the browse level
*/
public void setBrowseLevel(int level)
{
this.level = level;
}
/**
* @return the browse level
*/
public int getBrowseLevel()
{
return this.level;
}
/**
* @return true if top level browse, false if not
*/
public boolean isTopLevel()
{
if (this.level == 0)
{
return true;
}
return false;
}
/**
* @return true if second level browse, false if not
*/
public boolean isSecondLevel()
{
if (this.level == 1)
{
return true;
}
return false;
}
/**
* @return Returns the browseIndex.
*/
public BrowseIndex getBrowseIndex()
{
return browseIndex;
}
/**
* @param browseIndex The browseIndex to set.
*/
public void setBrowseIndex(BrowseIndex browseIndex)
throws BrowseException
{
this.browseIndex = browseIndex;
}
}
/**
* @return Returns the author limit.
@@ -233,94 +237,94 @@ public class BrowserScope
this.etAl = etAl;
}
/**
* @return Returns the collection.
*/
public Collection getCollection()
{
return collection;
}
/**
* @return Returns the collection.
*/
public Collection getCollection()
{
return collection;
}
/**
* @param collection The collection to set.
*/
public void setCollection(Collection collection)
{
this.collection = collection;
}
/**
* @param collection The collection to set.
*/
public void setCollection(Collection collection)
{
this.collection = collection;
}
/**
* @return Returns the community.
*/
public Community getCommunity()
{
return community;
}
/**
* @return Returns the community.
*/
public Community getCommunity()
{
return community;
}
/**
* @param community The community to set.
*/
public void setCommunity(Community community)
{
this.community = community;
}
/**
* @param community The community to set.
*/
public void setCommunity(Community community)
{
this.community = community;
}
/**
* @return Returns the context.
*/
public Context getContext()
{
return context;
}
/**
* @return Returns the context.
*/
public Context getContext()
{
return context;
}
/**
* @param context The context to set.
*/
public void setContext(Context context)
{
this.context = context;
}
/**
* @param context The context to set.
*/
public void setContext(Context context)
{
this.context = context;
}
/**
* @return Returns the focus.
*/
public int getJumpToItem()
{
return jumpItemId;
}
/**
* @return Returns the focus.
*/
public int getJumpToItem()
{
return jumpItemId;
}
/**
* @param itemId The focus to set.
*/
public void setJumpToItem(int itemId)
{
this.jumpItemId = itemId;
}
/**
* @param itemId The focus to set.
*/
public void setJumpToItem(int itemId)
{
this.jumpItemId = itemId;
}
/**
* @return the value to focus on
*/
public String getJumpToValue()
{
return jumpValue;
}
/**
* @param value the value to focus on
*/
public void setJumpToValue(String value)
{
this.jumpValue = value;
}
/**
* @return the value to focus on
*/
public String getJumpToValue()
{
return jumpValue;
}
/**
* @param value the value to focus on
*/
public void setJumpToValue(String value)
{
this.jumpValue = value;
}
/**
* @return the language of the value to focus on
*/
public String setJumpToValueLang()
public String getJumpToValueLang()
{
return jumpValueLang;
}
/**
* @param valueLang the language of the value to focus on
*/
@@ -328,12 +332,12 @@ public class BrowserScope
{
this.jumpValueLang = valueLang;
}
/**
* @return Returns the order.
*/
public String getOrder()
{
/**
* @return Returns the order.
*/
public String getOrder()
{
if (order != null)
return order;
@@ -344,11 +348,11 @@ public class BrowserScope
return SortOption.ASCENDING;
}
/**
* @param order The order to set.
*/
public void setOrder(String order)
{
/**
* @param order The order to set.
*/
public void setOrder(String order)
{
if (order == null)
{
this.order = null;
@@ -363,49 +367,65 @@ public class BrowserScope
}
}
/**
* @return Returns the resultsPerPage.
*/
public int getResultsPerPage()
{
return resultsPerPage;
}
/**
* @return Returns the resultsPerPage.
*/
public int getResultsPerPage()
{
return resultsPerPage;
}
/**
* @param resultsPerPage The resultsPerPage to set.
*/
public void setResultsPerPage(int resultsPerPage)
{
if (resultsPerPage > -1)
this.resultsPerPage = resultsPerPage;
}
/**
* @param resultsPerPage The resultsPerPage to set.
*/
public void setResultsPerPage(int resultsPerPage)
{
if (resultsPerPage > -1)
this.resultsPerPage = resultsPerPage;
}
/**
* @return Returns the sortBy.
*/
public int getSortBy()
{
return sortBy;
}
/**
* @return Returns the sortBy.
*/
public int getSortBy()
{
return sortBy;
}
/**
* @param sortBy The sortBy to set.
*/
public void setSortBy(int sortBy)
throws BrowseException
{
/**
* @param sortBy The sortBy to set.
*/
public void setSortBy(int sortBy)
throws BrowseException
{
this.sortBy = sortBy;
}
}
/**
* Obtain the sort option
*
* @return the sort option
* @throws BrowseException
*/
public SortOption getSortOption()
throws BrowseException
{
/**
* @return returns the offset for the browse
*/
public int getOffset()
{
return offset;
}
/**
* @param offset the offset to use for this scope
*/
public void setOffset(int offset)
{
this.offset = offset;
}
/**
* Obtain the sort option
*
* @return the sort option
* @throws BrowseException
*/
public SortOption getSortOption()
throws BrowseException
{
try
{
// If a sortOption hasn't been set, work out the default
@@ -460,36 +480,36 @@ public class BrowserScope
throw new BrowseException("Error in SortOptions", se);
}
}
/**
* @return Returns the startsWith.
*/
public String getStartsWith()
{
return startsWith;
}
/**
* @param startsWith The startsWith to set.
*/
public void setStartsWith(String startsWith)
{
this.startsWith = startsWith;
}
/**
* @return Returns the startsWith.
*/
public String getStartsWith()
{
return startsWith;
}
/**
* Used for second-level item browses,
* to only display items that match the value
* @return Returns the value.
*/
public String getFilterValue()
{
return filterValue;
}
/**
* @param startsWith The startsWith to set.
*/
public void setStartsWith(String startsWith)
{
this.startsWith = startsWith;
}
/**
* Used for second-level item browses,
* to only display items that match the value
* to only display items that match the value
* @return Returns the value.
*/
public String getFilterValue()
{
return filterValue;
}
/**
* Used for second-level item browses,
* to only display items that match the value
* @param value The value to set.
*/
public void setFilterValue(String value)
@@ -530,40 +550,40 @@ public class BrowserScope
{
this.filterValueLang = lang;
}
/**
* @return true if in community, false if not
*/
public boolean inCommunity()
{
if (this.community != null)
{
return true;
}
return false;
}
/**
* @return true if in collection, false if not
*/
public boolean inCollection()
{
if (this.collection != null)
{
return true;
}
return false;
}
/**
* @return true if ascending, false if not - or not set
*/
public boolean isAscending()
{
if (SortOption.ASCENDING.equalsIgnoreCase(order))
{
return true;
}
/**
* @return true if in community, false if not
*/
public boolean inCommunity()
{
if (this.community != null)
{
return true;
}
return false;
}
/**
* @return true if in collection, false if not
*/
public boolean inCollection()
{
if (this.collection != null)
{
return true;
}
return false;
}
/**
* @return true if ascending, false if not - or not set
*/
public boolean isAscending()
{
if (SortOption.ASCENDING.equalsIgnoreCase(order))
{
return true;
}
if (SortOption.DESCENDING.equalsIgnoreCase(order))
{
@@ -576,53 +596,53 @@ public class BrowserScope
return false;
return true;
}
/**
* @return true if has value, false if not
*/
public boolean hasFilterValue()
{
if (filterValue == null || "".equals(filterValue))
{
return false;
}
return true;
}
/**
* @return true if has item focus, false if not
*/
public boolean hasJumpToItem()
{
if (jumpItemId == -1)
{
return false;
}
return true;
}
/**
* @return true if has value focus, false if not
*/
public boolean hasJumpToValue()
{
if (this.jumpValue != null)
{
return true;
}
return false;
}
/**
* @return true if has starts with value, false if not
*/
public boolean hasStartsWith()
{
if (this.startsWith != null)
{
return true;
}
return false;
}
}
/**
* @return true if has value, false if not
*/
public boolean hasFilterValue()
{
if (filterValue == null || "".equals(filterValue))
{
return false;
}
return true;
}
/**
* @return true if has item focus, false if not
*/
public boolean hasJumpToItem()
{
if (jumpItemId == -1)
{
return false;
}
return true;
}
/**
* @return true if has value focus, false if not
*/
public boolean hasJumpToValue()
{
if (this.jumpValue != null)
{
return true;
}
return false;
}
/**
* @return true if has starts with value, false if not
*/
public boolean hasStartsWith()
{
if (this.startsWith != null)
{
return true;
}
return false;
}
}