* @see org.dspace.browse.BrowseCreateDAO#getDistinctID(java.lang.String, java.lang.String, java.lang.String)
*/
public int getDistinctID(String table, String value, String authority, String sortValue)
throws BrowseException
{
TableRowIterator tri = null;
if (log.isDebugEnabled())
{
log.debug("getDistinctID: table=" + table + ",value=" + value + ",sortValue=" + sortValue);
}
try
{
Object[] params;
String select;
if (authority != null)
{
params = new Object[]{ value, authority };
}
else
{
params = new Object[]{ value };
}
if (ConfigurationManager.getBooleanProperty("webui.browse.metadata.case-insensitive", false))
{
if (authority != null)
{
select = "SELECT distinct_id FROM " + table + " WHERE UPPER(value) = UPPER(?) and authority = ?";
}
else
{
select = "SELECT distinct_id FROM " + table + " WHERE UPPER(value) = UPPER(?) and authority IS NULL";
}
}
else
{
select = "SELECT id FROM " + table + " WHERE value = ?";
if (authority != null)
{
select = "SELECT distinct_id FROM " + table + " WHERE value = ? and authority = ?";
}
else
{
select = "SELECT distinct_id FROM " + table + " WHERE value = ? and authority IS NULL";
}
}
tri = DatabaseManager.query(context, select, params);
int distinctID = -1;
if (!tri.hasNext())
{
distinctID = insertDistinctRecord(table, value, authority, sortValue);
}
else
{
distinctID = tri.next().getIntColumn("distinct_id");
}
if (log.isDebugEnabled())
{
log.debug("getDistinctID: return=" + distinctID);
}
return distinctID;
}
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new BrowseException(e);
}
finally
{
if (tri != null)
{
tri.close();
}
}
}