|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.empire.commons.ErrorObject
org.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 als 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. |
Nested classes/interfaces inherited from class org.apache.empire.commons.ErrorObject |
---|
ErrorObject.ObjectErrorInfo |
Field Summary | |
---|---|
protected DBDatabaseDriver |
driver
|
static java.lang.String |
EMPTY_STRING
|
protected java.lang.String |
linkName
|
protected java.util.List<DBRelation> |
relations
|
protected java.lang.String |
schema
the database schema * |
static DBDatabase.DBSystemDate |
SYSDATE
|
protected java.util.List<DBTable> |
tables
|
protected java.util.List<DBView> |
views
|
Constructor Summary | |
---|---|
DBDatabase()
Constructs a new DBDatabase object set the variable 'schema' = null. |
|
DBDatabase(java.lang.String schema)
Constructs a new DBDatabase object and sets the specified schema object. |
|
DBDatabase(java.lang.String schema,
java.lang.String linkName)
Constructs a new DBDatabase object and sets the specified schema object. |
Method Summary | ||
---|---|---|
boolean |
addRelation(DBRelation.DBReference reference)
Adds a foreign key relation to the database. |
|
boolean |
addRelation(DBRelation.DBReference ref1,
DBRelation.DBReference ref2)
Add a foreign key relation to the database. |
|
boolean |
addRelation(java.lang.String name,
DBRelation.DBReference[] references)
Adds a foreign key relation to the database. |
|
boolean |
addTable(DBTable table)
Adds a DBTable object to list of database tables. There is usually no need to call this function directly since it is internally called from the DBTable's constructor. |
|
boolean |
addView(DBView view)
Adds a DBView object to list of database views. There is usually no need to call this function directly since it is internally called from the DBView's constructor. |
|
void |
appendQualifiedName(java.lang.StringBuilder buf,
java.lang.String name,
boolean quoteName)
Adds a full qualified object name including schema prefix and database link postfix (if any). |
|
protected boolean |
checkOpen()
|
|
void |
close(java.sql.Connection conn)
closes this database object by detaching it from the driver this is a shortcut for calling getDriver().closeDatabase(db, conn) |
|
void |
closeResultSet(java.sql.ResultSet rset)
Convenience function for closing a JDBC Resultset Use it instead of rset.close() and stmt.close() |
|
void |
closeStatement(java.sql.Statement stmt)
Convenience function for closing a JDBC Resultset Use it instead of stmt.close() |
|
boolean |
commit(java.sql.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 |
|
java.sql.ResultSet |
executeQuery(java.lang.String sqlCmd,
java.lang.Object[] sqlParams,
boolean scrollable,
java.sql.Connection conn)
Executes a select SQL-Statement and returns a resulset containing the query results. This function returns a JDBC ResultSet. Insteam of using this function directly you should use a DBReader object instead. |
|
int |
executeSQL(java.lang.String sqlCmd,
java.sql.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(java.lang.String sqlCmd,
java.lang.Object[] sqlParams,
java.sql.Connection conn)
|
|
int |
executeSQL(java.lang.String sqlCmd,
java.lang.Object[] sqlParams,
java.sql.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. |
|
boolean |
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. |
|
java.lang.String |
getLinkName()
Returns the database link name. |
|
java.lang.Object |
getNextSequenceValue(java.lang.String seqName,
java.sql.Connection conn)
|
|
java.lang.String |
getQualifiedName(java.lang.String name)
Deprecated. |
|
java.util.List<DBRelation> |
getRelations()
Returns the tables which has been defined in the database. |
|
java.lang.String |
getSchema()
Returns the schema for SQL statements. |
|
java.lang.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(java.lang.String name)
Finds a DBTable object by name. |
|
java.util.List<DBTable> |
getTables()
Returns the tables which has been defined in the database. |
|
java.sql.Timestamp |
getUpdateTimestamp(java.sql.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(java.lang.Object value,
DataType dataType)
Creates and returns a value object for the given value. |
|
DBValueExpr |
getValueExpr(java.lang.String value)
Creates and returns a value object for the given string value. |
|
DBView |
getView(java.lang.String name)
Finds a DBView object by name. |
|
java.util.List<DBView> |
getViews()
Returns the tables which has been defined in the database. |
|
boolean |
isOpen()
Indicates whether the database has been opened. |
|
boolean |
open(DBDatabaseDriver driver,
java.sql.Connection conn)
Sets the database driver for this database. |
|
java.util.List<java.lang.Object[]> |
queryObjectList(java.lang.String sqlCmd,
java.sql.Connection conn)
Returns a list Object-Arrays holding the result of a query. |
|
Options |
queryOptionList(java.lang.String sqlCmd,
java.sql.Connection conn)
Returns a list of key value pairs from an sql query. |
|
|
querySimpleList(java.lang.Class<T> c,
java.lang.String sqlCmd,
java.sql.Connection conn)
Returns a one dimensional array from an sql query. |
|
java.util.List<java.lang.Object> |
querySimpleList(java.lang.String sqlCmd,
java.sql.Connection conn)
Returns a one dimensional array from an sql query. |
|
double |
querySingleDouble(java.lang.String sqlCmd,
java.sql.Connection conn)
Returns the value of the first row/column of a sql-query as a double. |
|
double |
querySingleDouble(java.lang.String sqlCmd,
double defVal,
java.sql.Connection conn)
Returns the value of the first row/column of a sql-query as a double. |
|
int |
querySingleInt(java.lang.String sqlCmd,
java.sql.Connection conn)
Returns the value of the first row/column of a sql-query as an int. |
|
int |
querySingleInt(java.lang.String sqlCmd,
int defVal,
java.sql.Connection conn)
Returns the value of the first row/column of a sql-query as an int. |
|
long |
querySingleLong(java.lang.String sqlCmd,
java.sql.Connection conn)
Returns the value of the first row/column of a sql-query as a long. |
|
long |
querySingleLong(java.lang.String sqlCmd,
long defVal,
java.sql.Connection conn)
Returns the value of the first row/column of a sql-query as a long. |
|
java.lang.String |
querySingleString(java.lang.String sqlCmd,
java.sql.Connection conn)
Returns the value of the first row/column of a sql-query as a string. |
|
java.lang.String |
querySingleString(java.lang.String sqlCmd,
java.lang.String defVal,
java.sql.Connection conn)
Returns the value of the first row/column of a sql-query as a string. |
|
java.lang.Object |
querySingleValue(java.lang.String sqlCmd,
java.sql.Connection conn)
Returns the value of the first row/column of a sql-query as an object. |
|
boolean |
rollback(java.sql.Connection conn)
Discards all changes made since the previous commit/rollback and releases any database locks currently held by this Connection. |
|
boolean |
setLinkName(java.lang.String linkName)
Sets the name of the database link used to identify objects. |
|
boolean |
setSchema(java.lang.String schema)
Sets the schema for SQL statements. |
Methods inherited from class org.apache.empire.db.DBObject |
---|
error, error |
Methods inherited from class org.apache.empire.commons.ErrorObject |
---|
clearError, clearErrorInfo, error, error, error, error, error, error, error, getErrorInfo, getErrorMessage, getErrorParams, getErrorSource, getErrorType, getMessage, hasError, internalSetError, isExceptionsEnabled, setExceptionsEnabled, success |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final DBDatabase.DBSystemDate SYSDATE
public static final java.lang.String EMPTY_STRING
protected java.lang.String schema
protected java.lang.String linkName
protected java.util.List<DBTable> tables
protected java.util.List<DBRelation> relations
protected java.util.List<DBView> views
protected DBDatabaseDriver driver
Constructor Detail |
---|
public DBDatabase()
public DBDatabase(java.lang.String schema)
schema
- the database schemapublic DBDatabase(java.lang.String schema, java.lang.String linkName)
schema
- the database schemalinkName
- the database link nameMethod Detail |
---|
public DBDatabaseDriver getDriver()
public boolean open(DBDatabaseDriver driver, java.sql.Connection conn)
driver
- the databae driverconn
- the connection
public void close(java.sql.Connection conn)
conn
- the connection to closepublic boolean 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 completed
public DBDatabase getDatabase()
DBObject
getDatabase
in class DBObject
DBObject.getDatabase()
public java.lang.String getSchema()
public boolean setSchema(java.lang.String schema)
schema
- the schema to set
public java.lang.String getSchemaPrefix()
public java.lang.String getLinkName()
public boolean setLinkName(java.lang.String linkName)
linkName
- the database link name
@Deprecated public java.lang.String getQualifiedName(java.lang.String name)
name
- the object's name
public void appendQualifiedName(java.lang.StringBuilder buf, java.lang.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(java.lang.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(java.lang.Object value, DataType dataType)
value
- the valuedataType
- the database systems data type used for this value
public boolean addTable(DBTable table)
table
- the DBTable object
public java.util.List<DBTable> getTables()
public DBTable getTable(java.lang.String name)
name
- the name of the table
public final boolean addRelation(DBRelation.DBReference reference)
reference
- a reference for a source and target column pair
public final boolean 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 pair
public boolean addRelation(java.lang.String name, DBRelation.DBReference[] references)
name
- the relation namereferences
- a list of source and target column pairs
public java.util.List<DBRelation> getRelations()
public boolean addView(DBView view)
view
- the DBView object
public java.util.List<DBView> getViews()
public DBView getView(java.lang.String name)
name
- the name of the view
public boolean isOpen()
protected boolean checkOpen()
public DBCommand createCommand()
public java.sql.Timestamp getUpdateTimestamp(java.sql.Connection conn)
conn
- the connection
public java.lang.Object getNextSequenceValue(java.lang.String seqName, java.sql.Connection conn)
public java.lang.Object querySingleValue(java.lang.String sqlCmd, java.sql.Connection conn)
sqlCmd
- the SQL-Commandconn
- a valid connection to the database.
null
if there was no valuepublic int querySingleInt(java.lang.String sqlCmd, int defVal, java.sql.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(java.lang.String sqlCmd, java.sql.Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public long querySingleLong(java.lang.String sqlCmd, long defVal, java.sql.Connection conn)
sqlCmd
- the SQL statementdefVal
- the default valueconn
- a valid connection to the database.
public final long querySingleLong(java.lang.String sqlCmd, java.sql.Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public double querySingleDouble(java.lang.String sqlCmd, double defVal, java.sql.Connection conn)
sqlCmd
- the SQL statementdefVal
- the default valueconn
- a valid connection to the database.
public final double querySingleDouble(java.lang.String sqlCmd, java.sql.Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public java.lang.String querySingleString(java.lang.String sqlCmd, java.lang.String defVal, java.sql.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 java.lang.String querySingleString(java.lang.String sqlCmd, java.sql.Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public <T> java.util.List<T> querySimpleList(java.lang.Class<T> c, java.lang.String sqlCmd, java.sql.Connection conn)
T
- the type for th listc
- the class type for the listsqlCmd
- the SQL statementconn
- a valid connection to the database.
public java.util.List<java.lang.Object> querySimpleList(java.lang.String sqlCmd, java.sql.Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public Options queryOptionList(java.lang.String sqlCmd, java.sql.Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public java.util.List<java.lang.Object[]> queryObjectList(java.lang.String sqlCmd, java.sql.Connection conn)
sqlCmd
- the SQL statementconn
- a valid connection to the database.
public int executeSQL(java.lang.String sqlCmd, java.lang.Object[] sqlParams, java.sql.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(java.lang.String sqlCmd, java.lang.Object[] sqlParams, java.sql.Connection conn)
public final int executeSQL(java.lang.String sqlCmd, java.sql.Connection conn)
sqlCmd
- the SQL-Commandconn
- a valid connection to the database.
public java.sql.ResultSet executeQuery(java.lang.String sqlCmd, java.lang.Object[] sqlParams, boolean scrollable, java.sql.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 boolean commit(java.sql.Connection conn)
conn
- a valid database connection
public boolean rollback(java.sql.Connection conn)
conn
- a valid database connection
public void closeStatement(java.sql.Statement stmt)
stmt
- a Statement objectpublic void closeResultSet(java.sql.ResultSet rset)
rset
- a ResultSet object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |