mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
Add getNonPrimaryKeyColumnNames method which gets column names
from ResultSetMetaData In canonicalize method, the canonical name of a null table is null In process method, if the table name is null, obtain the column names from the ResultSetMetaData In process method, support BIGINT/long data type Add query method which uses PreparedStatements git-svn-id: http://scm.dspace.org/svn/repo/trunk@57 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -112,6 +112,25 @@ public class DatabaseManager
|
||||
canonicalize(table));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an iterator with the results of executing STATEMENT.
|
||||
* The type of result is given by TABLE.
|
||||
* The context is that of the connection which was used to create
|
||||
* STATEMENT.
|
||||
*
|
||||
* @param statement - The prepared statement
|
||||
* @param table - The name of the table which results
|
||||
* @return - A TableRowIterator with the results of the query
|
||||
* @exception SQLException - If a database error occurs
|
||||
*/
|
||||
public static TableRowIterator query(String table,
|
||||
PreparedStatement statement)
|
||||
throws SQLException
|
||||
{
|
||||
return new TableRowIterator(statement.executeQuery(),
|
||||
canonicalize(table));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the single row result to this query, null if no result.
|
||||
* If more than one row results, only the first is returned.
|
||||
@@ -463,6 +482,23 @@ public class DatabaseManager
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all the columns which are not primary keys
|
||||
*/
|
||||
protected static List getNonPrimaryKeyColumnNames ( ResultSetMetaData meta)
|
||||
throws SQLException
|
||||
{
|
||||
List results = new ArrayList();
|
||||
int columns = meta.getColumnCount();
|
||||
|
||||
for (int i = 0; i < columns; i++ )
|
||||
{
|
||||
results.add(meta.getColumnLabel(i + 1));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the canonical name for TABLE.
|
||||
*
|
||||
@@ -471,7 +507,7 @@ public class DatabaseManager
|
||||
*/
|
||||
static String canonicalize(String table)
|
||||
{
|
||||
return table.toLowerCase();
|
||||
return table == null ? null : table.toLowerCase();
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
@@ -622,12 +658,16 @@ public class DatabaseManager
|
||||
static TableRow process (ResultSet results, String table)
|
||||
throws SQLException
|
||||
{
|
||||
TableRow row = new TableRow(canonicalize(table),
|
||||
getNonPrimaryKeyColumnNames(table));
|
||||
|
||||
ResultSetMetaData meta = results.getMetaData();
|
||||
int columns = meta.getColumnCount() + 1;
|
||||
|
||||
List columnNames = table == null ?
|
||||
getNonPrimaryKeyColumnNames(meta) :
|
||||
getNonPrimaryKeyColumnNames(table);
|
||||
|
||||
TableRow row = new TableRow(canonicalize(table), columnNames);
|
||||
|
||||
|
||||
// Process the columns in order
|
||||
// (This ensures maximum backwards compatibility with
|
||||
// old JDBC drivers)
|
||||
@@ -644,6 +684,10 @@ public class DatabaseManager
|
||||
{
|
||||
row.setColumn(name, results.getInt(i));
|
||||
}
|
||||
else if (jdbctype == Types.BIGINT)
|
||||
{
|
||||
row.setColumn(name, results.getLong(i));
|
||||
}
|
||||
else if (jdbctype == Types.VARCHAR)
|
||||
{
|
||||
row.setColumn(name, results.getString(i));
|
||||
|
Reference in New Issue
Block a user