Package com.valqueries
Class Orm
java.lang.Object
com.valqueries.Orm
- All Implemented Interfaces:
- IOrm,- IOrmOperations,- ITransactionContext,- AutoCloseable
- 
Constructor SummaryConstructorsConstructorDescriptionOrm(JdbcHelper jdbc, boolean autoClose) Orm(javax.inject.Provider<JdbcHelper> jdbcProvider, boolean autoClose) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()<ReturnType>
 ReturnTypeconditionalExecute(Function<IOrmOperations, ReturnType> mySqlFunction, 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.<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.<T> List<T>queryWithPlaceholders(String sql, Setter setter, List<String> parameters, IRowMapper<T> rowMapper) New version ofIOrmOperations.query(String, Setter, IRowMapper)that avoids expensive regex operations<T> Stream<T>streamQuery(String sql, Setter setter, IRowMapper<T> rowMapper) New version ofIOrmOperations.query(String, Setter, IRowMapper)that avoids collecting the whole result into a list.<T> Stream<T>streamQueryWithPlaceholders(String sql, Setter setter, List<String> parameters, IRowMapper<T> rowMapper) New version ofIOrmOperations.streamQuery(String, Setter, IRowMapper)that avoids expensive regex operations.voidNew version ofIOrmOperations.update(String, Setter)that avoids expensive regex operationsMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.valqueries.IOrmOperationsquery, queryOne, querySingle
- 
Constructor Details- 
Orm
- 
Orm
 
- 
- 
Method Details- 
update- Specified by:
- updatein interface- IOrmOperations
 
- 
update- Specified by:
- updatein interface- IOrmOperations
 
- 
updateWithPlaceholderspublic UpdateResult updateWithPlaceholders(String sql, Setter setter, Supplier<List<String>> parametersSupplier) Description copied from interface:IOrmOperationsNew version ofIOrmOperations.update(String, Setter)that avoids expensive regex operations- Specified by:
- updateWithPlaceholdersin interface- IOrmOperations
- Parameters:
- sql- SQL string with placeholders such as- ?instead of the usual- :paramNametokens
- setter- Setter as usual
- parametersSupplier- Supplier that provides the list of value tokens as they would appear in the SQL string
- Returns:
- The result of the update operation
 
- 
save- Specified by:
- savein interface- IOrmOperations
 
- 
queryDescription copied from interface:IOrmOperationsQueries data from the database and maps it to the list of objects using row mapper- Specified by:
- queryin interface- IOrmOperations
- 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 query
- rowMapper- mapper transforming- OrmResultSetto the object of your choice
- Returns:
- list of objects representing the result set rows from the database (list element per result set row)
 
- 
streamQueryDescription copied from interface:IOrmOperationsNew version ofIOrmOperations.query(String, Setter, IRowMapper)that avoids collecting the whole result into a list. Once the returned stream is consumed,thiswill be closed.- Specified by:
- streamQueryin interface- IOrmOperations
- 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 query
- rowMapper- mapper transforming- OrmResultSetto the object of your choice
- Returns:
- stream of objects representing the result set rows from the database (stream element per result set row)
 
- 
queryWithPlaceholderspublic <T> List<T> queryWithPlaceholders(String sql, Setter setter, List<String> parameters, IRowMapper<T> rowMapper) Description copied from interface:IOrmOperationsNew version ofIOrmOperations.query(String, Setter, IRowMapper)that avoids expensive regex operations- Specified by:
- queryWithPlaceholdersin interface- IOrmOperations
- Type Parameters:
- T- Type of the object you wish database rows to be transformed to
- Parameters:
- sql- SQL string with placeholders such as- ?instead of the usual- :paramNametokens
- setter- Setter as usual
- parameters- List of value tokens as they would appear in the SQL string
- rowMapper- Mapper transforming- OrmResultSetto the object of your choice
- Returns:
- List of objects representing the result set rows from the database (list element per result set row)
 
- 
streamQueryWithPlaceholderspublic <T> Stream<T> streamQueryWithPlaceholders(String sql, Setter setter, List<String> parameters, IRowMapper<T> rowMapper) Description copied from interface:IOrmOperationsNew version ofIOrmOperations.streamQuery(String, Setter, IRowMapper)that avoids expensive regex operations. Once the returned stream is consumed,thiswill be closed.- Specified by:
- streamQueryWithPlaceholdersin interface- IOrmOperations
- Type Parameters:
- T- Type of the object you wish database rows to be transformed to
- Parameters:
- sql- SQL string with placeholders such as- ?instead of the usual- :paramNametokens
- setter- Setter as usual
- parameters- List of value tokens as they would appear in the SQL string
- rowMapper- Mapper transforming- OrmResultSetto the object of your choice
- Returns:
- Stream of objects representing the result set rows from the database (stream element per result set row)
 
- 
querySinglepublic <T> Optional<T> querySingle(String sql, Setter setter, IRowMapper<T> rowMapper) throws OrmException.MoreThanOneRowFound Description copied from interface:IOrmOperationsQueries 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:
- querySinglein interface- IOrmOperations
- 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 query
- rowMapper- mapper transforming- OrmResultSetto 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@Deprecated public <T> Optional<T> queryOne(String sql, Setter setter, IRowMapper<T> rowMapper) throws OrmException.MoreThanOneRowFound Deprecated.Description copied from interface:IOrmOperationsDeprecated because it throws aNullPointerExceptionwhen 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:
- queryOnein interface- IOrmOperations
- 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 query
- rowMapper- mapper transforming- OrmResultSetto 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 query
 
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- ITransactionContext
 
- 
conditionalExecutepublic <ReturnType> ReturnType conditionalExecute(Function<IOrmOperations, ReturnType> mySqlFunction, Function<IOrmOperations, ReturnType> sqlServerFunction) Description copied from interface:IOrmOperationsExecute the consumer depending on the database type of the connection. This method should be your last resource when running vendor specific code.- Specified by:
- conditionalExecutein interface- IOrmOperations
- Parameters:
- mySqlFunction- Consumer to be executed if the database is MariaDB or MySQL.
- sqlServerFunction- Consumer to be executed if the database is SQL Server.
 
 
-