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 usedResultReader
s 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>
SimpleDataSource
is a simple implementation of anDataSource
that can be used directly and that has no logging, no runtime-information and treats all errors asIllegalStateException
s. While this class is easy to use, it is still strongly recommended to write your own subclass ofDataSource
in 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 newSimpleDataSource
encapsulating the specifiedDataSource
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterExecuteQuery(java.lang.String sql)
This event-method is called immediately afterStatement.executeQuery(String)
was successfully called.protected void
afterExecuteUpdate(java.lang.String sql, int rowCount)
This event-method is called immediately afterStatement.executeUpdate(String)
was successfully called.protected void
afterReadResult(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 void
beforeExecuteQuery(java.lang.String sql)
This event-method is called immediately beforeStatement.executeQuery(String)
is called.protected void
beforeExecuteUpdate(java.lang.String sql)
This event-method is called immediately beforeStatement.executeUpdate(String)
is called.protected void
beforeReadResult(java.lang.String sql)
This event-method is called immediately beforeResultReader.readResult(ResultSet)
is called.protected void
noteExecuteQueryTime(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 void
noteExecuteUpdateTime(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 void
noteReadResultTime(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.IllegalStateException
onErrorCreatingStatement(java.lang.Throwable t, java.lang.String sql)
This event-method is called by all SQL-execution-methods if there is noStatement
available from the underlyingConnection
.protected java.lang.IllegalStateException
onErrorExecutingQuery(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.IllegalStateException
onErrorExecutingUpdate(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.IllegalStateException
onErrorGettingConnection(java.lang.Throwable t, java.lang.String sql)
This event-method is called by all SQL-execution-methods if there is noConnection
available from the underlyingDataSource
.protected java.lang.IllegalStateException
onErrorGettingDatabaseProductName(java.lang.Throwable t)
This event-method is called byDataSource.getSqlDialect()
if there is any error getting the database product name.protected java.lang.IllegalStateException
onErrorGettingMetaData(java.lang.Throwable t)
This event-method is called byDataSource.getSqlDialect()
if there is any error getting theDatabaseMetaData
.protected java.lang.IllegalStateException
onErrorReadingResultSet(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 newSimpleDataSource
encapsulating the specifiedDataSource
. The specifiedDataSource
must 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:DataSource
This event-method is called by all SQL-execution-methods if there is noConnection
available from the underlyingDataSource
. This method must return a suitableException
.- Specified by:
onErrorGettingConnection
in classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>
- Parameters:
t
- originalThrowable
thrown 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:DataSource
This event-method is called by all SQL-execution-methods if there is noStatement
available from the underlyingConnection
. This method must return a suitableException
.- Specified by:
onErrorCreatingStatement
in classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>
- Parameters:
t
- originalThrowable
thrown 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:DataSource
This event-method is called byDataSource.executeQuery(String, ResultReader)
if there is any error executing the statement. This method must return a suitableException
.- Specified by:
onErrorExecutingQuery
in classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>
- Parameters:
t
- originalThrowable
thrown 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:DataSource
This event-method is called byDataSource.executeUpdate(String)
if there is any error executing the statement. This method must return a suitableException
.- Specified by:
onErrorExecutingUpdate
in classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>
- Parameters:
t
- originalThrowable
thrown 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:DataSource
This event-method is called byDataSource.executeQuery(String, ResultReader)
if there is any error reading theResultSet
. This method must return a suitableException
.- Specified by:
onErrorReadingResultSet
in classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>
- Parameters:
t
- originalThrowable
thrown byany of the ResultSet.get...()-methods
sql
- 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:DataSource
This event-method is called byDataSource.getSqlDialect()
if there is any error getting theDatabaseMetaData
. This method must return a suitableException
.- Specified by:
onErrorGettingMetaData
in classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>
- Parameters:
t
- originalThrowable
thrown byConnection.getMetaData()
- Returns:
- a suitable
Exception
-
onErrorGettingDatabaseProductName
protected java.lang.IllegalStateException onErrorGettingDatabaseProductName(java.lang.Throwable t)
Description copied from class:DataSource
This event-method is called byDataSource.getSqlDialect()
if there is any error getting the database product name. This method must return a suitableException
.- Specified by:
onErrorGettingDatabaseProductName
in classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>
- Parameters:
t
- originalThrowable
thrown byDatabaseMetaData.getDatabaseProductName()
- Returns:
- a suitable
Exception
-
beforeExecuteUpdate
protected void beforeExecuteUpdate(java.lang.String sql)
Description copied from class:DataSource
This event-method is called immediately beforeStatement.executeUpdate(String)
is called.- Specified by:
beforeExecuteUpdate
in 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:DataSource
This event-method is called immediately afterStatement.executeUpdate(String)
is called, no matter whether the call was successful or not.- Specified by:
noteExecuteUpdateTime
in 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:DataSource
This event-method is called immediately afterStatement.executeUpdate(String)
was successfully called. It is called afterDataSource.noteExecuteUpdateTime(String, long, boolean)
.- Specified by:
afterExecuteUpdate
in 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:DataSource
This event-method is called immediately beforeStatement.executeQuery(String)
is called.- Specified by:
beforeExecuteQuery
in 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:DataSource
This event-method is called immediately afterStatement.executeQuery(String)
is called, no matter whether the call was successful or not.- Specified by:
noteExecuteQueryTime
in 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:DataSource
This event-method is called immediately afterStatement.executeQuery(String)
was successfully called. It is called afterDataSource.noteExecuteQueryTime(String, long, boolean)
.- Specified by:
afterExecuteQuery
in 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:DataSource
This event-method is called immediately beforeResultReader.readResult(ResultSet)
is called.- Specified by:
beforeReadResult
in 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:DataSource
This event-method is called immediately afterResultReader.readResult(ResultSet)
is called, no matter whether the call was successful or not.- Specified by:
noteReadResultTime
in 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:DataSource
This event-method is called immediately afterResultReader.readResult(ResultSet)
was successfully called.It is called afterDataSource.noteReadResultTime(String, long, boolean)
.- Specified by:
afterReadResult
in classDataSource<java.lang.IllegalStateException,CommonReadResultException extends java.lang.Exception>
- Parameters:
sql
- SQL-statement of the SQL-execution-methodrowCount
- count of selected rows
-
-