Package io.micronaut.data.jdbc.runtime
Interface JdbcOperations
- All Known Subinterfaces:
JdbcRepositoryOperations
- All Known Implementing Classes:
DefaultJdbcRepositoryOperations
public interface JdbcOperations
Simple JDBC operations interface.
- Since:
- 1.0.0
- Author:
- graemerocher
-
Method Summary
Modifier and TypeMethodDescription<T> @NonNull Stream<T>entityStream(@NonNull ResultSet resultSet, @NonNull Class<T> rootEntity) Map a result set to a stream of the given type.<T> @NonNull Stream<T>entityStream(@NonNull ResultSet resultSet, @Nullable String prefix, @NonNull Class<T> rootEntity) Map a result set to a stream of the given type.<R> Rexecute(@NonNull ConnectionCallback<R> callback) Execute the given operation with the given callback.@NonNull ConnectionThis method will return the currently active connection for the current transaction or throw an exception if no transaction is present.@NonNull DataSource<R> RprepareStatement(@NonNull String sql, @NonNull PreparedStatementCallback<R> callback) Execute the given operation with the given callback.<E,D> D readDTO(@NonNull String prefix, @NonNull ResultSet resultSet, @NonNull Class<E> rootEntity, @NonNull Class<D> dtoType) Read an entity using the given prefix to be passes to result set lookups.default <E,D> D Read an entity using the given prefix to be passes to result set lookups.<E> EreadEntity(@NonNull String prefix, @NonNull ResultSet resultSet, @NonNull Class<E> type) Read an entity using the given prefix to be passes to result set lookups.default <E> EreadEntity(@NonNull ResultSet resultSet, @NonNull Class<E> type) Read an entity using the given prefix to be passes to result set lookups.
-
Method Details
-
getDataSource
- Returns:
- The backing data source.
-
getConnection
This method will return the currently active connection for the current transaction or throw an exception if no transaction is present.- Returns:
- The current connection for the active transaction.
- Throws:
NoTransactionException- if no transaction is present.
-
execute
Execute the given operation with the given callback.- Type Parameters:
R- The result type- Parameters:
callback- The callback- Returns:
- The result
-
prepareStatement
@NonNull <R> R prepareStatement(@NonNull @NonNull String sql, @NonNull @NonNull PreparedStatementCallback<R> callback) Execute the given operation with the given callback.- Type Parameters:
R- The result type- Parameters:
sql- The SQLcallback- The callback- Returns:
- The result
-
entityStream
@NonNull <T> @NonNull Stream<T> entityStream(@NonNull @NonNull ResultSet resultSet, @Nullable @Nullable String prefix, @NonNull @NonNull Class<T> rootEntity) Map a result set to a stream of the given type.- Type Parameters:
T- The generic type- Parameters:
resultSet- The result setprefix- The prefix to use for each column name that is mappedrootEntity- The entity type- Returns:
- The stream
- Throws:
DataAccessException- If an error occurs reading the result
-
entityStream
@NonNull <T> @NonNull Stream<T> entityStream(@NonNull @NonNull ResultSet resultSet, @NonNull @NonNull Class<T> rootEntity) Map a result set to a stream of the given type.- Type Parameters:
T- The generic type- Parameters:
resultSet- The result setrootEntity- The entity type- Returns:
- The stream
- Throws:
DataAccessException- If an error occurs reading the result
-
readEntity
@NonNull <E> E readEntity(@NonNull @NonNull String prefix, @NonNull @NonNull ResultSet resultSet, @NonNull @NonNull Class<E> type) throws DataAccessException Read an entity using the given prefix to be passes to result set lookups.- Type Parameters:
E- The entity generic type- Parameters:
prefix- The prefixresultSet- The result settype- The entity type- Returns:
- The entity result
- Throws:
DataAccessException- if it is not possible read the result from the result set.
-
readEntity
@NonNull default <E> E readEntity(@NonNull @NonNull ResultSet resultSet, @NonNull @NonNull Class<E> type) throws DataAccessException Read an entity using the given prefix to be passes to result set lookups.- Type Parameters:
E- The entity generic type- Parameters:
resultSet- The result settype- The entity type- Returns:
- The entity result
- Throws:
DataAccessException- if it is not possible read the result from the result set.
-
readDTO
@NonNull <E,D> D readDTO(@NonNull @NonNull String prefix, @NonNull @NonNull ResultSet resultSet, @NonNull @NonNull Class<E> rootEntity, @NonNull @NonNull Class<D> dtoType) throws DataAccessException Read an entity using the given prefix to be passes to result set lookups.- Type Parameters:
E- The entity generic typeD- The DTO generic type- Parameters:
prefix- The prefixresultSet- The result setrootEntity- The entity typedtoType- The DTO type. Must be annotated withIntrospected- Returns:
- The entity result
- Throws:
DataAccessException- if it is not possible read the result from the result set.
-
readDTO
@NonNull default <E,D> D readDTO(@NonNull @NonNull ResultSet resultSet, @NonNull @NonNull Class<E> rootEntity, @NonNull @NonNull Class<D> dtoType) throws DataAccessException Read an entity using the given prefix to be passes to result set lookups.- Type Parameters:
E- The entity generic typeD- The DTO generic type- Parameters:
resultSet- The result setrootEntity- The entity typedtoType- The DTO type. Must be annotated withIntrospected- Returns:
- The entity result
- Throws:
DataAccessException- if it is not possible read the result from the result set.
-