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 usedResultReader
s 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 IllegalStateException
s. 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 newSimpleDataSource
encapsulating the specifiedDataSource
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
afterExecuteQuery
(String sql) This event-method is called immediately afterStatement.executeQuery(String)
was successfully called.protected void
afterExecuteUpdate
(String sql, int rowCount) This event-method is called immediately afterStatement.executeUpdate(String)
was successfully called.protected void
afterReadResult
(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
(String sql) This event-method is called immediately beforeStatement.executeQuery(String)
is called.protected void
This event-method is called immediately beforeStatement.executeUpdate(String)
is called.protected void
beforeReadResult
(String sql) This event-method is called immediately beforeResultReader.readResult(ResultSet)
is called.protected void
noteExecuteQueryTime
(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
(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
(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 IllegalStateException
onErrorCreatingStatement
(Throwable t, String sql) This event-method is called by all SQL-execution-methods if there is noStatement
available from the underlyingConnection
.protected IllegalStateException
onErrorExecutingQuery
(Throwable t, String sql) This event-method is called byDataSource.executeQuery(String, ResultReader)
if there is any error executing the statement.protected IllegalStateException
onErrorExecutingUpdate
(Throwable t, String sql) This event-method is called byDataSource.executeUpdate(String)
if there is any error executing the statement.protected IllegalStateException
onErrorGettingConnection
(Throwable t, String sql) This event-method is called by all SQL-execution-methods if there is noConnection
available from the underlyingDataSource
.protected IllegalStateException
This event-method is called byDataSource.getSqlDialect()
if there is any error getting the database product name.protected IllegalStateException
This event-method is called byDataSource.getSqlDialect()
if there is any error getting theDatabaseMetaData
.protected IllegalStateException
onErrorReadingResultSet
(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 newSimpleDataSource
encapsulating the specifiedDataSource
. The specifiedDataSource
must not benull
.- Parameters:
dataSource
- underlyingDataSource
-
-
Method Details
-
onErrorGettingConnection
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<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
t
- originalThrowable
thrown byDataSource.getConnection()
sql
- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorCreatingStatement
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<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
t
- originalThrowable
thrown byConnection.createStatement()
sql
- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorExecutingQuery
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<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
t
- originalThrowable
thrown byStatement.executeQuery(String)
sql
- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorExecutingUpdate
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<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
t
- originalThrowable
thrown byStatement.executeUpdate(String)
sql
- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorReadingResultSet
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<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
t
- originalThrowable
thrown byany of the ResultSet.get...()-methods
sql
- SQL-statement of the SQL-execution-method- Returns:
- a suitable
Exception
-
onErrorGettingMetaData
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<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
t
- originalThrowable
thrown byConnection.getMetaData()
- Returns:
- a suitable
Exception
-
onErrorGettingDatabaseProductName
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<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
t
- originalThrowable
thrown byDatabaseMetaData.getDatabaseProductName()
- Returns:
- a suitable
Exception
-
beforeExecuteUpdate
Description copied from class:DataSource
This event-method is called immediately beforeStatement.executeUpdate(String)
is called.- Specified by:
beforeExecuteUpdate
in classDataSource<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
sql
- SQL-statement of the SQL-execution-method
-
noteExecuteUpdateTime
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<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: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<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
sql
- SQL-statement of the SQL-execution-methodrowCount
- count of manipulated rows
-
beforeExecuteQuery
Description copied from class:DataSource
This event-method is called immediately beforeStatement.executeQuery(String)
is called.- Specified by:
beforeExecuteQuery
in classDataSource<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
sql
- SQL-statement of the SQL-execution-method
-
noteExecuteQueryTime
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<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: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<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
sql
- SQL-statement of the SQL-execution-method
-
beforeReadResult
Description copied from class:DataSource
This event-method is called immediately beforeResultReader.readResult(ResultSet)
is called.- Specified by:
beforeReadResult
in classDataSource<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
sql
- SQL-statement of the SQL-execution-method
-
noteReadResultTime
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<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: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<IllegalStateException,
CommonReadResultException extends Exception> - Parameters:
sql
- SQL-statement of the SQL-execution-methodrowCount
- count of selected rows
-