|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sibvisions.rad.persist.jdbc.DBAccess
public class DBAccess
The DBAccess
is the implementation for most used SQL databases.
Standard ANSI SQL Databases are anyways supported.
Its used to read/write data between the storage and the DataBook/DataPage
.
It has database type specific implementations.
Example:
DBAccess dba = new DBAccess();
// set connect properties
dba.setDriver("org.hsqldb.jdbcDriver");
dba.setUrl("jdbc:hsqldb:file:testdbs/test/testdb");
dba.setUsername("sa");
dba.setPassword("");
Properties pDBProperties = new Properties();
pDBProperties.put("shutdown", true);
dba.setDBProperties(pDBProperties);
// open
dba.open();
To get Database independent DBAccess, it is better to use:
DBAccess dba = DBAccess.getDBAccess("jdbc:hsqldb:file:testdbs/test/testdb");
// insert data into test table
PreparedStatement psPreparedStatement = dba.getPreparedStatement(
"insert into test (id, name) values(?,?)", false);
psPreparedStatement.setInt(1, 1);
psPreparedStatement.setString(2, "projectX");
dba.executeUpdate(psPreparedStatement);
// select data from test table
psPreparedStatement = dba.getPreparedStatement("select * from test", false);
ResultSet rs = dba.executeQuery(psPreparedStatement);
while (rs.next())
{
System.out.println(rs.getInt("id") + "," + rs.getString("name"));
}
IDBAccess
,
RemoteDataBook
Nested Class Summary | |
---|---|
static class |
DBAccess.ColumnMetaDataInfo
The ColumnMetaDataInfo is caches information about column meta data requests. |
Field Summary | |
---|---|
protected static ILogger |
logger
The logger for protocol the performance. |
static int |
LONGNVARCHAR
A jdbc VARCHAR DB column data type constant. |
static int |
NCHAR
A jdbc VARCHAR DB column data type constant. |
static int |
NCLOB
A jdbc BLOB DB column data type constant. |
static int |
NVARCHAR
A jdbc VARCHAR DB column data type constant. |
static String |
QUOTE
JVx generell DB quote character. will be translated in the DB specific. |
static int |
SQLXML
A jdbc XML DB column data type constant. |
Constructor Summary | |
---|---|
DBAccess()
Constructs a new DBAccess Object. |
Method Summary | |
---|---|
void |
close()
Closes the database Connection and releases all memory. |
void |
commit()
Commits the DB transaction. |
protected Object |
convertDatabaseSpecificObjectToValue(ServerColumnMetaData pColumnMetaData,
Object pObject)
Enables the database specific implementation to handle/convert special objects. |
protected Object |
convertValueToDatabaseSpecificObject(Object pValue)
Converts an object to a standard value for the specific database. |
protected String |
createReplace(String pSource,
String pOld,
String pNew)
Create an DB specific replace command, which replacs in the pSource all pOld to pNew. |
protected String |
createWhereColumn(ServerMetaData pServerMetaData,
CompareCondition pCompare,
String pColumnName)
Creates the where column. |
protected String |
createWhereParam(ServerMetaData pServerMetaData,
CompareCondition pCompare)
Creates the where parameter. |
void |
delete(String pWriteBackTable,
ServerMetaData pServerMetaData,
Object[] pDelete)
Deletes the specified row. |
Object |
executeFunction(String pFunctionName,
int pReturnType,
Object... pParameters)
Executes a DB function with the specified parameters and return the result. |
void |
executeProcedure(String pProcedureName,
Object... pParameters)
Executes a DB procedure with the specified parameters. |
List<Object> |
executeSql(String pStatement,
Object... pParameters)
Executes a SQL command as prepared statement. |
void |
executeStatement(String pStatement)
Executes a DDL or DML Statement. |
int |
executeUpdate(PreparedStatement pSqlStatement)
Calls executesUpdate() for specified PreparedStatement
and returns the number of updated rows. |
List<Object[]> |
fetch(ServerMetaData pServerMetaData,
String pBeforeQueryColumns,
String[] pQueryColumns,
String pFromClause,
ICondition pFilter,
String pLastWhereCondition,
String pAfterWhereClause,
SortDefinition pSort,
int pFromRow,
int pMinimumRowCount)
Returns the List of fetched rows (as List of Object[]) for the specified query tables and parameters. |
protected SQLException |
formatSQLException(SQLException pSqlException)
Adds the SQL Error Code into the message of the SQL Exception. |
protected SQLException |
formatSQLException(SQLException pSqlException,
String pMessage,
String pCode)
Adds the SQL Error Code into the message of the SQL Exception. |
Hashtable<String,Object[]> |
getAllowedValues(String pCatalog,
String pSchema,
String pTable)
Gets the allowed values from a specific table. |
protected String |
getAutomaticLinkColumnName(ForeignKey pForeignKey)
Returns the automatic link column name for the specified ForeignKey and FK Column in the master table. |
static TranslationMap |
getAutomaticLinkColumnNameTranslation()
Returns the TranslationMap for the automatic link column name custom Translation. its used in the getAutomaticLinkColName(ForeignKey pForeignKey) to change the column, thats determined. |
DBAccess.ColumnMetaDataInfo |
getColumnMetaData(String pFromClause,
String[] pQueryColumns,
String pBeforeQueryColumns,
String pWhereClause,
String pAfterWhereClause,
String pWriteBackTable,
String[] pWriteBackColumns)
Returns the meta data information for the specified query, and configures all columns with defaults. |
Connection |
getConnection()
Returns the conncetion to the database. |
String |
getDatabaseSpecificLockStatement(String pWriteBackTable,
ServerMetaData pServerMetaData,
ICondition pPKFilter)
Returns the database specific statement to lock the specified row in the database. |
static DBAccess |
getDBAccess(Connection pConnection)
Gets the suitable DBAccess for the given connection. |
static DBAccess |
getDBAccess(DBCredentials pCredentials)
Gets the suitable DBAccess for the given DBCredentials . |
static DBAccess |
getDBAccess(String pJdbcUrl)
Gets the suitable DBAcces for the given JdbcUrl. |
Properties |
getDBProperties()
Returns the DB specific initial parameters for the Connection creation. |
String |
getDBProperty(String pName)
Gets the value for a specific database property. |
Object[] |
getDefaultAllowedValues(String pCatalog,
String pSchema,
String pTable,
ServerColumnMetaData pMetaData)
Gets the default allowed values for a given column from a given table. |
String |
getDefaultSchema()
Gets the default schema name, if it was set manually. |
Hashtable<String,Object> |
getDefaultValues(String pCatalog,
String pSchema,
String pTable)
Gets all default column values of a specific table. |
String |
getDriver()
Gets the database driver name as String . |
List<ForeignKey> |
getFKs(String pCatalog,
String pSchema,
String pTable)
Returns all Foreign Keys for the specified table. |
protected String |
getFromClause(String pWriteBackTable,
List<ForeignKey> auForeignKeys)
It creates and returns a from clause with joins over all foreign tables. |
int |
getMaxTime()
Returns the maximum time in miliseconds to use, to try to fetch all rows. reduce open cursors, and increase performance. |
String |
getPassword()
Sets the password to use for the connection to the database. |
Key |
getPK(String pCatalog,
String pSchema,
String pTable)
Gets all Primary Key columns and return it as list of Strings. |
PreparedStatement |
getPreparedStatement(String pSqlStatement,
boolean pReturnKey)
Return a PreparedStatement for the given SQL statement. |
protected String[] |
getQueryColumns(String pWriteBackTable,
List<ForeignKey> pForeignKeys,
String[] pWriteBackColumns)
It creates and returns the query columns, with all write back columns and includes the columns for the LinkReferences (automatic link celleditors). |
String |
getSelectStatement(ICondition pFilter,
String pFromClause,
String[] pQueryColumns,
String pBeforeQueryColumns,
String pWhereClause,
String pAfterWhereClause,
ServerMetaData pServerMetaData)
It initialize the select for a specified storage unit and return the SELECT statement. |
String |
getTableForSynonym(String pSynomyn)
Returns the full qualified table name incl. schema/catalog/db link for the given synonym. |
List<Key> |
getUKs(String pCatalog,
String pSchema,
String pTable)
It gets all columns for each Unique Key and return it. |
String |
getUrl()
Gets the jdbc url String for this database. |
String |
getUsername()
Gets the user name to connect with. |
String |
getWHEREClause(ICondition pFilter,
ServerMetaData pServerMetaData,
boolean pUsePrefix)
Returns the WHERE clause for a UPDATE, DELETE or SELECT statement specified with a Filter . |
Object[] |
insert(String pWriteBackTable,
ServerMetaData pServerMetaData,
Object[] pNewDataRow)
Returns the newly inserted row from the write back table. |
Object[] |
insertAnsiSQL(String pWriteBackTable,
String pInsertStatement,
ServerMetaData pServerMetaData,
Object[] pNewDataRow,
String pDummyColumn)
Returns the newly inserted row from a Ansi SQL Database. |
Object[] |
insertDatabaseSpecific(String pWriteBackTable,
String pInsertStatement,
ServerMetaData pServerMetaData,
Object[] pNewDataRow,
String pDummyColumn)
Returns the newly inserted row from an Database specific insert statement. |
boolean |
isAutoQuote(String pName)
It returns true if this name should be automated quoted. |
boolean |
isOpen()
Returns true, if the database is still open. |
boolean |
isTypeEqual(ServerColumnMetaData pServerColumnMetaData,
CompareCondition pCompare)
Check if the Type of the column and the value to compare is equal. |
void |
lockRow(String pWriteBackTable,
ServerMetaData pServerMetaData,
ICondition pPKFilter)
It locks the specified row in the storage. |
protected int |
lockRowInternal(String pWriteBackTable,
ServerMetaData pServerMetaData,
ICondition pPKFilter)
It locks the current row and return how many rows are affected. |
void |
open()
It opens the database and stores the Connection object. |
String |
quote(String pName)
Quotes a named DB object with our internal quote character, if it should be quoted in this database. |
String |
quoteAllways(String pName)
Quotes a named DB object with the JVx DB QUOTE character. |
static void |
registerDBAccessClass(String pJdbcUrlPrefix,
Class<? extends DBAccess> pClass)
Registers the Class for the jdbc url prefix. |
String |
removeDBSpecificQuotes(String pName)
Removes the DB specific quotes of a named DB object. |
static String |
removeQuotes(String pName)
Removes the JVx DB Quotes of a named DB object. |
void |
rollback()
Rollback the DB transaction. |
static void |
setAutomaticLinkColumnNameTranslation(TranslationMap pTranslationMap)
Sets the TranslationMap for the automatic link column name custom Translation. its used in the getAutomaticLinkColName(ForeignKey pForeignKey) to change the column, thats determined. |
protected int |
setColumnsToStore(PreparedStatement pInsert,
ServerColumnMetaData[] pServerColumnMetaData,
int[] iaWriteables,
Object[] pNew,
Object[] pOld)
Sets the values of all changed columns to store from the value Object[]s into the PreparedStatement and returns the last used parameter index. |
protected void |
setConnection(Connection pConnection)
Sets the internal conncetion to the database. |
protected boolean |
setDatabaseSpecificType(ResultSetMetaData pMetaData,
int pColumnIndex,
ServerColumnMetaData pColumnMetaData)
Enables the database specific implementation to change the metadata before the default settings are made. |
void |
setDBProperties(Properties pProperties)
Sets DB specific initial parameters for the Connection creation. |
void |
setDBProperty(String pName,
String pValue)
Sets a specific database property. |
void |
setDefaultSchema(String pSchema)
Sets the user-defined default schema. |
void |
setDriver(String pDriver)
Sets the database driver name as String . |
protected void |
setFilterParameter(int iStartParameterIndex,
PreparedStatement pStatement,
ICondition pFilter)
Sets all Filter parameter values into the PreparedStatement . |
void |
setMaxTime(int pMaxTime)
Sets the maximum time in miliseconds to use, to try to fetch all rows. reduce open cursors, and increase performance. |
void |
setPassword(String pPassword)
Sets the password to use for the connection to the database. |
void |
setQueryTimeOut(int pQueryTimeOut)
Sets the query time out. |
protected void |
setQuoteCharacters(String pOpen,
String pClose)
Sets the database specific quote characters. |
void |
setUrl(String pUrl)
Sets the url String for this database. |
void |
setUsername(String pUsername)
Sets the user name to connect with. |
protected String[] |
splitSchemaTable(String pFromClause)
Separates the schema and table from the given from clause. |
boolean |
supportsGetGeneratedKeys()
Returns if this Database specific supports generated keys. |
String |
toString()
|
protected Object |
translateDefaultValue(String pColumnName,
int pDataType,
String pDefaultValue)
Translates a default value from a column to the datatype object. |
String |
translateQuotes(String pStatement)
It replaces all JVx quotes with the database specific quote. |
protected Object |
translateValue(int pDataType,
String pValue)
Translates an object value to the datatype object. |
Object[] |
update(String pWriteBackTable,
ServerMetaData pServerMetaData,
Object[] pOld,
Object[] pNew)
Return the updated row. |
int |
updateAnsiSQL(String pWriteBackTable,
String sUpdateStatement,
ServerMetaData pServerMetaData,
Object[] pOld,
Object[] pNew,
ICondition pPKFilter)
Updates the specified row and return the count of affected rows. |
int |
updateDatabaseSpecific(String pWriteBackTable,
String sUpdateStatement,
ServerMetaData pServerMetaData,
Object[] pOld,
Object[] pNew,
ICondition pPKFilter)
Updates the specified row and return the count of affected rows. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int NCHAR
public static final int NVARCHAR
public static final int LONGNVARCHAR
public static final int SQLXML
public static final int NCLOB
public static final String QUOTE
protected static ILogger logger
Constructor Detail |
---|
public DBAccess()
Method Detail |
---|
public static DBAccess getDBAccess(String pJdbcUrl) throws DataSourceException
pJdbcUrl
- the JdbcUrl.
DataSourceException
- if the instance name is unknown or the DBAccess object cannot be created.public static DBAccess getDBAccess(DBCredentials pCredentials) throws DataSourceException
DBCredentials
.
pCredentials
- the database credentials.
DataSourceException
- if the instance name is unknown or the DBAccess object cannot be created.public static DBAccess getDBAccess(Connection pConnection) throws DataSourceException
pConnection
- the database connection.
DataSourceException
- if the instance name is unknown or the DBAccess object cannot be created.public static void registerDBAccessClass(String pJdbcUrlPrefix, Class<? extends DBAccess> pClass)
pJdbcUrlPrefix
- the jdbc url prefix.pClass
- the Class.public static void setAutomaticLinkColumnNameTranslation(TranslationMap pTranslationMap)
pTranslationMap
- the TranslationMap to use.public static TranslationMap getAutomaticLinkColumnNameTranslation()
protected String getFromClause(String pWriteBackTable, List<ForeignKey> auForeignKeys) throws DataSourceException
pWriteBackTable
- the write back table to useauForeignKeys
- the ForeignKey array to use
DataSourceException
- if an error occur in determining the from clause and query columns.protected String getAutomaticLinkColumnName(ForeignKey pForeignKey)
pForeignKey
- the ForeignKEy to use.
setAutomaticLinkColumnNameTranslation(TranslationMap)
protected String[] getQueryColumns(String pWriteBackTable, List<ForeignKey> pForeignKeys, String[] pWriteBackColumns) throws DataSourceException
pWriteBackTable
- the write back table to usepForeignKeys
- the ForeignKey array to usepWriteBackColumns
- the write back table columns to use.
DataSourceException
- if an error occur in determining the from clause and query columns.public List<Key> getUKs(String pCatalog, String pSchema, String pTable) throws DataSourceException
pCatalog
- the catalog to usepSchema
- the schema to usepTable
- the table to use
DataSourceException
- if an error occur during UK search process.public Key getPK(String pCatalog, String pSchema, String pTable) throws DataSourceException
pCatalog
- the catalog to usepSchema
- the schema to usepTable
- the table to use
DataSourceException
- if an error occur during PK search process.public List<ForeignKey> getFKs(String pCatalog, String pSchema, String pTable) throws DataSourceException
pCatalog
- the catalog to usepSchema
- the schema to usepTable
- the table to use as base table.
DataSourceException
- if an error occur in determining the ForeignKeys.public String getTableForSynonym(String pSynomyn) throws DataSourceException
pSynomyn
- the synonym to use.
DataSourceException
- if an error occur in determining the synonyms.public List<Object[]> fetch(ServerMetaData pServerMetaData, String pBeforeQueryColumns, String[] pQueryColumns, String pFromClause, ICondition pFilter, String pLastWhereCondition, String pAfterWhereClause, SortDefinition pSort, int pFromRow, int pMinimumRowCount) throws DataSourceException
fetch
in interface IDBAccess
pServerMetaData
- the MetaDataColumn array to use.pBeforeQueryColumns
- the before query columnspQueryColumns
- the query columnspFromClause
- the from clause with query tables and join definitionspFilter
- the filter to usepLastWhereCondition
- the last where condition in querypAfterWhereClause
- the after where clause in querypSort
- the sort order to usepFromRow
- the row index from to fetchpMinimumRowCount
- the minimum count row to fetch
DataSourceException
- if the fetch fails.public void lockRow(String pWriteBackTable, ServerMetaData pServerMetaData, ICondition pPKFilter) throws DataSourceException
lockRow
in interface IDBAccess
pWriteBackTable
- the storage unit to usepServerMetaData
- the MetaDataColumn array to use.pPKFilter
- the PrimaryKey in as an ICondition
to identify the row to lock
DataSourceException
- if an Exception
occur during interacting with the storageprotected int lockRowInternal(String pWriteBackTable, ServerMetaData pServerMetaData, ICondition pPKFilter) throws DataSourceException
pWriteBackTable
- the storage unit to usepPKFilter
- the PrimaryKey in as an ICondition
to identify the row to lockpServerMetaData
- the MetaDataColumn array to use.
DataSourceException
- if an Exception
occur during interacting with the storagepublic Object[] insert(String pWriteBackTable, ServerMetaData pServerMetaData, Object[] pNewDataRow) throws DataSourceException
insert
in interface IDBAccess
pWriteBackTable
- the write back table to use.pServerMetaData
- the meta data to use.pNewDataRow
- the new values Object[] to insert.
DataSourceException
- if an Exception
occur during insert the row to the tablepublic Object[] update(String pWriteBackTable, ServerMetaData pServerMetaData, Object[] pOld, Object[] pNew) throws DataSourceException
update
in interface IDBAccess
pWriteBackTable
- the write back table to use.pServerMetaData
- the meta data to use.pOld
- the old values of the rowpNew
- the new values of the row
DataSourceException
- if an Exception
occur during update.public int updateDatabaseSpecific(String pWriteBackTable, String sUpdateStatement, ServerMetaData pServerMetaData, Object[] pOld, Object[] pNew, ICondition pPKFilter) throws DataSourceException
pWriteBackTable
- the table to use for the updatesUpdateStatement
- the SQL Statement to use for the updatepServerMetaData
- the meta data to use.pOld
- the old row (values) to use.pNew
- the new row (values) to use.pPKFilter
- the PrimaryKey equals filter to use.
DataSourceException
- if an Exception
occur during update to the storagepublic int updateAnsiSQL(String pWriteBackTable, String sUpdateStatement, ServerMetaData pServerMetaData, Object[] pOld, Object[] pNew, ICondition pPKFilter) throws DataSourceException
pWriteBackTable
- the table to use for the updatesUpdateStatement
- the SQL Statement to use for the updatepServerMetaData
- the meta data to use.pOld
- the old row (values) to use.pNew
- the new row (values) to use.pPKFilter
- the PrimaryKey equals filter to use.
DataSourceException
- if an Exception
occur during update to the storagepublic void delete(String pWriteBackTable, ServerMetaData pServerMetaData, Object[] pDelete) throws DataSourceException
delete
in interface IDBAccess
pWriteBackTable
- the write back table to use.pServerMetaData
- the meta data to use.pDelete
- the row to delete.
DataSourceException
- if an Exception
occur during delete.public String toString()
toString
in class Object
protected void setQuoteCharacters(String pOpen, String pClose)
pOpen
- the open quote characterpClose
- the close quote characterpublic boolean isAutoQuote(String pName)
pName
- the name to quote.
public String quote(String pName)
pName
- the name to use.
public String quoteAllways(String pName)
pName
- the name to use.
public static String removeQuotes(String pName)
pName
- the name to use.
public String removeDBSpecificQuotes(String pName)
pName
- the name to use.
public String translateQuotes(String pStatement)
pStatement
- the statement to use.
public void open() throws DataSourceException
Connection
object.
DataSourceException
- if the database couldn't openedpublic boolean isOpen() throws DataSourceException
DataSourceException
- if isClosed() on the DB Connection
throws an Exceptionpublic void close() throws DataSourceException
Connection
and releases all memory.
DataSourceException
- if database couldn't closed.public void rollback() throws DataSourceException
DataSourceException
- if the transaction couldn't rollbackpublic void commit() throws DataSourceException
DataSourceException
- if the transaction couldn't commitpublic void setQueryTimeOut(int pQueryTimeOut)
pQueryTimeOut
- the timeout in milisecondspublic Connection getConnection()
conncetion
to the database.
conncetion
to the database.protected void setConnection(Connection pConnection)
conncetion
to the database.
pConnection
- the conncetion
to the databasepublic String getDriver()
String
.
public void setDriver(String pDriver)
String
.
pDriver
- the database driver namepublic String getUrl()
String
for this database.
String
.public void setUrl(String pUrl)
String
for this database.
pUrl
- the jdbc url String
.public String getUsername()
public void setUsername(String pUsername)
pUsername
- the user namepublic String getPassword()
public void setPassword(String pPassword)
pPassword
- the password to use for the databasepublic void setDBProperty(String pName, String pValue)
pName
- the property namepValue
- th valuepublic String getDBProperty(String pName)
pName
- the property name
null
if the property was not foundpublic void setDBProperties(Properties pProperties)
Connection
creation.
pProperties
- DB specific initial parameterspublic Properties getDBProperties()
Connection
creation.
Connection
creation.public int getMaxTime()
public void setMaxTime(int pMaxTime)
pMaxTime
- the iMaxTime to setpublic void executeProcedure(String pProcedureName, Object... pParameters) throws DataSourceException
pProcedureName
- the procedure (optional with package) name.pParameters
- the parameters to use with the correct and corresponding java type.
DataSourceException
- if the call failed.public Object executeFunction(String pFunctionName, int pReturnType, Object... pParameters) throws DataSourceException
pFunctionName
- the function (optional with package) name.pReturnType
- the return SQL Type (see Types
pParameters
- the parameters to use with the correct and corresponding java type.
DataSourceException
- if the call failed.public void executeStatement(String pStatement) throws SQLException
pStatement
- the statement.
SQLException
- if an error occur during execution.public List<Object> executeSql(String pStatement, Object... pParameters) throws SQLException
pStatement
- the statement with or without parameterspParameters
- the parameters to use
null
if the command returned no
result
SQLException
- if an error occurs during executionpublic PreparedStatement getPreparedStatement(String pSqlStatement, boolean pReturnKey) throws DataSourceException
PreparedStatement
for the given SQL statement.
pSqlStatement
- the SQL statement to preparepReturnKey
- if the generated key in insert statements should returned
PreparedStatement
for the given SQL statement.
DataSourceException
- if the statement couldn't prepared.public int executeUpdate(PreparedStatement pSqlStatement) throws DataSourceException
executesUpdate()
for specified PreparedStatement
and returns the number of updated rows.
pSqlStatement
- the PreparedStatement
to use
DataSourceException
- if the statement couldn't updated.protected SQLException formatSQLException(SQLException pSqlException)
pSqlException
- the SQL Exception to use.
protected SQLException formatSQLException(SQLException pSqlException, String pMessage, String pCode)
pSqlException
- the SQL Exception to use.pMessage
- the message to usepCode
- the detected error code
public String getSelectStatement(ICondition pFilter, String pFromClause, String[] pQueryColumns, String pBeforeQueryColumns, String pWhereClause, String pAfterWhereClause, ServerMetaData pServerMetaData) throws DataSourceException
pFilter
- the Filter
to usepFromClause
- the list of query tables to use in the SELECT statement.pQueryColumns
- the list of query columns to use in the SELECT statement.pBeforeQueryColumns
- the string to place in the SELECT statement between the SELECT and the first query column.pWhereClause
- the string to place in the SELECT statement after the last WHERE condition from the
Filter or MasterReference (Master-Detail Condition).pAfterWhereClause
- the string to place in the SELECT statement after the WHERE clause and before the ORDER BY clause.pServerMetaData
- the MetaDataColumn array to use.
DataSourceException
- if it's not possible to build the select statement in fact of missing elementspublic String getDatabaseSpecificLockStatement(String pWriteBackTable, ServerMetaData pServerMetaData, ICondition pPKFilter) throws DataSourceException
pWriteBackTable
- the table to use.pPKFilter
- the PK filter with the values to use.pServerMetaData
- the MetaDataColumn array to use.
DataSourceException
- if some parts are missing for the statementpublic Object[] insertDatabaseSpecific(String pWriteBackTable, String pInsertStatement, ServerMetaData pServerMetaData, Object[] pNewDataRow, String pDummyColumn) throws DataSourceException
pWriteBackTable
- the table to use for the insertpInsertStatement
- the SQL Statement to use for the insertpServerMetaData
- the meta data to use.pNewDataRow
- the new row (Object[]) with the values to insertpDummyColumn
- null
, if all writeable columns are null, but for a correct INSERT it have
to be minimum one column to use in the syntax.
DataSourceException
- if an Exception
occur during insert to the storagepublic boolean supportsGetGeneratedKeys()
public Object[] insertAnsiSQL(String pWriteBackTable, String pInsertStatement, ServerMetaData pServerMetaData, Object[] pNewDataRow, String pDummyColumn) throws DataSourceException
pWriteBackTable
- the table to use for the insertpInsertStatement
- the SQL Statement to use for the insertpServerMetaData
- the meta data to use.pNewDataRow
- the new row (Object[]) with the values to insertpDummyColumn
- true, if all writeable columns are null, but for a correct INSERT it have
to be minimum one column to use in the syntax.
DataSourceException
- if an Exception
occur during insert to the storagepublic DBAccess.ColumnMetaDataInfo getColumnMetaData(String pFromClause, String[] pQueryColumns, String pBeforeQueryColumns, String pWhereClause, String pAfterWhereClause, String pWriteBackTable, String[] pWriteBackColumns) throws DataSourceException
pBeforeQueryColumns
- the before query columnspQueryColumns
- the query columnspFromClause
- the from clause with query tables and join definitionspWhereClause
- the last where condition in querypAfterWhereClause
- the after where clause in querypWriteBackTable
- the write back table to use for the isWriteable() state (Optional)pWriteBackColumns
- the write back columns to use for the isWriteable() state (Optional)
DataSourceException
- if an Exception
occur during getting the meta data or
if the storage is not opened or
if one columns SQL type is not supportedpublic String getWHEREClause(ICondition pFilter, ServerMetaData pServerMetaData, boolean pUsePrefix) throws DataSourceException
Filter
.
pFilter
- the Filter
to usepServerMetaData
- the MetaData
to usepUsePrefix
- true
to use the prefixed column (real column name) and false
to
ignore prefixes (the simple name of the column)
Filter
.
DataSourceException
- if columns not existingprotected void setFilterParameter(int iStartParameterIndex, PreparedStatement pStatement, ICondition pFilter) throws DataSourceException
Filter
parameter values into the PreparedStatement
.
iStartParameterIndex
- the start index for the parameters to set.pStatement
- the PreparedStatement
to initializepFilter
- the Filter
to get the values
DataSourceException
- if the values can't set into the PreparedStatement
protected int setColumnsToStore(PreparedStatement pInsert, ServerColumnMetaData[] pServerColumnMetaData, int[] iaWriteables, Object[] pNew, Object[] pOld) throws DataSourceException
PreparedStatement
and returns the last used parameter index.
pInsert
- the PreparedStatement
to initializepServerColumnMetaData
- the column meta data to use.iaWriteables
- the writable columns as int index arraypNew
- the new values Object[]pOld
- the old values Object[]
PreparedStatement
.
DataSourceException
- if the values can't set into the PreparedStatement
public Hashtable<String,Object> getDefaultValues(String pCatalog, String pSchema, String pTable) throws DataSourceException
pCatalog
- the catalog namepSchema
- the schema namepTable
- the table name
Hashtable
with the column name as key and the default value as value. It only contains columns
with a default value
DataSourceException
- if the database access throws an exceptionprotected Object translateDefaultValue(String pColumnName, int pDataType, String pDefaultValue) throws Exception
pColumnName
- the column name to translatepDataType
- the datatype of the columnpDefaultValue
- the original default value from the database
null
if the default value is not valid
Exception
- if the type translation causes an error or the datatype is not supportedprotected Object translateValue(int pDataType, String pValue) throws Exception
pDataType
- the datatype of the columnpValue
- the value from the database
null
if the value is not valid
Exception
- if the type translation causes an error or the datatype is not supportedpublic Hashtable<String,Object[]> getAllowedValues(String pCatalog, String pSchema, String pTable) throws DataSourceException
pCatalog
- the catalog namepSchema
- the schema namepTable
- the table to check
Hashtable
with a column name as key and the allowed values as array of Object
s or
null
if there are no allowed values
DataSourceException
- if the database access throws an exceptionpublic Object[] getDefaultAllowedValues(String pCatalog, String pSchema, String pTable, ServerColumnMetaData pMetaData)
pCatalog
- the catalog namepSchema
- the schema namepTable
- the table to checkpMetaData
- the column meta data
null
if there are no default valuesprotected String createReplace(String pSource, String pOld, String pNew)
pSource
- the source to replace.pOld
- the old value.pNew
- the new value.
protected String createWhereParam(ServerMetaData pServerMetaData, CompareCondition pCompare)
pServerMetaData
- the server metadatapCompare
- the compare condition
protected String createWhereColumn(ServerMetaData pServerMetaData, CompareCondition pCompare, String pColumnName)
pServerMetaData
- the server metadatapCompare
- the compare conditionpColumnName
- the column name to use
public boolean isTypeEqual(ServerColumnMetaData pServerColumnMetaData, CompareCondition pCompare)
pServerColumnMetaData
- the server column meta data for the column to compare.pCompare
- the compare condition to use.
protected String[] splitSchemaTable(String pFromClause)
pFromClause
- the from clause
public void setDefaultSchema(String pSchema)
pSchema
- the schema namegetDefaultSchema()
public String getDefaultSchema()
setDefaultSchema(String)
protected Object convertDatabaseSpecificObjectToValue(ServerColumnMetaData pColumnMetaData, Object pObject)
pColumnMetaData
- the column metadatapObject
- the read object
protected Object convertValueToDatabaseSpecificObject(Object pValue)
pValue
- any value
protected boolean setDatabaseSpecificType(ResultSetMetaData pMetaData, int pColumnIndex, ServerColumnMetaData pColumnMetaData) throws SQLException
pMetaData
- the metadata from the resultsetpColumnIndex
- the column index in the resultset metadatapColumnMetaData
- the newly created and pre-configured column metadata
true
if column metadata are changed and the default settings should not be applied,
false
to apply the standard settings
SQLException
- if metadata access fails
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |