public class DatabaseManager extends Object
Modifier | Constructor and Description |
---|---|
protected |
DatabaseManager()
Protected Constructor to prevent instantiation except by derived classes.
|
Modifier and Type | Method and Description |
---|---|
static void |
applyOffsetAndLimit(StringBuffer query,
List<Serializable> params,
int offset,
int limit) |
static TableRow |
create(Context context,
String table)
Create a new row in the given table, and assigns a unique id.
|
static int |
delete(Context context,
String table,
int id)
Delete a table row via its primary key.
|
static int |
delete(Context context,
TableRow row)
Delete row from the RDBMS.
|
static int |
deleteByValue(Context context,
String table,
String column,
Object value)
Delete all table rows with the given value.
|
static TableRow |
find(Context context,
String table,
int id)
Find a table row by its primary key.
|
static TableRow |
findByUnique(Context context,
String table,
String column,
Object value)
Find a table row by a unique value.
|
static void |
freeConnection(Connection c)
Release resources associated with this connection.
|
static Connection |
getConnection()
Obtain an RDBMS connection.
|
static DataSource |
getDataSource() |
protected static String |
getPrimaryKeyColumn(String table)
Return the name of the primary key column in the given table.
|
static String |
getPrimaryKeyColumn(TableRow row)
Return the name of the primary key column.
|
static void |
insert(Context context,
TableRow row)
Insert a table row into the RDBMS.
|
static boolean |
isOracle() |
protected static void |
loadParameters(PreparedStatement statement,
Object[] parameters)
Iterate over the given parameters and add them to the given prepared statement.
|
static void |
loadSql(Reader r)
Load SQL from a reader into the RDBMS.
|
static void |
loadSql(String sql)
Load SQL into the RDBMS.
|
static void |
main(String[] args)
Main method used to perform tests on the database
|
static TableRowIterator |
query(Context context,
String query,
Object... parameters)
Return an iterator with the results of the query.
|
static TableRow |
querySingle(Context context,
String query,
Object... parameters)
Return the single row result to this query, or null if no result.
|
static TableRow |
querySingleTable(Context context,
String table,
String query,
Object... parameters)
Return the single row result to this query, or null if no result.
|
static TableRowIterator |
queryTable(Context context,
String table,
String query,
Object... parameters)
Return an iterator with the results of the query.
|
static TableRow |
row(String table)
Create a table row object that can be passed into the insert method, not
commonly used unless the table has a referential integrity constraint.
|
static void |
setConstraintDeferred(Context context,
String constraintName)
Set the constraint check to deferred (commit time)
|
static void |
setConstraintImmediate(Context context,
String constraintName)
Set the constraint check to immediate (every query)
|
static void |
shutdown()
Provide a means for a (web) application to cleanly terminate the connection pool.
|
static int |
update(Context context,
TableRow row)
Update changes to the RDBMS.
|
static int |
updateQuery(Context context,
String query,
Object... parameters)
Execute an update, insert or delete query.
|
protected DatabaseManager()
public static boolean isOracle()
public static void setConstraintDeferred(Context context, String constraintName) throws SQLException
context
- The context objectconstraintName
- the constraint name to deferredSQLException
public static void setConstraintImmediate(Context context, String constraintName) throws SQLException
context
- The context objectconstraintName
- the constraint name to check immediately after every querySQLException
public static TableRowIterator queryTable(Context context, String table, String query, Object... parameters) throws SQLException
context
- The context objecttable
- The name of the table which resultsquery
- The SQL queryparameters
- A set of SQL parameters to be included in query. The order of
the parameters must correspond to the order of their reference
within the query.SQLException
- If a database error occurspublic static TableRowIterator query(Context context, String query, Object... parameters) throws SQLException
context
- The context objectquery
- The SQL queryparameters
- A set of SQL parameters to be included in query. The order of
the parameters must correspond to the order of their reference
within the query.SQLException
- If a database error occurspublic static TableRow querySingle(Context context, String query, Object... parameters) throws SQLException
context
- Current DSpace contextquery
- The SQL queryparameters
- A set of SQL parameters to be included in query. The order of
the parameters must correspond to the order of their reference
within the query.SQLException
- If a database error occurspublic static TableRow querySingleTable(Context context, String table, String query, Object... parameters) throws SQLException
context
- Current DSpace contexttable
- The name of the table which resultsquery
- The SQL queryparameters
- A set of SQL parameters to be included in query. The order of
the parameters must correspond to the order of their reference
within the query.SQLException
- If a database error occurspublic static int updateQuery(Context context, String query, Object... parameters) throws SQLException
context
- Current DSpace contextquery
- The SQL query to executeparameters
- A set of SQL parameters to be included in query. The order of
the parameters must correspond to the order of their reference
within the query.SQLException
- If a database error occurspublic static TableRow create(Context context, String table) throws SQLException
context
- Current DSpace contexttable
- The RDBMS table in which to create the new rowSQLException
public static TableRow find(Context context, String table, int id) throws SQLException
context
- Current DSpace contexttable
- The table in which to find the rowid
- The primary key valueSQLException
- If a database error occurspublic static TableRow findByUnique(Context context, String table, String column, Object value) throws SQLException
context
- Current DSpace contexttable
- The table to use to find the objectcolumn
- The name of the unique columnvalue
- The value of the unique columnSQLException
- If a database error occurspublic static int delete(Context context, String table, int id) throws SQLException
context
- Current DSpace contexttable
- The table to delete fromid
- The primary key valueSQLException
- If a database error occurspublic static int deleteByValue(Context context, String table, String column, Object value) throws SQLException
context
- Current DSpace contexttable
- The table to delete fromcolumn
- The name of the columnvalue
- The value of the columnSQLException
- If a database error occurspublic static Connection getConnection() throws SQLException
SQLException
- If a database error occurs, or a connection cannot be
obtained.public static DataSource getDataSource()
public static void freeConnection(Connection c)
c
- The connection to releasepublic static TableRow row(String table) throws SQLException
table
- The RDBMS table in which to create the new rowSQLException
public static void insert(Context context, TableRow row) throws SQLException
context
- Current DSpace contextrow
- The row to insertSQLException
- If a database error occurspublic static int update(Context context, TableRow row) throws SQLException
context
- Current DSpace contextrow
- The row to updateSQLException
- If a database error occurspublic static int delete(Context context, TableRow row) throws SQLException
context
- Current DSpace contextrow
- The row to deleteSQLException
- If a database error occurspublic static void loadSql(String sql) throws SQLException
sql
- The SQL to load.
throws SQLException
If a database error occursSQLException
public static void loadSql(Reader r) throws SQLException, IOException
r
- The Reader from which to read the SQL.SQLException
- If a database error occursIOException
- If an error occurs obtaining data from the readerpublic static String getPrimaryKeyColumn(TableRow row) throws SQLException
row
- The TableRow to return the primary key for.SQLException
- If a database error occursprotected static String getPrimaryKeyColumn(String table) throws SQLException
table
- The name of the RDBMS tableSQLException
- If a database error occurspublic static void shutdown() throws SQLException
SQLException
protected static void loadParameters(PreparedStatement statement, Object[] parameters) throws SQLException
statement
- The unparameterized statement.parameters
- The parameters to be set on the statement.SQLException
public static void main(String[] args)
args
- The command line argumentspublic static void applyOffsetAndLimit(StringBuffer query, List<Serializable> params, int offset, int limit)
Copyright © 2016 DuraSpace. All Rights Reserved.