|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.empire.db.DBDatabaseDriver
public abstract class DBDatabaseDriver
The DBDatabaseDriver class is an abstract base class for all database drivers. Its purpose is to handle everything that is - or might be - database vendor specific.
Nested Class Summary | |
---|---|
static class |
DBDatabaseDriver.DBSeqTable
This class is used to emulate sequences by using a sequence table. |
static interface |
DBDatabaseDriver.DBSetGenKeys
This interface is used to set the auto generated keys when executing insert statements. |
Constructor Summary | |
---|---|
DBDatabaseDriver()
Constructor |
Method Summary | |
---|---|
void |
addEnableRelationStmt(DBRelation r,
boolean enable,
DBSQLScript script)
Appends a statement to enable or disable a foreign key relation. The default is to drop or create the relation Override this method to provide different behavior for your database. |
protected void |
addStatementParam(PreparedStatement pstmt,
int paramIndex,
Object value,
Connection conn)
Adds a statement parameter to a prepared statement |
void |
appendElementName(StringBuilder sql,
String name)
Appends a table, view or column name to an SQL phrase. |
void |
appendElementName(StringBuilder sql,
String name,
boolean useQuotes)
Appends a table, view or column name to an SQL phrase. |
protected void |
appendSQLTextValue(StringBuilder buf,
String value)
this helper function doubles up single quotes for SQL |
protected void |
attachDatabase(DBDatabase db,
Connection conn)
Called when a database is opened |
void |
checkDatabase(DBDatabase db,
String owner,
Connection conn)
Checks the database whether or not it is consistent with the description. |
protected void |
close(Statement stmt)
|
DBCommandExpr |
createCombinedCommand(DBCommandExpr left,
String keyWord,
DBCommandExpr right)
This function gives the driver a chance to provide a custom implementation for a combined command such as UNION or INTERSECT |
abstract DBCommand |
createCommand(DBDatabase db)
This function creates a DBCommand derived object this database |
protected void |
detachDatabase(DBDatabase db,
Connection conn)
Called when a database is closed |
protected boolean |
detectQuoteName(String name)
Detects whether a table or column name needs to be quoted or not By default all reserved SQL keywords as well as names containing a "-", "/", "+" or " " require quoting. Overrides this function to add database specific keywords like "user" or "count" |
ResultSet |
executeQuery(String sqlCmd,
Object[] sqlParams,
boolean scrollable,
Connection conn)
|
int |
executeSQL(String sqlCmd,
Object[] sqlParams,
Connection conn,
DBDatabaseDriver.DBSetGenKeys genKeys)
Executes the select, update or delete SQL-Command with a Statement object. |
String |
extractErrorMessage(SQLException e)
Extracts native error message of an sqlExeption. |
Object |
getColumnAutoValue(DBDatabase db,
DBTableColumn column,
Connection conn)
Returns an auto-generated value for a particular column |
abstract String |
getConvertPhrase(DataType destType,
DataType srcType,
Object format)
Returns a data type convertion phrase template for this driver The returned template must contain a '?' which will be replaced by a column expression. |
void |
getDDLScript(DBCmdType type,
DBObject dbo,
DBSQLScript script)
Appends the required DLL commands to create, drop or alter an object to the supplied DBDQLScript. |
abstract Object |
getNextSequenceValue(DBDatabase db,
String SeqName,
int minValue,
Connection conn)
Returns the next value of a named sequence The numbers are used for fields of type DBExpr.DT_AUTOINC. If a driver supports this function it must return true for isSupported(DBDriverFeature.SEQUENCES). |
Object |
getResultValue(ResultSet rset,
int columnIndex,
DataType dataType)
Reads a single column value from the given JDBC ResultSet and returns a value object of desired data type. See DBExpr.getValueClass(DataType) for java class type mapping. |
protected String |
getSQLDateTimeString(Object value,
int sqlTemplate,
int sqlPattern,
int sqlCurrentDate)
encodes a Date value for an SQL command string. |
protected String |
getSQLNumberString(Object value,
DataType type)
encodes a numeric value for an SQL command string. |
abstract String |
getSQLPhrase(int phrase)
Returns an sql phrase template for this database system. Templates for sql function expressions must contain a '?' character which will be replaced by the current column expression. If other parameters are necessary the template must contain placeholders like {0}, {1} etc. |
protected String |
getSQLTextString(DataType type,
Object value)
encodes Text values for an SQL command string. |
Timestamp |
getUpdateTimestamp(Connection conn)
Returns a timestamp that is used for record updates. |
String |
getValueString(Object value,
DataType type)
Creates a sql string for a given value. |
boolean |
isDDLColumnDefaults()
|
abstract boolean |
isSupported(DBDriverFeature type)
Returns whether or not a particular feature is supported by this driver |
protected void |
prepareStatement(PreparedStatement pstmt,
Object[] sqlParams,
Connection conn)
Prepares an sql statement by setting the supplied objects as parameters. |
void |
setDDLColumnDefaults(boolean ddlColumnDefaults)
Set true if column default values should be included in DDL Statements |
protected boolean |
stringToBoolean(String value)
this function converts a string containing a boolean expression to a boolean. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SQL_NULL_VALUE
public static final int SQL_PARAMETER
public static final int SQL_RENAME_TABLE
public static final int SQL_RENAME_COLUMN
public static final int SQL_DATABASE_LINK
public static final int SQL_QUOTES_OPEN
public static final int SQL_QUOTES_CLOSE
public static final int SQL_CONCAT_EXPR
public static final int SQL_BOOLEAN_TRUE
public static final int SQL_BOOLEAN_FALSE
public static final int SQL_CURRENT_DATE
public static final int SQL_DATE_PATTERN
public static final int SQL_DATE_TEMPLATE
public static final int SQL_CURRENT_DATETIME
public static final int SQL_DATETIME_PATTERN
public static final int SQL_DATETIME_TEMPLATE
public static final int SQL_FUNC_COALESCE
public static final int SQL_FUNC_SUBSTRING
public static final int SQL_FUNC_SUBSTRINGEX
public static final int SQL_FUNC_REPLACE
public static final int SQL_FUNC_REVERSE
public static final int SQL_FUNC_STRINDEX
public static final int SQL_FUNC_STRINDEXFROM
public static final int SQL_FUNC_LENGTH
public static final int SQL_FUNC_UPPER
public static final int SQL_FUNC_LOWER
public static final int SQL_FUNC_TRIM
public static final int SQL_FUNC_LTRIM
public static final int SQL_FUNC_RTRIM
public static final int SQL_FUNC_ESCAPE
public static final int SQL_FUNC_ABS
public static final int SQL_FUNC_ROUND
public static final int SQL_FUNC_TRUNC
public static final int SQL_FUNC_FLOOR
public static final int SQL_FUNC_CEILING
public static final int SQL_FUNC_DAY
public static final int SQL_FUNC_MONTH
public static final int SQL_FUNC_YEAR
public static final int SQL_FUNC_SUM
public static final int SQL_FUNC_MAX
public static final int SQL_FUNC_MIN
public static final int SQL_FUNC_AVG
public static final int SQL_FUNC_DECODE
public static final int SQL_FUNC_DECODE_SEP
public static final int SQL_FUNC_DECODE_PART
public static final int SQL_FUNC_DECODE_ELSE
protected boolean ddlColumnDefaults
protected static final char[] ILLEGAL_NAME_CHARS
protected static final String[] GENERAL_SQL_KEYWORDS
protected final Set<String> reservedSQLKeywords
Constructor Detail |
---|
public DBDatabaseDriver()
Method Detail |
---|
public abstract DBCommand createCommand(DBDatabase db)
db
- the database for which to create a command object for
public DBCommandExpr createCombinedCommand(DBCommandExpr left, String keyWord, DBCommandExpr right)
left
- the left commandkeyWord
- the key word (either "UNION" or "INTERSECT")left
- the right command
public abstract boolean isSupported(DBDriverFeature type)
type
- type of requested feature. @see DBDriverFeature
protected boolean detectQuoteName(String name)
public void appendElementName(StringBuilder sql, String name, boolean useQuotes)
sql
- the StringBuilder containing the SQL phrase.name
- the name of the object (table, view or column)useQuotes
- use quotes or notpublic final void appendElementName(StringBuilder sql, String name)
sql
- the StringBuilder containing the SQL phrase.name
- the name of the object (table, view or column)public abstract String getSQLPhrase(int phrase)
phrase
- the identifier of the phrase
public abstract String getConvertPhrase(DataType destType, DataType srcType, Object format)
destType
- the target data typesrcType
- the source data typeformat
- additional formatting information (optional)
public abstract Object getNextSequenceValue(DBDatabase db, String SeqName, int minValue, Connection conn)
db
- the databaseSeqName
- the name of the sequenceminValue
- the minimum value of the sequenceconn
- a valid database connection
public Object getColumnAutoValue(DBDatabase db, DBTableColumn column, Connection conn)
db
- the databasecolumn
- the column for which a value is requiredconn
- a valid database connection
protected void prepareStatement(PreparedStatement pstmt, Object[] sqlParams, Connection conn) throws SQLException
pstmt
- the prepared statementsqlParams
- list of objects
SQLException
protected void addStatementParam(PreparedStatement pstmt, int paramIndex, Object value, Connection conn) throws SQLException
pstmt
- the prepared statementparamIndex
- the parameter indexvalue
- the parameter valueconn
- the connection
SQLException
public String extractErrorMessage(SQLException e)
e
- the SQLException
public Object getResultValue(ResultSet rset, int columnIndex, DataType dataType) throws SQLException
Reads a single column value from the given JDBC ResultSet and returns a value object of desired data type.
See DBExpr.getValueClass(DataType)
for java class type mapping.
This gives the driver the opportunity to change the value i.e. to simulate missing data types with other types.
rset
- the sql Resultset with the current data rowcolumnIndex
- one based column Index of the desired columndataType
- the required data type
SQLException
- if a database access error occurspublic int executeSQL(String sqlCmd, Object[] sqlParams, Connection conn, DBDatabaseDriver.DBSetGenKeys genKeys) throws SQLException
sqlCmd
- the SQL-CommandsqlParams
- array of sql command parameters used for prepared statements (Optional).conn
- a valid connection to the database.genKeys
- allows to set the auto generated key of a record (INSERT statements only)
SQLException
- if a database access error occurspublic ResultSet executeQuery(String sqlCmd, Object[] sqlParams, boolean scrollable, Connection conn) throws SQLException
SQLException
protected void close(Statement stmt)
public String getValueString(Object value, DataType type)
value
- the value which is inserted to the new Stringtype
- the sql data type of the supplied value
protected String getSQLNumberString(Object value, DataType type)
value
- the numeric valuetype
- the number data type
protected String getSQLDateTimeString(Object value, int sqlTemplate, int sqlPattern, int sqlCurrentDate)
value
- sqlTemplate
- sqlPattern
- sqlCurrentDate
-
protected String getSQLTextString(DataType type, Object value)
type
- date type (can only be TEXT, CHAR, CLOB and UNIQUEID)value
- the text to be encoded
protected void appendSQLTextValue(StringBuilder buf, String value)
protected boolean stringToBoolean(String value)
value
- the string containing a boolean expression
protected void attachDatabase(DBDatabase db, Connection conn)
protected void detachDatabase(DBDatabase db, Connection conn)
public void checkDatabase(DBDatabase db, String owner, Connection conn)
db
- the databaseowner
- the ownerconn
- the connectionpublic void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
type
- operation to perform (CREATE, DROP, ALTER)dbo
- the object for which to perform the operation (DBDatabase, DBTable, DBView, DBColumn, DBRelation)script
- the script to which to add the DDL command(s)public void addEnableRelationStmt(DBRelation r, boolean enable, DBSQLScript script)
r
- the foreign key relation which should be enabled or disabledenable
- true to enable the relation or false to disablescript
- the script to which to add the DDL command(s)public boolean isDDLColumnDefaults()
true
if column default values are created with dll statements or false
if notpublic void setDDLColumnDefaults(boolean ddlColumnDefaults)
ddlColumnDefaults
- true
if dll statements should include
column default values or false
if notpublic Timestamp getUpdateTimestamp(Connection conn)
conn
- the connection that might be used
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |