Package com.valqueries.automapper
Class TestDoubleTransactionContext
java.lang.Object
com.valqueries.automapper.TestDoubleTransactionContext
- All Implemented Interfaces:
IOrmOperations
,ITransactionContext
,AutoCloseable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
<ReturnType>
ReturnTypeconditionalExecute
(Function<IOrmOperations, ReturnType> sqlDbFunction, Function<IOrmOperations, ReturnType> sqlServerFunction) Execute the consumer depending on the database type of the connection.<T> List<T>
query
(String sql, Setter setter, IRowMapper<T> rowMapper) Queries data from the database and maps it to the list of objects using row mapper<T> Optional<T>
queryOne
(String sql, Setter setter, IRowMapper<T> rowMapper) Deprecated because it throws aNullPointerException
when the result is null instead of returning empty optional.<T> Optional<T>
querySingle
(String sql, Setter setter, IRowMapper<T> rowMapper) Queries for a single row from the database and maps it to the object using row mapper.void
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.valqueries.IOrmOperations
query, queryOne, querySingle, queryWithPlaceholders, streamQuery, streamQueryWithPlaceholders, updateWithPlaceholders
-
Constructor Details
-
TestDoubleTransactionContext
public TestDoubleTransactionContext()
-
-
Method Details
-
update
- Specified by:
update
in interfaceIOrmOperations
-
update
- Specified by:
update
in interfaceIOrmOperations
-
save
- Specified by:
save
in interfaceIOrmOperations
-
query
Description copied from interface:IOrmOperations
Queries data from the database and maps it to the list of objects using row mapper- Specified by:
query
in interfaceIOrmOperations
- Type Parameters:
T
- type of the object you wish database rows to be transformed to- Parameters:
sql
- query to be executed in order to fetch data. Parameters must be parametrized with named parameters like `:my_param`setter
- setter used to populate parameters in the queryrowMapper
- mapper transformingOrmResultSet
to the object of your choice- Returns:
- list of objects representing the result set rows from the database (list element per result set row)
-
querySingle
public <T> Optional<T> querySingle(String sql, Setter setter, IRowMapper<T> rowMapper) throws OrmException.MoreThanOneRowFound Description copied from interface:IOrmOperations
Queries for a single row from the database and maps it to the object using row mapper. Throws an exception if more than one row has been found. Returns empty optional in case if no rows were found or the row is mapped to null value.- Specified by:
querySingle
in interfaceIOrmOperations
- Type Parameters:
T
- type of the object you wish database rows to be transformed to- Parameters:
sql
- query to be executed in order to fetch data. Parameters must be parametrized with named parameters like `:my_param`setter
- setter used to populate parameters in the queryrowMapper
- mapper transformingOrmResultSet
to the object of your choice- Returns:
- Optional of the object representing a row found in the database. Empty if no row were found or row is mapped to null value
- Throws:
OrmException.MoreThanOneRowFound
- in case more than one row can be found for a given query
-
queryOne
public <T> Optional<T> queryOne(String sql, Setter setter, IRowMapper<T> rowMapper) throws OrmException.MoreThanOneRowFound, NullPointerException Description copied from interface:IOrmOperations
Deprecated because it throws aNullPointerException
when the result is null instead of returning empty optional.Queries for a single row from the database and maps it to the object using row mapper. Throws an exception if more than one row has been found. Returns empty optional in case if no rows were found.
- Specified by:
queryOne
in interfaceIOrmOperations
- Type Parameters:
T
- type of the object you wish database rows to be transformed to- Parameters:
sql
- query to be executed in order to fetch data. Parameters must be parametrized with named parameters like `:my_param`setter
- setter used to populate parameters in the queryrowMapper
- mapper transformingOrmResultSet
to the object of your choice- Returns:
- Optional of the object representing a row found in the database. Empty if no row were found
- Throws:
OrmException.MoreThanOneRowFound
- in case more than one row can be found for a given queryNullPointerException
- in case more than one row can be found for a given query
-
conditionalExecute
public <ReturnType> ReturnType conditionalExecute(Function<IOrmOperations, ReturnType> sqlDbFunction, Function<IOrmOperations, ReturnType> sqlServerFunction) Description copied from interface:IOrmOperations
Execute the consumer depending on the database type of the connection. This method should be your last resource when running vendor specific code.- Specified by:
conditionalExecute
in interfaceIOrmOperations
- Parameters:
sqlDbFunction
- Consumer to be executed if the database is MariaDB or MySQL.sqlServerFunction
- Consumer to be executed if the database is SQL Server.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceITransactionContext
-