Package com.saperion.common.sql
Class SimpleDataSource<CommonReadResultException extends java.lang.Exception>
- java.lang.Object
-
- com.saperion.common.sql.DataSource<java.lang.IllegalStateException,CommonReadResultException>
-
- com.saperion.common.sql.SimpleDataSource<CommonReadResultException>
-
- Type Parameters:
CommonReadResultException- common type of all usedResultReaders duringDataSource.executeQuery(String, ResultReader)-operations to signal business-exceptions duringResultReader.readResult(ResultSet)
public class SimpleDataSource<CommonReadResultException extends java.lang.Exception> extends DataSource<java.lang.IllegalStateException,CommonReadResultException>
SimpleDataSourceis a simple implementation of anDataSourcethat can be used directly and that has no logging, no runtime-information and treats all errors asIllegalStateExceptions. While this class is easy to use, it is still strongly recommended to write your own subclass ofDataSourcein any real project to provide improved treatment.- Author:
- agz
-
-
Field Summary
-
Fields inherited from class com.saperion.common.sql.DataSource
LOGGER
-
-
Constructor Summary
Constructors Constructor Description SimpleDataSource(javax.sql.DataSource dataSource)Creates a newSimpleDataSourceencapsulating the specifiedDataSource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterExecuteQuery(java.lang.String sql)This event-method is called immediately afterStatement.executeQuery(String)was successfully called.protected voidafterExecuteUpdate(java.lang.String sql, int rowCount)This event-method is called immediately afterStatement.executeUpdate(String)was successfully called.protected voidafterReadResult(java.lang.String sql, int rowCount)This event-method is called immediately afterResultReader.readResult(ResultSet)was successfully called.It is called afterDataSource.noteReadResultTime(String, long, boolean).protected voidbeforeExecuteQuery(java.lang.String sql)This event-method is called immediately beforeStatement.executeQuery(String)is called.protected voidbeforeExecuteUpdate(java.lang.String sql)This event-method is called immediately beforeStatement.executeUpdate(String)is called.protected voidbeforeReadResult(java.lang.String sql)This event-method is called immediately beforeResultReader.readResult(ResultSet)is called.protected voidnoteExecuteQueryTime(java.lang.String sql, long timeNanoseconds, boolean success)This event-method is called immediately afterStatement.executeQuery(String)is called, no matter whether the call was successful or not.protected voidnoteExecuteUpdateTime(java.lang.String sql, long timeNanoseconds, boolean success)This event-method is called immediately afterStatement.executeUpdate(String)is called, no matter whether the call was successful or not.protected voidnoteReadResultTime(java.lang.String sql, long timeNanoseconds, boolean success)This event-method is called immediately afterResultReader.readResult(ResultSet)is called, no matter whether the call was successful or not.protected java.lang.IllegalStateExceptiononErrorCreatingStatement(java.lang.Throwable t, java.lang.String sql)This event-method is called by all SQL-execution-methods if there is noStatementavailable from the underlyingConnection.protected java.lang.IllegalStateExceptiononErrorExecutingQuery(java.lang.Throwable t, java.lang.String sql)This event-method is called byDataSource.executeQuery(String, ResultReader)if there is any error executing the statement.protected java.lang.IllegalStateExceptiononErrorExecutingUpdate(java.lang.Throwable t, java.lang.String sql)This event-method is called byDataSource.executeUpdate(String)if there is any error executing the statement.protected java.lang.IllegalStateExceptiononErrorGettingConnection(java.lang.Throwable t, java.lang.String sql)This event-method is called by all SQL-execution-methods if there is noConnectionavailable from the underlyingDataSource.protected java.lang.IllegalStateExceptiononErrorGettingDatabaseProductName(java.lang.Throwable t)This event-method is called byDataSource.getSqlDialect()if there is any error getting the database product name.protected java.lang.IllegalStateExceptiononErrorGettingMetaData(java.lang.Throwable t)This event-method is called byDataSource.getSqlDialect()if there is any error getting theDatabaseMetaData.protected java.lang.IllegalStateExceptiononErrorReadingResultSet(java.lang.Throwable t, java.lang.String sql)This event-method is called byDataSource.executeQuery(String, ResultReader)if there is any error reading theResultSet.-
Methods inherited from class com.saperion.common.sql.DataSource
executeQuery, executeUpdate, getSqlDataSource, getSqlDialect
-
-
-
-
Constructor Detail
-
SimpleDataSource
public SimpleDataSource(javax.sql.DataSource dataSource)
Creates a newSimpleDataSourceencapsulating the specifiedDataSource. The specifiedDataSourcemust not benull.- Parameters:
dataSource- underlyingDataSource
-
-
Method Detail
-
onErrorGettingConnection
protected java.lang.IllegalStateException onErrorGettingConnection(java.lang.Throwable t, java.lang.String sql)Description copied from class:DataSourceThis event-method is called by all SQL-execution-methods if there is noConnectionavailable from the underlyingDataSource. This method must return a suitableException.- Specified by:
onErrorGettingConnectionin classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
t- originalThrowablethrown byDataSource.getConnection()sql- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorCreatingStatement
protected java.lang.IllegalStateException onErrorCreatingStatement(java.lang.Throwable t, java.lang.String sql)Description copied from class:DataSourceThis event-method is called by all SQL-execution-methods if there is noStatementavailable from the underlyingConnection. This method must return a suitableException.- Specified by:
onErrorCreatingStatementin classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
t- originalThrowablethrown byConnection.createStatement()sql- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorExecutingQuery
protected java.lang.IllegalStateException onErrorExecutingQuery(java.lang.Throwable t, java.lang.String sql)Description copied from class:DataSourceThis event-method is called byDataSource.executeQuery(String, ResultReader)if there is any error executing the statement. This method must return a suitableException.- Specified by:
onErrorExecutingQueryin classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
t- originalThrowablethrown byStatement.executeQuery(String)sql- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorExecutingUpdate
protected java.lang.IllegalStateException onErrorExecutingUpdate(java.lang.Throwable t, java.lang.String sql)Description copied from class:DataSourceThis event-method is called byDataSource.executeUpdate(String)if there is any error executing the statement. This method must return a suitableException.- Specified by:
onErrorExecutingUpdatein classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
t- originalThrowablethrown byStatement.executeUpdate(String)sql- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorReadingResultSet
protected java.lang.IllegalStateException onErrorReadingResultSet(java.lang.Throwable t, java.lang.String sql)Description copied from class:DataSourceThis event-method is called byDataSource.executeQuery(String, ResultReader)if there is any error reading theResultSet. This method must return a suitableException.- Specified by:
onErrorReadingResultSetin classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
t- originalThrowablethrown byany of the ResultSet.get...()-methodssql- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorGettingMetaData
protected java.lang.IllegalStateException onErrorGettingMetaData(java.lang.Throwable t)
Description copied from class:DataSourceThis event-method is called byDataSource.getSqlDialect()if there is any error getting theDatabaseMetaData. This method must return a suitableException.- Specified by:
onErrorGettingMetaDatain classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
t- originalThrowablethrown byConnection.getMetaData()- Returns:
- a suitable
Exception
-
onErrorGettingDatabaseProductName
protected java.lang.IllegalStateException onErrorGettingDatabaseProductName(java.lang.Throwable t)
Description copied from class:DataSourceThis event-method is called byDataSource.getSqlDialect()if there is any error getting the database product name. This method must return a suitableException.- Specified by:
onErrorGettingDatabaseProductNamein classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
t- originalThrowablethrown byDatabaseMetaData.getDatabaseProductName()- Returns:
- a suitable
Exception
-
beforeExecuteUpdate
protected void beforeExecuteUpdate(java.lang.String sql)
Description copied from class:DataSourceThis event-method is called immediately beforeStatement.executeUpdate(String)is called.- Specified by:
beforeExecuteUpdatein classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
sql- SQL-statement of the SQL-execution-method
-
noteExecuteUpdateTime
protected void noteExecuteUpdateTime(java.lang.String sql, long timeNanoseconds, boolean success)Description copied from class:DataSourceThis event-method is called immediately afterStatement.executeUpdate(String)is called, no matter whether the call was successful or not.- Specified by:
noteExecuteUpdateTimein classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
sql- SQL-statement of the SQL-execution-methodtimeNanoseconds- the execution-time ofStatement.executeUpdate(String)in nanoseconds, no matter whether the call was successful or notsuccess- indicates whether the call was successful or not
-
afterExecuteUpdate
protected void afterExecuteUpdate(java.lang.String sql, int rowCount)Description copied from class:DataSourceThis event-method is called immediately afterStatement.executeUpdate(String)was successfully called. It is called afterDataSource.noteExecuteUpdateTime(String, long, boolean).- Specified by:
afterExecuteUpdatein classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
sql- SQL-statement of the SQL-execution-methodrowCount- count of manipulated rows
-
beforeExecuteQuery
protected void beforeExecuteQuery(java.lang.String sql)
Description copied from class:DataSourceThis event-method is called immediately beforeStatement.executeQuery(String)is called.- Specified by:
beforeExecuteQueryin classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
sql- SQL-statement of the SQL-execution-method
-
noteExecuteQueryTime
protected void noteExecuteQueryTime(java.lang.String sql, long timeNanoseconds, boolean success)Description copied from class:DataSourceThis event-method is called immediately afterStatement.executeQuery(String)is called, no matter whether the call was successful or not.- Specified by:
noteExecuteQueryTimein classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
sql- SQL-statement of the SQL-execution-methodtimeNanoseconds- the execution-time ofStatement.executeQuery(String)in nanoseconds, no matter whether the call was successful or notsuccess- indicates whether the call was successful or not
-
afterExecuteQuery
protected void afterExecuteQuery(java.lang.String sql)
Description copied from class:DataSourceThis event-method is called immediately afterStatement.executeQuery(String)was successfully called. It is called afterDataSource.noteExecuteQueryTime(String, long, boolean).- Specified by:
afterExecuteQueryin classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
sql- SQL-statement of the SQL-execution-method
-
beforeReadResult
protected void beforeReadResult(java.lang.String sql)
Description copied from class:DataSourceThis event-method is called immediately beforeResultReader.readResult(ResultSet)is called.- Specified by:
beforeReadResultin classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
sql- SQL-statement of the SQL-execution-method
-
noteReadResultTime
protected void noteReadResultTime(java.lang.String sql, long timeNanoseconds, boolean success)Description copied from class:DataSourceThis event-method is called immediately afterResultReader.readResult(ResultSet)is called, no matter whether the call was successful or not.- Specified by:
noteReadResultTimein classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
sql- SQL-statement of the SQL-execution-methodtimeNanoseconds- the execution-time ofResultReader.readResult(ResultSet)in nanoseconds, no matter whether the call was successful or notsuccess- indicates whether the call was successful or not
-
afterReadResult
protected void afterReadResult(java.lang.String sql, int rowCount)Description copied from class:DataSourceThis event-method is called immediately afterResultReader.readResult(ResultSet)was successfully called.It is called afterDataSource.noteReadResultTime(String, long, boolean).- Specified by:
afterReadResultin classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>- Parameters:
sql- SQL-statement of the SQL-execution-methodrowCount- count of selected rows
-
-