public class DatabaseManager
extends java.lang.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(java.lang.StringBuffer query,
java.util.List<java.io.Serializable> params,
int offset,
int limit) |
static TableRow |
create(Context context,
java.lang.String table)
Create a new row in the given table, and assigns a unique id.
|
static int |
delete(Context context,
java.lang.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,
java.lang.String table,
java.lang.String column,
java.lang.Object value)
Delete all table rows with the given value.
|
static TableRow |
find(Context context,
java.lang.String table,
int id)
Find a table row by its primary key.
|
static TableRow |
findByUnique(Context context,
java.lang.String table,
java.lang.String column,
java.lang.Object value)
Find a table row by a unique value.
|
static void |
freeConnection(java.sql.Connection c)
Release resources associated with this connection.
|
static java.sql.Connection |
getConnection()
Obtain an RDBMS connection.
|
static javax.sql.DataSource |
getDataSource() |
protected static java.lang.String |
getPrimaryKeyColumn(java.lang.String table)
Return the name of the primary key column in the given table.
|
static java.lang.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(java.sql.PreparedStatement statement,
java.lang.Object[] parameters)
Iterate over the given parameters and add them to the given prepared statement.
|
static void |
loadSql(java.io.Reader r)
Load SQL from a reader into the RDBMS.
|
static void |
loadSql(java.lang.String sql)
Load SQL into the RDBMS.
|
static void |
main(java.lang.String[] args)
Main method used to perform tests on the database
|
static TableRowIterator |
query(Context context,
java.lang.String query,
java.lang.Object... parameters)
Return an iterator with the results of the query.
|
static TableRow |
querySingle(Context context,
java.lang.String query,
java.lang.Object... parameters)
Return the single row result to this query, or null if no result.
|
static TableRow |
querySingleTable(Context context,
java.lang.String table,
java.lang.String query,
java.lang.Object... parameters)
Return the single row result to this query, or null if no result.
|
static TableRowIterator |
queryTable(Context context,
java.lang.String table,
java.lang.String query,
java.lang.Object... parameters)
Return an iterator with the results of the query.
|
static TableRow |
row(java.lang.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,
java.lang.String constraintName)
Set the constraint check to deferred (commit time)
|
static void |
setConstraintImmediate(Context context,
java.lang.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,
java.lang.String query,
java.lang.Object... parameters)
Execute an update, insert or delete query.
|
protected DatabaseManager()
public static boolean isOracle()
public static void setConstraintDeferred(Context context, java.lang.String constraintName) throws java.sql.SQLException
context - The context objectconstraintName - the constraint name to deferredjava.sql.SQLExceptionpublic static void setConstraintImmediate(Context context, java.lang.String constraintName) throws java.sql.SQLException
context - The context objectconstraintName - the constraint name to check immediately after every queryjava.sql.SQLExceptionpublic static TableRowIterator queryTable(Context context, java.lang.String table, java.lang.String query, java.lang.Object... parameters) throws java.sql.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.java.sql.SQLException - If a database error occurspublic static TableRowIterator query(Context context, java.lang.String query, java.lang.Object... parameters) throws java.sql.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.java.sql.SQLException - If a database error occurspublic static TableRow querySingle(Context context, java.lang.String query, java.lang.Object... parameters) throws java.sql.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.java.sql.SQLException - If a database error occurspublic static TableRow querySingleTable(Context context, java.lang.String table, java.lang.String query, java.lang.Object... parameters) throws java.sql.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.java.sql.SQLException - If a database error occurspublic static int updateQuery(Context context, java.lang.String query, java.lang.Object... parameters) throws java.sql.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.java.sql.SQLException - If a database error occurspublic static TableRow create(Context context, java.lang.String table) throws java.sql.SQLException
context - Current DSpace contexttable - The RDBMS table in which to create the new rowjava.sql.SQLExceptionpublic static TableRow find(Context context, java.lang.String table, int id) throws java.sql.SQLException
context - Current DSpace contexttable - The table in which to find the rowid - The primary key valuejava.sql.SQLException - If a database error occurspublic static TableRow findByUnique(Context context, java.lang.String table, java.lang.String column, java.lang.Object value) throws java.sql.SQLException
context - Current DSpace contexttable - The table to use to find the objectcolumn - The name of the unique columnvalue - The value of the unique columnjava.sql.SQLException - If a database error occurspublic static int delete(Context context, java.lang.String table, int id) throws java.sql.SQLException
context - Current DSpace contexttable - The table to delete fromid - The primary key valuejava.sql.SQLException - If a database error occurspublic static int deleteByValue(Context context, java.lang.String table, java.lang.String column, java.lang.Object value) throws java.sql.SQLException
context - Current DSpace contexttable - The table to delete fromcolumn - The name of the columnvalue - The value of the columnjava.sql.SQLException - If a database error occurspublic static java.sql.Connection getConnection()
throws java.sql.SQLException
java.sql.SQLException - If a database error occurs, or a connection cannot be
obtained.public static javax.sql.DataSource getDataSource()
public static void freeConnection(java.sql.Connection c)
c - The connection to releasepublic static TableRow row(java.lang.String table) throws java.sql.SQLException
table - The RDBMS table in which to create the new rowjava.sql.SQLExceptionpublic static void insert(Context context, TableRow row) throws java.sql.SQLException
context - Current DSpace contextrow - The row to insertjava.sql.SQLException - If a database error occurspublic static int update(Context context, TableRow row) throws java.sql.SQLException
context - Current DSpace contextrow - The row to updatejava.sql.SQLException - If a database error occurspublic static int delete(Context context, TableRow row) throws java.sql.SQLException
context - Current DSpace contextrow - The row to deletejava.sql.SQLException - If a database error occurspublic static void loadSql(java.lang.String sql)
throws java.sql.SQLException
sql - The SQL to load.
throws SQLException
If a database error occursjava.sql.SQLExceptionpublic static void loadSql(java.io.Reader r)
throws java.sql.SQLException,
java.io.IOException
r - The Reader from which to read the SQL.java.sql.SQLException - If a database error occursjava.io.IOException - If an error occurs obtaining data from the readerpublic static java.lang.String getPrimaryKeyColumn(TableRow row) throws java.sql.SQLException
row - The TableRow to return the primary key for.java.sql.SQLException - If a database error occursprotected static java.lang.String getPrimaryKeyColumn(java.lang.String table)
throws java.sql.SQLException
table - The name of the RDBMS tablejava.sql.SQLException - If a database error occurspublic static void shutdown()
throws java.sql.SQLException
java.sql.SQLExceptionprotected static void loadParameters(java.sql.PreparedStatement statement,
java.lang.Object[] parameters)
throws java.sql.SQLException
statement - The unparameterized statement.parameters - The parameters to be set on the statement.java.sql.SQLExceptionpublic static void main(java.lang.String[] args)
args - The command line argumentspublic static void applyOffsetAndLimit(java.lang.StringBuffer query,
java.util.List<java.io.Serializable> params,
int offset,
int limit)
Copyright © 2018 DuraSpace. All Rights Reserved.