|
||||||||||
| 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| Field Summary | |
|---|---|
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 | |
|---|---|
static void |
clearMetaData()
Clears the meta data cache. |
static void |
clearMetaData(String pApplicationName)
Clears the meta data cache for the given application. |
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. |
static String |
createIdentifier(Object... pIdentifier)
Creates an identifier string from the given parameter. |
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. |
protected static void |
debug(Object... pInfo)
Logs debug information. |
void |
delete(String pWriteBackTable,
ServerMetaData pServerMetaData,
Object[] pDelete)
Deletes the specified row. |
protected static void |
error(Object... pInfo)
Logs error information. |
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 pWhereCondition,
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. |
List<Object[]> |
fetch(ServerMetaData pServerMetaData,
String pBeforeQueryColumns,
String[] pQueryColumns,
String pFromClause,
ICondition pFilter,
String pWhereCondition,
String pAfterWhereClause,
SortDefinition pSort,
int pFromRow,
int pMinimumRowCount,
boolean pAllowLazyFetch)
Returns the List of fetched rows (as List of Object[]) for the specified query tables and parameters. |
List<Object[]> |
fetch(ServerMetaData pServerMetaData,
String pBeforeQueryColumns,
String[] pQueryColumns,
String pFromClause,
ICondition pFilter,
String pWhereCondition,
String pAfterWhereClause,
SortDefinition pSort,
String pOrderByClause,
int pFromRow,
int pMinimumRowCount)
Mostly same as fetch(ServerMetaData, String, String[], String, ICondition, String, String, SortDefinition, int, int). |
List<Object[]> |
fetch(ServerMetaData pServerMetaData,
String pBeforeQueryColumns,
String[] pQueryColumns,
String pFromClause,
ICondition pFilter,
String pWhereCondition,
String pAfterWhereClause,
SortDefinition pSort,
String pOrderByClause,
int pFromRow,
int pMinimumRowCount,
boolean pAllowLazyFetch)
Mostly same as fetch(ServerMetaData, String, String[], String, ICondition, String, String, SortDefinition, int, int). |
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. |
Map<String,Object[]> |
getAllowedValues(String pCatalog,
String pSchema,
String pTable)
Gets the allowed values from a specific table. |
protected Map<String,Object[]> |
getAllowedValuesIntern(String pCatalog,
String pSchema,
String pTable)
Gets the allowed values from a specific 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. |
String |
getCloseQuoteCharacter()
Gets the database specific quote character. |
ServerColumnMetaData[] |
getColumnMetaData(String pFromClause,
String[] pQueryColumns,
String pBeforeQueryColumns,
String pWhereClause,
String pAfterWhereClause)
Returns the meta data information for the specified query, and configures all columns with defaults. |
protected ServerColumnMetaData[] |
getColumnMetaDataIntern(String pFromClause,
String[] pQueryColumns,
String pBeforeQueryColumns,
String pWhereClause,
String pAfterWhereClause)
Returns the meta data information for the specified query, and configures all columns with defaults. |
protected String |
getColumnName(ResultSetMetaData pMetaData,
int pColumn)
Gets the column name from the given resultset metadata. |
Connection |
getConnection()
Returns the conncetion to the database. |
protected 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 external 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. |
static long |
getDefaultLargeObjectLimit()
Gets the default value for the limit for what is considered a "large object". |
String |
getDefaultSchema()
Gets the default schema name, if it was set manually. |
Map<String,Object> |
getDefaultValues(String pCatalog,
String pSchema,
String pTable)
Gets all default column values of a specific table. |
protected Map<String,Object> |
getDefaultValuesIntern(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> |
getForeignKeys(String pCatalog,
String pSchema,
String pTable)
Returns all Foreign Keys for the specified table. |
protected List<ForeignKey> |
getForeignKeysIntern(String pCatalog,
String pSchema,
String pTable)
Returns all Foreign Keys for the specified table. |
protected String |
getIdentifier()
Gets the identifier for this DBAccess. |
long |
getLargeObjectLimit()
Gets the value for the limit for what is considered a "large object". |
int |
getMaxColumnLength()
Returns the maximum allowed column length. |
int |
getMaxTime()
Returns the maximum time in miliseconds to use, to try to fetch all rows. reduce open cursors, and increase performance. |
MetaDataCacheOption |
getMetaDataCacheOption()
Gets the metadata cache option for this instance. |
String |
getOpenQuoteCharacter()
Gets the database specific open quote character. |
protected Object[] |
getParameter(ICondition cCondition)
Returns the parameters used for this ICondition. |
String |
getPassword()
Sets the password to use for the connection to the database. |
PreparedStatement |
getPreparedStatement(String pSqlStatement,
boolean pReturnKey)
Return a PreparedStatement for the given SQL statement. |
Key |
getPrimaryKey(String pCatalog,
String pSchema,
String pTable)
It's gets all Primary Key columns and return it as String[]. |
protected Key |
getPrimaryKeyIntern(String pCatalog,
String pSchema,
String pTable)
It's gets all Primary Key columns and return it as String[]. |
int |
getQueryTimeOut()
Gets the query time out. |
String |
getSelectStatement(ServerMetaData pServerMetaData,
String pBeforeQueryColumns,
String[] pQueryColumns,
String pFromClause,
ICondition pFilter,
String pWhereClause,
String pAfterWhereClause,
SortDefinition pSort,
String pOrderByClause)
It initialize the select for a specified storage unit and return the SELECT statement. |
protected String |
getSQL(ServerMetaData pServerMetaData,
ICondition pCondition,
boolean pUseRealColumnName)
Returns the ANSI SQL String for this ICondition. |
String |
getTableForSynonym(String pSynomyn)
Returns the full qualified table name incl. schema/catalog/db link for the given synonym. |
protected String |
getTableForSynonymIntern(String pSynomyn)
Returns the full qualified table name incl. schema/catalog/db link for the given synonym. |
TableInfo |
getTableInfo(String pWriteBackTable)
Returns the meta data information for the specified query, and configures all columns with defaults. |
protected TableInfo |
getTableInfoIntern(String pWriteBackTable)
Returns the meta data information for the specified query, and configures all columns with defaults. |
List<Key> |
getUniqueKeys(String pCatalog,
String pSchema,
String pTable)
It gets all columns for each Unique Key and return it. |
protected List<Key> |
getUniqueKeysIntern(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. |
protected String |
getWhereClause(ServerMetaData pServerMetaData,
ICondition pFilter,
String pWhereClause,
boolean pUsePrefix)
Returns the WHERE clause for a UPDATE, DELETE or SELECT statement specified with a Filter. |
protected static void |
info(Object... pInfo)
Logs information. |
Object[] |
insert(String pWriteBackTable,
ServerMetaData pServerMetaData,
Object[] pNewDataRow)
Returns the newly inserted row from the write back table. |
protected Object[] |
insertAnsiSQL(String pWriteBackTable,
String pInsertStatement,
ServerMetaData pServerMetaData,
Object[] pNewDataRow,
String pDummyColumn)
Returns the newly inserted row from a Ansi SQL Database. |
protected Object[] |
insertDatabaseSpecific(String pWriteBackTable,
String pInsertStatement,
ServerMetaData pServerMetaData,
Object[] pNewDataRow,
String pDummyColumn)
Returns the newly inserted row from a Database specific insert statement. |
boolean |
isAutoCommit()
Gets whether auto-commit is en-/disabled. |
boolean |
isAutoQuote(String pName)
It returns true if this name should be automated quoted. |
static boolean |
isJdbc(String pUrl)
Gets whether the given URL is a JDBC resource. |
protected static boolean |
isLogEnabled(ILogger.LogLevel pLevel)
Gets whether the given log level is enabled. |
protected boolean |
isMetaDataCacheEnabled()
Gets whether the meta data cache should be used. |
boolean |
isModified()
Gets whether the database access is modified. |
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. |
void |
setAutoCommit(boolean pEnable)
Sets auto-commit state. |
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. |
static void |
setDefaultLargeObjectLimit(long pDefaultLargeObjectLimit)
Sets the default value for the limit for what is considered a "large object". |
void |
setDefaultSchema(String pSchema)
Sets the user-defined default schema. |
void |
setDriver(String pDriver)
Sets the database driver name as String. |
void |
setLargeObjectLimit(long pLargeObjectLimit)
Sets the value for the limit for what is considered a "large object". |
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 |
setMetaDataCacheOption(MetaDataCacheOption pOption)
Sets the metadata cache option for this instance. |
protected void |
setModified(boolean pModified)
Sets modified state of the connection. |
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 returns 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
| 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 long getDefaultLargeObjectLimit()
fetchLargObjectsLazy
option set to determine if the current object should be lazily fetched or not.
"Lazy" means that the object is only send to the client if the value
is actually requested. It is still fetched from the datasource and
cached on the server side.
Note that the default limit is only applied to new instances of DBAccess.
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()
public static void setDefaultLargeObjectLimit(long pDefaultLargeObjectLimit)
fetchLargObjectsLazy
option set to determine if the current object should be lazily fetched or not.
"Lazy" means that the object is only send to the client if the value
is actually requested. It is still fetched from the datasource and
cached on the server side.
Note that the default limit is only applied to new instances of DBAccess.
pDefaultLargeObjectLimit - the new default limit.
protected List<Key> getUniqueKeysIntern(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 long getLargeObjectLimit()
fetchLargObjectsLazy option set to determine
if the current object should be lazily fetched or not.
"Lazy" means that the object is only send to the client if the value is
actually requested. It is still fetched from the datasource and cached on
the server side.
protected Key getPrimaryKeyIntern(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.
protected List<ForeignKey> getForeignKeysIntern(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 final List<Key> getUniqueKeys(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 final Key getPrimaryKey(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 final List<ForeignKey> getForeignKeys(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 final String getTableForSynonym(String pSynomyn)
throws DataSourceException
pSynomyn - the synonym to use.
DataSourceException - if an error occur in determining the synonyms.
protected String getTableForSynonymIntern(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 pWhereCondition,
String pAfterWhereClause,
SortDefinition pSort,
int pFromRow,
int pMinimumRowCount,
boolean pAllowLazyFetch)
throws DataSourceException
fetch in interface IDBAccesspServerMetaData - 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 usepWhereCondition - 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 fetchpAllowLazyFetch - if lazy fetch should be allowed.
DataSourceException - if the fetch fails.
public List<Object[]> fetch(ServerMetaData pServerMetaData,
String pBeforeQueryColumns,
String[] pQueryColumns,
String pFromClause,
ICondition pFilter,
String pWhereCondition,
String pAfterWhereClause,
SortDefinition pSort,
int pFromRow,
int pMinimumRowCount)
throws DataSourceException
pBeforeQueryColumns - the before query columnspQueryColumns - the query columnspFromClause - the from clause with query tables and join definitionspFilter - the filter to usepWhereCondition - 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 fetchpServerMetaData - the MetaDataColumn array to use.
DataSourceException - if the fetch fails.
public List<Object[]> fetch(ServerMetaData pServerMetaData,
String pBeforeQueryColumns,
String[] pQueryColumns,
String pFromClause,
ICondition pFilter,
String pWhereCondition,
String pAfterWhereClause,
SortDefinition pSort,
String pOrderByClause,
int pFromRow,
int pMinimumRowCount)
throws DataSourceException
fetch(ServerMetaData, String, String[], String, ICondition, String, String, SortDefinition, int, int).
This fetch does accept an additional order by clause which will be used
if the given default sort is null.
pBeforeQueryColumns - the before query columnspQueryColumns - the query columnspFromClause - the from clause with query tables and join definitionspFilter - the filter to usepWhereCondition - the last where condition in querypAfterWhereClause - the after where clause in querypOrderByClause - the order by clausepSort - the sort order to usepFromRow - the row index from to fetchpMinimumRowCount - the minimum count row to fetchpServerMetaData - the MetaDataColumn array to use.
DataSourceException - if the fetch fails.
public List<Object[]> fetch(ServerMetaData pServerMetaData,
String pBeforeQueryColumns,
String[] pQueryColumns,
String pFromClause,
ICondition pFilter,
String pWhereCondition,
String pAfterWhereClause,
SortDefinition pSort,
String pOrderByClause,
int pFromRow,
int pMinimumRowCount,
boolean pAllowLazyFetch)
throws DataSourceException
fetch(ServerMetaData, String, String[], String, ICondition, String, String, SortDefinition, int, int).
This fetch does accept an additional order by clause which will be used
if the given default sort is null.
pBeforeQueryColumns - the before query columnspQueryColumns - the query columnspFromClause - the from clause with query tables and join definitionspFilter - the filter to usepWhereCondition - the last where condition in querypAfterWhereClause - the after where clause in querypOrderByClause - the order by clausepSort - the sort order to usepFromRow - the row index from to fetchpMinimumRowCount - the minimum count row to fetchpServerMetaData - the MetaDataColumn array to use.pAllowLazyFetch - if lazy fetch should be allowed.
DataSourceException - if the fetch fails.
public void lockRow(String pWriteBackTable,
ServerMetaData pServerMetaData,
ICondition pPKFilter)
throws DataSourceException
lockRow in interface IDBAccesspWriteBackTable - 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 storage
protected 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 storage
public Object[] insert(String pWriteBackTable,
ServerMetaData pServerMetaData,
Object[] pNewDataRow)
throws DataSourceException
insert in interface IDBAccesspWriteBackTable - 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 void setLargeObjectLimit(long pLargeObjectLimit)
fetchLargObjectsLazy option set to determine
if the current object should be lazily fetched or not.
"Lazy" means that the object is only send to the client if the value is
actually requested. It is still fetched from the datasource and cached on
the server side.
pLargeObjectLimit - the new limit.
public Object[] update(String pWriteBackTable,
ServerMetaData pServerMetaData,
Object[] pOld,
Object[] pNew)
throws DataSourceException
update in interface IDBAccesspWriteBackTable - 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 storage
public 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 storage
public void delete(String pWriteBackTable,
ServerMetaData pServerMetaData,
Object[] pDelete)
throws DataSourceException
delete in interface IDBAccesspWriteBackTable - 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 Objectpublic String getOpenQuoteCharacter()
public String getCloseQuoteCharacter()
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 opened
public boolean isOpen()
throws DataSourceException
DataSourceException - if isClosed() on the DB Connection throws an Exception
public void close()
throws DataSourceException
Connection and releases all memory.
close in interface ICloseableDataSourceException - if database couldn't closed.
public void setAutoCommit(boolean pEnable)
throws DataSourceException
pEnable - true to enable, false to disable auto-commit
DataSourceException - if setting state failed
public boolean isAutoCommit()
throws DataSourceException
true if enabled, false otherwise
DataSourceException - if getting state failed
public void rollback()
throws DataSourceException
DataSourceException - if the transaction couldn't rollback
public void commit()
throws DataSourceException
DataSourceException - if the transaction couldn't commitpublic int getQueryTimeOut()
public 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 database
public 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 int getMaxColumnLength()
public 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 TypespParameters - 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 execution
public 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(ServerMetaData pServerMetaData,
String pBeforeQueryColumns,
String[] pQueryColumns,
String pFromClause,
ICondition pFilter,
String pWhereClause,
String pAfterWhereClause,
SortDefinition pSort,
String pOrderByClause)
throws DataSourceException
pServerMetaData - the MetaDataColumn array to use.pBeforeQueryColumns - the string to place in the SELECT statement between the SELECT and the first query column.pQueryColumns - the list of query columns to use in the SELECT statement.pFromClause - the list of query tables to use in the SELECT statement.pFilter - the Filter to usepWhereClause - 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.pSort - the sort definition.pOrderByClause - the order by clause.
DataSourceException - if it's not possible to build the select statement in fact of missing elements
protected String getWhereClause(ServerMetaData pServerMetaData,
ICondition pFilter,
String pWhereClause,
boolean pUsePrefix)
throws DataSourceException
Filter.
pServerMetaData - the MetaData to usepFilter - the Filter to usepWhereClause - the where clause 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 existing
protected 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 statement
protected 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()
protected 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 storage
protected ServerColumnMetaData[] getColumnMetaDataIntern(String pFromClause,
String[] pQueryColumns,
String pBeforeQueryColumns,
String pWhereClause,
String pAfterWhereClause)
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 query
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 supported
public final ServerColumnMetaData[] getColumnMetaData(String pFromClause,
String[] pQueryColumns,
String pBeforeQueryColumns,
String pWhereClause,
String pAfterWhereClause)
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 query
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 supported
protected TableInfo getTableInfoIntern(String pWriteBackTable)
throws DataSourceException
pWriteBackTable - the write back table 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 supported
public final TableInfo getTableInfo(String pWriteBackTable)
throws DataSourceException
pWriteBackTable - the write back table 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 supported
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 final Map<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 exception
protected Map<String,Object> getDefaultValuesIntern(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 exception
protected 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 supported
protected 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 supported
protected Map<String,Object[]> getAllowedValuesIntern(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 Objects or
null if there are no allowed values
DataSourceException - if the database access throws an exception
public final Map<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 Objects or
null if there are no allowed values
DataSourceException - if the database access throws an exception
public 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 values
protected String getSQL(ServerMetaData pServerMetaData,
ICondition pCondition,
boolean pUseRealColumnName)
throws DataSourceException
ICondition.
pServerMetaData - the MetaDataColumn array to use.pCondition - the Condition to use.pUseRealColumnName - true to use the prefixed column (real column name) and false to
ignore prefixes (the simple name of the column)
ICondition.
DataSourceException - if columns not existing
protected 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 Object[] getParameter(ICondition cCondition)
ICondition.
cCondition - the Condition to use.
ICondition.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)
throws SQLException
pColumnMetaData - the column metadatapObject - the read object
SQLException - if it fails.protected Object convertValueToDatabaseSpecificObject(Object pValue)
pValue - any value
protected String getIdentifier()
public static void clearMetaData()
public static void clearMetaData(String pApplicationName)
pApplicationName - the application namepublic static String createIdentifier(Object... pIdentifier)
pIdentifier - the identifier
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 failspublic void setMetaDataCacheOption(MetaDataCacheOption pOption)
pOption - the metadata cache optionisMetaDataCacheEnabled()public MetaDataCacheOption getMetaDataCacheOption()
setMetaDataCacheOption(MetaDataCacheOption)protected boolean isMetaDataCacheEnabled()
protected void setModified(boolean pModified)
throws DataSourceException
pModified - true to set the connection modified, false to set it not modified
DataSourceException - if auto-commit detection failspublic boolean isModified()
true if modified, false otherwiseprotected static boolean isLogEnabled(ILogger.LogLevel pLevel)
pLevel - the level to check
true if the log level is enabled, false otherwiseprotected static void debug(Object... pInfo)
pInfo - the debug informationprotected static void info(Object... pInfo)
pInfo - the informationprotected static void error(Object... pInfo)
pInfo - the error informationpublic static boolean isJdbc(String pUrl)
pUrl - the URL
true if given URL is a jdbc resource
protected String getColumnName(ResultSetMetaData pMetaData,
int pColumn)
throws SQLException
pMetaData - the metadatapColumn - the column index
SQLException - if accessing metadata failed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||