Package com.saperion.common.sql
Class SimpleDataSource<CommonReadResultException extends Exception>
java.lang.Object
com.saperion.common.sql.DataSource<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 Exception>
extends DataSource<IllegalStateException,CommonReadResultException>
SimpleDataSource is a simple implementation of an DataSource that can be used directly and that has
no logging, no runtime-information and treats all errors as IllegalStateExceptions. While this class is easy
to use, it is still strongly recommended to write your own subclass of DataSource in any real project to
provide improved treatment.
- Author:
- agz
-
Field Summary
Fields inherited from class com.saperion.common.sql.DataSource
LOGGER -
Constructor Summary
ConstructorsConstructorDescriptionSimpleDataSource(DataSource dataSource) Creates a newSimpleDataSourceencapsulating the specifiedDataSource. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterExecuteQuery(String sql) This event-method is called immediately afterStatement.executeQuery(String)was successfully called.protected voidafterExecuteUpdate(String sql, int rowCount) This event-method is called immediately afterStatement.executeUpdate(String)was successfully called.protected voidafterReadResult(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(String sql) This event-method is called immediately beforeStatement.executeQuery(String)is called.protected voidThis event-method is called immediately beforeStatement.executeUpdate(String)is called.protected voidbeforeReadResult(String sql) This event-method is called immediately beforeResultReader.readResult(ResultSet)is called.protected voidnoteExecuteQueryTime(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(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(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 IllegalStateExceptiononErrorCreatingStatement(Throwable t, String sql) This event-method is called by all SQL-execution-methods if there is noStatementavailable from the underlyingConnection.protected IllegalStateExceptiononErrorExecutingQuery(Throwable t, String sql) This event-method is called byDataSource.executeQuery(String, ResultReader)if there is any error executing the statement.protected IllegalStateExceptiononErrorExecutingUpdate(Throwable t, String sql) This event-method is called byDataSource.executeUpdate(String)if there is any error executing the statement.protected IllegalStateExceptiononErrorGettingConnection(Throwable t, String sql) This event-method is called by all SQL-execution-methods if there is noConnectionavailable from the underlyingDataSource.protected IllegalStateExceptionThis event-method is called byDataSource.getSqlDialect()if there is any error getting the database product name.protected IllegalStateExceptionThis event-method is called byDataSource.getSqlDialect()if there is any error getting theDatabaseMetaData.protected IllegalStateExceptiononErrorReadingResultSet(Throwable t, 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 Details
-
SimpleDataSource
Creates a newSimpleDataSourceencapsulating the specifiedDataSource. The specifiedDataSourcemust not benull.- Parameters:
dataSource- underlyingDataSource
-
-
Method Details
-
onErrorGettingConnection
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<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
t- originalThrowablethrown byDataSource.getConnection()sql- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorCreatingStatement
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<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
t- originalThrowablethrown byConnection.createStatement()sql- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorExecutingQuery
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<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
t- originalThrowablethrown byStatement.executeQuery(String)sql- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorExecutingUpdate
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<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
t- originalThrowablethrown byStatement.executeUpdate(String)sql- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorReadingResultSet
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<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
t- originalThrowablethrown byany of the ResultSet.get...()-methodssql- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorGettingMetaData
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<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
t- originalThrowablethrown byConnection.getMetaData()- Returns:
- a suitable
Exception
-
onErrorGettingDatabaseProductName
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<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
t- originalThrowablethrown byDatabaseMetaData.getDatabaseProductName()- Returns:
- a suitable
Exception
-
beforeExecuteUpdate
Description copied from class:DataSourceThis event-method is called immediately beforeStatement.executeUpdate(String)is called.- Specified by:
beforeExecuteUpdatein classDataSource<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
sql- SQL-statement of the SQL-execution-method
-
noteExecuteUpdateTime
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<IllegalStateException,CommonReadResultException extends 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
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<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
sql- SQL-statement of the SQL-execution-methodrowCount- count of manipulated rows
-
beforeExecuteQuery
Description copied from class:DataSourceThis event-method is called immediately beforeStatement.executeQuery(String)is called.- Specified by:
beforeExecuteQueryin classDataSource<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
sql- SQL-statement of the SQL-execution-method
-
noteExecuteQueryTime
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<IllegalStateException,CommonReadResultException extends 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
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<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
sql- SQL-statement of the SQL-execution-method
-
beforeReadResult
Description copied from class:DataSourceThis event-method is called immediately beforeResultReader.readResult(ResultSet)is called.- Specified by:
beforeReadResultin classDataSource<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
sql- SQL-statement of the SQL-execution-method
-
noteReadResultTime
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<IllegalStateException,CommonReadResultException extends 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
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<IllegalStateException,CommonReadResultException extends Exception> - Parameters:
sql- SQL-statement of the SQL-execution-methodrowCount- count of selected rows
-