|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.empire.db.DBObject
org.apache.empire.db.DBDatabase
public abstract class DBDatabase
This abstract class is the applicaton's interface for a particular database schema.
It provides access to the various database objects such as tables, views and relations.
It also provides methods to execute DQL and DML SQL-commands.
Nested Class Summary | |
---|---|
static class |
DBDatabase.DBSystemDate
This class represents the database systems current date and time. |
Field Summary | |
---|---|
protected DBDatabaseDriver |
driver
|
static String |
EMPTY_STRING
|
protected String |
instanceId
|
protected String |
linkName
|
protected long |
longRunndingStmtThreshold
|
protected List<DBRelation> |
relations
|
protected String |
schema
the database schema * |
static DBDatabase.DBSystemDate |
SYSDATE
|
protected List<DBTable> |
tables
|
protected List<DBView> |
views
|
Constructor Summary | |
---|---|
DBDatabase()
Constructs a new DBDatabase object set the variable 'schema' = null. |
|
DBDatabase(String schema)
Constructs a new DBDatabase object and sets the specified schema object. |
|
DBDatabase(String schema,
String linkName)
Constructs a new DBDatabase object and sets the specified schema object. |
Method Summary | ||
---|---|---|
DBRelation |
addRelation(DBRelation.DBReference reference)
Adds a foreign key relation to the database. |
|
DBRelation |
addRelation(DBRelation.DBReference ref1,
DBRelation.DBReference ref2)
Add a foreign key relation to the database. |
|
DBRelation |
addRelation(String name,
DBRelation.DBReference[] references)
Adds a foreign key relation to the database. |
|
protected void |
addTable(DBTable table)
Adds a DBTable object to list of database tables. This function is called internally from the DBTable's constructor. |
|
protected void |
addView(DBView view)
Adds a DBView object to list of database views. This function is called internally from the DBView's constructor. |
|
void |
appendQualifiedName(StringBuilder buf,
String name,
boolean quoteName)
Adds a full qualified object name including schema prefix and database link postfix (if any). |
|
protected void |
checkOpen()
checks if the database has been opened or false otherwise |
|
void |
close(Connection conn)
closes this database object by detaching it from the driver this is a shortcut for calling getDriver().closeDatabase(db, conn) |
|
void |
closeResultSet(ResultSet rset)
Convenience function for closing a JDBC Resultset Use it instead of rset.close() and stmt.close() |
|
void |
closeStatement(Statement stmt)
Convenience function for closing a JDBC Resultset Use it instead of stmt.close() |
|
void |
commit(Connection conn)
Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by the Connection. |
|
DBCommand |
createCommand()
Creates a new Command object for this database |
|
ResultSet |
executeQuery(String sqlCmd,
Object[] sqlParams,
boolean scrollable,
Connection conn)
Executes a select SQL-Statement and returns a resultset containing the query results. This function returns a JDBC ResultSet. Instead of using this function directly you should use a DBReader object instead. |
|
int |
executeSQL(String sqlCmd,
Connection conn)
Executes an update, insert or delete SQL-Statement. We recommend to use a DBCommand object in order to build the sqlCmd. |
|
int |
executeSQL(String sqlCmd,
Object[] sqlParams,
Connection conn)
|
|
int |
executeSQL(String sqlCmd,
Object[] sqlParams,
Connection conn,
DBDatabaseDriver.DBSetGenKeys setGenKeys)
Executes an update, insert or delete SQL-Statement. We recommend to use a DBCommand object in order to build the sqlCmd. |
|
static DBDatabase |
findByClass(Class<? extends DBDatabase> cls)
find a database by id |
|
static DBDatabase |
findById(String dbIdent)
find a database by id |
|
void |
getCreateDDLScript(DBDatabaseDriver driver,
DBSQLScript script)
Creates a DDL Script for creating all database objects on the target database. This function may be called even if the database has not been previously opened. |
|
DBDatabase |
getDatabase()
Returns the database object to which this object belongs to. |
|
DBDatabaseDriver |
getDriver()
Returns the driver for this database. |
|
String |
getId()
Returns the database instance id |
|
String |
getLinkName()
Returns the database link name. |
|
Object |
getNextSequenceValue(String seqName,
Connection conn)
|
|
String |
getQualifiedName(String name)
Deprecated. |
|
DBRelation |
getRelation(String relationName)
Returns the relation of a given name |
|
List<DBRelation> |
getRelations()
Returns the relations which have been defined in the database. |
|
DBRowSet |
getRowSet(String name)
Finds a DBRowSet object (DBTable or DBView) by name. |
|
String |
getSchema()
Returns the schema for SQL statements. |
|
String |
getSchemaPrefix()
Returns the schema-prefix for SQL statements e.g. |
|
DBValueExpr |
getSystemDateExpr()
Creates and returns a value object for the database systems current date and time. |
|
DBTable |
getTable(String name)
Finds a DBTable object by name. |
|
List<DBTable> |
getTables()
Returns the tables which have been defined in the database. |
|
Timestamp |
getUpdateTimestamp(Connection conn)
Returns a timestamp that is used for record updates. |
|
DBValueExpr |
getValueExpr(boolean value)
Creates and returns a value object for the given boolean value. |
|
DBValueExpr |
getValueExpr(int value)
Creates and returns a value object for the given integer value. |
|
DBValueExpr |
getValueExpr(long value)
Creates and returns a value object for the given long value. |
|
DBValueExpr |
getValueExpr(Object value,
DataType dataType)
Creates and returns a value object for the given value. |
|
DBValueExpr |
getValueExpr(String value)
Creates and returns a value object for the given string value. |
|
DBView |
getView(String name)
Finds a DBView object by name. |
|
List<DBView> |
getViews()
Returns the views which have been defined in the database. |
|
boolean |
isOpen()
Indicates whether the database has been opened. |
|
boolean |
isPreparedStatementsEnabled()
return whether prepared statements are preferred over normal statements (Default is false) Note: This will only apply for update and insert commands as well as for read operations on a DBRecord. |
|
void |
open(DBDatabaseDriver driver,
Connection conn)
Sets the database driver for this database. |
|
List<Object[]> |
queryObjectList(String sqlCmd,
Connection conn)
Returns the result of a query as a list Object-Arrays This function should only be used for small lists. |
|
int |
queryObjectList(String sqlCmd,
Connection conn,
Collection<Object[]> result)
Adds the result of a query to a given collection. The individual rows will be added as an array of objects (object[]) |
|
int |
queryObjectList(String sqlCmd,
Object[] sqlParams,
Connection conn,
Collection<Object[]> result,
int maxRows)
Adds the result of a query to a given collection. The individual rows will be added as an array of objects (object[]) |
|
Options |
queryOptionList(String sqlCmd,
Connection conn)
Returns a list of key value pairs from an sql query. |
|
int |
queryOptionList(String sqlCmd,
Connection conn,
Options result)
Fills an option list provided with the result from a query. |
|
int |
queryOptionList(String sqlCmd,
Object[] sqlParams,
Connection conn,
Options result)
Fills an option list provided with the result from a query. |
|
|
querySimpleList(Class<T> c,
String sqlCmd,
Connection conn)
Returns a one dimensional array from an sql query. |
|
|
querySimpleList(Class<T> c,
String sqlCmd,
Connection conn,
Collection<T> result)
Adds the first column of a query result to a collection. |
|
|
querySimpleList(Class<T> c,
String sqlCmd,
Object[] sqlParams,
DataType dataType,
Connection conn,
Collection<T> result,
int maxRows)
Adds the first column of a query result to a collection. |
|
List<Object> |
querySimpleList(String sqlCmd,
Connection conn)
Returns a one dimensional array from an sql query. |
|
int |
querySingleInt(String sqlCmd,
Connection conn)
Returns the value of the first row/column of a sql-query as an int. |
|
int |
querySingleInt(String sqlCmd,
int defVal,
Connection conn)
Returns the value of the first row/column of a sql-query as an int. |
|
int |
querySingleInt(String sqlCmd,
Object[] sqlParams,
int defVal,
Connection conn)
Returns the value of the first row/column of a sql-query as an int. |
|
long |
querySingleLong(String sqlCmd,
Connection conn)
Returns the value of the first row/column of a sql-query as a long. |
|
long |
querySingleLong(String sqlCmd,
long defVal,
Connection conn)
Returns the value of the first row/column of a sql-query as a long. |
|
long |
querySingleLong(String sqlCmd,
Object[] sqlParams,
long defVal,
Connection conn)
Returns the value of the first row/column of a sql-query as a long. |
|
Object[] |
querySingleRow(String sqlCmd,
Connection conn)
Returns all values of the first row of a sql-query as an array. |
|
Object[] |
querySingleRow(String sqlCmd,
Object[] sqlParams,
Connection conn)
Returns all values of the first row of a sql-query as an array. |
|
String |
querySingleString(String sqlCmd,
Connection conn)
Returns the value of the first row/column of a sql-query as a string. |
|
String |
querySingleString(String sqlCmd,
Object[] sqlParams,
String defVal,
Connection conn)
Returns the value of the first row/column of a sql-query as a string. |
|
String |
querySingleString(String sqlCmd,
String defVal,
Connection conn)
Returns the value of the first row/column of a sql-query as a string. |
|
Object |
querySingleValue(String sqlCmd,
Connection conn)
Returns the value of the first row/column of a sql-query as an object. |
|
Object |
querySingleValue(String sqlCmd,
Object[] sqlParams,
Connection conn)
Returns the value of the first row/column of a sql-query as an object. |
|
Object |
querySingleValue(String sqlCmd,
Object[] sqlParams,
DataType dataType,
Connection conn)
Returns the value of the first row/column of a sql-query as an object. |
|
protected void |
register(String dbid)
registers the database in the global list of databases |
|
void |
rollback(Connection conn)
Discards all changes made since the previous commit/rollback and releases any database locks currently held by this Connection. |
|
void |
setLinkName(String linkName)
Sets the name of the database link used to identify objects. |
|
void |
setPreparedStatementsEnabled(boolean preparedStatementsEnabled)
enables or disables the use of prepared statements for update and insert commands as well as for read operations on a DBRecord. |
|
void |
setSchema(String schema)
Sets the schema for SQL statements. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected long longRunndingStmtThreshold
public static final DBDatabase.DBSystemDate SYSDATE
public static final String EMPTY_STRING
protected String schema
protected String linkName
protected List<DBTable> tables
protected List<DBRelation> relations
protected List<DBView> views
protected DBDatabaseDriver driver
protected String instanceId
Constructor Detail |
---|
public DBDatabase(String schema, String linkName)
schema
- the database schemalinkName
- the database link namepublic DBDatabase(String schema)
schema
- the database schemapublic DBDatabase()
Method Detail |
---|
public static DBDatabase findById(String dbIdent)
public static DBDatabase findByClass(Class<? extends DBDatabase> cls)
protected void register(String dbid)
dbid
- public String getId()
public DBDatabaseDriver getDriver()
public boolean isPreparedStatementsEnabled()
public void setPreparedStatementsEnabled(boolean preparedStatementsEnabled)
preparedStatementsEnabled
- public void open(DBDatabaseDriver driver, Connection conn)
driver
- the database driverconn
- the connectionpublic void close(Connection conn)
conn
- the connection to closepublic void getCreateDDLScript(DBDatabaseDriver driver, DBSQLScript script)
Once the database is open you can use getDriver().getDLLCommand()
to create, alter or delete other database objects
driver
- The driver for which to create a DDL Scriptscript
- the script object that will be completedpublic DBDatabase getDatabase()
DBObject
getDatabase
in class DBObject
DBObject.getDatabase()
public String getSchema()
public void setSchema(String schema)
schema
- the schema to setpublic String getSchemaPrefix()
public String getLinkName()
public void setLinkName(String linkName)
linkName
- the database link name@Deprecated public String getQualifiedName(String name)
name
- the object's name
public void appendQualifiedName(StringBuilder buf, String name, boolean quoteName)
buf
- the string buffer to which to append the qualified object namename
- the object's namequoteName
- use quotes or notpublic DBValueExpr getSystemDateExpr()
public DBValueExpr getValueExpr(String value)
value
- the String value
public DBValueExpr getValueExpr(boolean value)
value
- the Boolean value
public DBValueExpr getValueExpr(int value)
value
- the int value
public DBValueExpr getValueExpr(long value)
value
- the long value
public DBValueExpr getValueExpr(Object value, DataType dataType)
value
- the valuedataType
- the database systems data type used for this value
protected void addTable(DBTable table)
table
- the DBTable objectpublic List<DBTable> getTables()
public DBRowSet getRowSet(String name)
name
- the name of the table
public DBTable getTable(String name)
name
- the name of the table
public final DBRelation addRelation(DBRelation.DBReference reference)
reference
- a reference for a source and target column pairpublic final DBRelation addRelation(DBRelation.DBReference ref1, DBRelation.DBReference ref2)
ref1
- a reference for a source and target column pairref2
- a reference for a source and target column pairpublic DBRelation addRelation(String name, DBRelation.DBReference[] references)
name
- the relation namereferences
- a list of source and target column pairspublic List<DBRelation> getRelations()
public DBRelation getRelation(String relationName)
protected void addView(DBView view)
view
- the DBView objectpublic List<DBView> getViews()
public DBView getView(String name)
name
- the name of the view
public boolean isOpen()
protected void checkOpen()
public DBCommand createCommand()
public Timestamp getUpdateTimestamp(Connection conn)
conn
- the connection
public Object getNextSequenceValue(String seqName, Connection conn)
public Object querySingleValue(String sqlCmd, Object[] sqlParams, DataType dataType, Connection conn)
sqlCmd
- the SQL-CommandsqlParams
- list of query parameter valuesdataType
- the expected data typeconn
- a valid connection to the database.
public final Object querySingleValue(String sqlCmd, Object[] sqlParams, Connection conn)
sqlCmd
- the SQL-CommandsqlParams
- list of query parameter valuesconn
- a valid connection to the database.
public final Object querySingleValue(String sqlCmd, Connection conn)
sqlCmd
- the SQL-Commandconn
- a valid connection to the database.
public final int querySingleInt(String sqlCmd, Object[] sqlParams, int defVal, Connection conn)
sqlCmd
- the SQL statementsqlParams
- list of query parameter valuesdefVal
- the default value if no value was returned by the databaseconn
- a valid connection to the database.
public final int querySingleInt(String sqlCmd, int defVal, Connection conn)
sqlCmd
- the SQL statementdefVal
- the default value if no value was returned by the databaseconn
- a valid connection to the database.
public final int querySingleInt(String sqlCmd, Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public final long querySingleLong(String sqlCmd, Object[] sqlParams, long defVal, Connection conn)
sqlCmd
- the SQL statementsqlParams
- list of query parameter valuesdefVal
- the default valueconn
- a valid connection to the database.
public final long querySingleLong(String sqlCmd, long defVal, Connection conn)
sqlCmd
- the SQL statementdefVal
- the default valueconn
- a valid connection to the database.
public final long querySingleLong(String sqlCmd, Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public final String querySingleString(String sqlCmd, Object[] sqlParams, String defVal, Connection conn)
sqlCmd
- the SQL statementsqlParams
- list of query parameter valuesdefVal
- the default value if no value was returned by the databaseconn
- a valid connection to the database.
public final String querySingleString(String sqlCmd, String defVal, Connection conn)
sqlCmd
- the SQL statementdefVal
- the default value if no value was returned by the databaseconn
- a valid connection to the database.
public final String querySingleString(String sqlCmd, Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public <T> int querySimpleList(Class<T> c, String sqlCmd, Object[] sqlParams, DataType dataType, Connection conn, Collection<T> result, int maxRows)
T
- the type for the listc
- the class type for the listsqlCmd
- the SQL statementdataType
- the expected data typeconn
- a valid connection to the database.maxRows
- maximum number of rows or -1 for all rows
public final <T> int querySimpleList(Class<T> c, String sqlCmd, Connection conn, Collection<T> result)
T
- the type for the listc
- the class type for the listsqlCmd
- the SQL statementconn
- a valid connection to the database.
public final <T> List<T> querySimpleList(Class<T> c, String sqlCmd, Connection conn)
T
- the type for the listc
- the class type for the listsqlCmd
- the SQL statementconn
- a valid connection to the database.
public final List<Object> querySimpleList(String sqlCmd, Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public int queryOptionList(String sqlCmd, Object[] sqlParams, Connection conn, Options result)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public final int queryOptionList(String sqlCmd, Connection conn, Options result)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public final Options queryOptionList(String sqlCmd, Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public int queryObjectList(String sqlCmd, Object[] sqlParams, Connection conn, Collection<Object[]> result, int maxRows)
This function should only be used for small lists. Otherwise a DBReader should be used!
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public final int queryObjectList(String sqlCmd, Connection conn, Collection<Object[]> result)
This function should only be used for small lists. Otherwise a DBReader should be used!
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public final List<Object[]> queryObjectList(String sqlCmd, Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public Object[] querySingleRow(String sqlCmd, Object[] sqlParams, Connection conn)
sqlCmd
- the SQL-CommandsqlParams
- list of query parameter valuesconn
- a valid connection to the database.
public final Object[] querySingleRow(String sqlCmd, Connection conn)
sqlCmd
- the SQL-Commandconn
- a valid connection to the database.
public int executeSQL(String sqlCmd, Object[] sqlParams, Connection conn, DBDatabaseDriver.DBSetGenKeys setGenKeys)
sqlCmd
- the SQL-CommandsqlParams
- a list of objects to replace sql parametersconn
- a valid connection to the database.setGenKeys
- object to set the generated keys for
public final int executeSQL(String sqlCmd, Object[] sqlParams, Connection conn)
public final int executeSQL(String sqlCmd, Connection conn)
sqlCmd
- the SQL-Commandconn
- a valid connection to the database.
public ResultSet executeQuery(String sqlCmd, Object[] sqlParams, boolean scrollable, Connection conn)
sqlCmd
- the SQL-CommandsqlParams
- a list of parameters for parameter queries (may depend on driver)scrollable
- true if the reader should be scrollable or false if notconn
- a valid connection to the database.
public void commit(Connection conn)
conn
- a valid database connectionpublic void rollback(Connection conn)
conn
- a valid database connectionpublic void closeStatement(Statement stmt)
stmt
- a Statement objectpublic void closeResultSet(ResultSet rset)
rset
- a ResultSet object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |