Package org.apache.empire.dbms
Interface DBMSHandler
- All Known Implementing Classes:
DBMSHandlerBase,DBMSHandlerDerby,DBMSHandlerH2,DBMSHandlerHSql,DBMSHandlerMSSQL,DBMSHandlerMySQL,DBMSHandlerOracle,DBMSHandlerPostgreSQL,DBMSHandlerSQLite
public interface DBMSHandler
The DBMSHandler interface implements all RDBMS specific logic
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceThis interface is used to set the auto generated keys when executing insert statements. -
Method Summary
Modifier and TypeMethodDescriptionvoidappendEnableRelationStmt(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.voidappendObjectName(DBSQLBuilder sql, String name, Boolean useQuotes) Appends a table, view or column name to an SQL phrase.voidattachDatabase(DBDatabase db, Connection conn) Called when a database is openedbooleancheckExists(DBDatabase db, Connection conn) Checks if a database existsvoidcloseResultSet(ResultSet rset) Closes the provided JDBC Resultset Use it instead of rset.close() and stmt.close()createCombinedCommand(DBCommandExpr left, String keyWord, DBCommandExpr right) This function gives the dbms a chance to provide a custom implementation for a combined command such as UNION or INTERSECTcreateCommand(boolean autoPrepareStmt) This function creates a DBCommand for this DBMSCreates a DataModelChecker instance of this DBMSHandlercreateModelParser(String catalog, String schema) Creates a DataModelParser instance of this DBMSHandlerThis function creates a DBSQLBuilder for this DBMSvoiddetachDatabase(DBDatabase db, Connection conn) Called when a database is closedbooleandetectQuoteName(DBObject object, String name) Returns true if a name needs to be wrapped in quotes or false otherwiseint[]executeBatch(String[] sqlCmd, Object[][] sqlCmdParams, Connection conn) Executes a list of sql statements as batchexecuteQuery(String sqlCmd, Object[] sqlParams, boolean scrollable, Connection conn) Executes an select SQL-command and returns the query resultsintexecuteSQL(String sqlCmd, Object[] sqlParams, Connection conn, DBMSHandler.DBSetGenKeys genKeys) Executes an insert, update or delete SQL-commandExtracts native error message of an sqlExeption.getColumnAutoValue(DBDatabase db, DBTableColumn column, Connection conn) Returns an auto-generated value for a particular columngetConvertPhrase(DataType destType, DataType srcType, Object format) Returns a data type convertion phrase template for this dbms
The returned template must contain a '?'voidgetDDLScript(DBDDLGenerator.DDLActionType type, DBObject dbo, DBSQLScript script) Appends the required DLL commands to create, drop or alter an object to the supplied DBDQLScript.getIgnoreCaseExpr(DBColumnExpr columnExpr) Returns an expression that ignores the case of a column expression This is only called for case sensitive column expressions (expr.isCaseSensitive()) Default is upper(expr)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.getSQLPhrase(DBSqlPhrase phrase) Returns an sql phrase template for this database system.
Templates for sql function expressions must contain a '?'getUpdateTimestamp(Connection conn) Returns a DMBS-Timestamp that is used for record updates.booleanisSupported(DBMSFeature type) Returns whether or not a particular feature is supported by this dbmsquerySingleValue(String sqlCmd, Object[] sqlParams, DataType dataType, Connection conn) Executes an select SQL-command that returns only one scalar value if no row are returned by the query then ObjectUtils.NO_VALUE is returned
-
Method Details
-
checkExists
Checks if a database exists- Parameters:
db- the databaseconn- the Jdbc connection- Returns:
- true if database exists of false otherwise
-
attachDatabase
Called when a database is opened- Parameters:
db- the databaseconn- the Jdbc connection
-
detachDatabase
Called when a database is closed- Parameters:
db- the databaseconn- the Jdbc connection
-
createSQLBuilder
DBSQLBuilder createSQLBuilder()This function creates a DBSQLBuilder for this DBMS- Returns:
- a DBMS specific DBSQLBuilder object
-
createCommand
This function creates a DBCommand for this DBMS- Parameters:
autoPrepareStmt- whether or not the Command should automatically generate a prepared statement (using ?)- Returns:
- a DBMS specific DBCommand object
-
createCombinedCommand
This function gives the dbms a chance to provide a custom implementation for a combined command such as UNION or INTERSECT- Parameters:
left- the left commandkeyWord- the key word (either "UNION" or "INTERSECT")right- the right command- Returns:
- a DBCommandExpr object
-
isSupported
Returns whether or not a particular feature is supported by this dbms- Parameters:
type- type of requested feature. @see DBMSFeature- Returns:
- true if the features is supported or false otherwise
-
detectQuoteName
Returns true if a name needs to be wrapped in quotes or false otherwise- Parameters:
name- the name of the object (table, view or column)
-
appendObjectName
Appends a table, view or column name to an SQL phrase.- Parameters:
sql- the StringBuilder containing the SQL phrase.name- the name of the object (table, view or column)useQuotes- use quotes or not. When null is passed then detectQuoteName() is called
-
getSQLPhrase
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.- Parameters:
phrase- the identifier of the phrase- Returns:
- the phrase template
-
getConvertPhrase
Returns a data type convertion phrase template for this dbms
The returned template must contain a '?' which will be replaced by a column expression.- Parameters:
destType- the target data typesrcType- the source data typeformat- additional formatting information (optional)- Returns:
- the data conversion phrase template
-
getUpdateTimestamp
Returns a DMBS-Timestamp that is used for record updates.- Parameters:
conn- the connection that might be used- Returns:
- the current date and time.
-
getColumnAutoValue
Returns an auto-generated value for a particular column- Parameters:
db- the databasecolumn- the column for which a value is requiredconn- a valid database connection- Returns:
- the auto-generated value
-
getIgnoreCaseExpr
Returns an expression that ignores the case of a column expression This is only called for case sensitive column expressions (expr.isCaseSensitive()) Default is upper(expr)- Parameters:
columnExpr- the expression for which to ignore the case- Returns:
- the ignore case expression
-
querySingleValue
Object querySingleValue(String sqlCmd, Object[] sqlParams, DataType dataType, Connection conn) throws SQLException Executes an select SQL-command that returns only one scalar value if no row are returned by the query then ObjectUtils.NO_VALUE is returned- Parameters:
sqlCmd- the SQL-CommandsqlParams- array of sql command parameters used for prepared statements (Optional).dataType- the requested return typeconn- a valid connection to the database.- Returns:
- the scalar result value or ObjectUtils.NO_VALUE if no row are returned by the query
- Throws:
SQLException
-
executeSQL
int executeSQL(String sqlCmd, Object[] sqlParams, Connection conn, DBMSHandler.DBSetGenKeys genKeys) throws SQLException Executes an insert, update or delete SQL-command- Parameters:
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)- Returns:
- the row count for insert, update or delete or 0 for SQL statements that return nothing
- Throws:
SQLException- thrown if a database access error occurs
-
executeBatch
Executes a list of sql statements as batch- Parameters:
sqlCmd- the sql commandsqlCmdParams- the command paramsconn- the jdbc connection- Returns:
- the number of affected records
- Throws:
SQLException- thrown if a database access error occurs
-
executeQuery
ResultSet executeQuery(String sqlCmd, Object[] sqlParams, boolean scrollable, Connection conn) throws SQLException Executes an select SQL-command and returns the query results- Parameters:
sqlCmd- the SQL-CommandsqlParams- array of sql command parameters used for prepared statements (Optional).scrollable- true if scrollable or false otherwiseconn- a valid connection to the database.- Returns:
- the JDBC resultset
- Throws:
SQLException- thrown if a database access error occurs
-
getResultValue
Reads a single column value from the given JDBC ResultSet and returns a value object of desired data type. This gives the dbms the opportunity to change the value i.e. to simulate missing data types with other types.- Parameters:
rset- the sql Resultset with the current data rowcolumnIndex- one based column Index of the desired columndataType- the required data type- Returns:
- the value of the Column
- Throws:
SQLException- if a database access error occurs
-
closeResultSet
Closes the provided JDBC Resultset Use it instead of rset.close() and stmt.close()- Parameters:
rset- a ResultSet object
-
getDDLScript
Appends the required DLL commands to create, drop or alter an object to the supplied DBDQLScript.- Parameters:
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)
-
appendEnableRelationStmt
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.- Parameters:
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)
-
createModelParser
Creates a DataModelParser instance of this DBMSHandler- Parameters:
catalog- the database catalogschema- the database schema- Returns:
- the model parser
-
createModelChecker
Creates a DataModelChecker instance of this DBMSHandler- Parameters:
db- the database- Returns:
- the model checker
-
extractErrorMessage
Extracts native error message of an sqlExeption.- Parameters:
e- the SQLException- Returns:
- the error message of the database
-