Cnt - The connection typeRS - The result set typePS - The prepared statement typeExc - The exception type@Internal
public abstract class AbstractSqlRepositoryOperations<Cnt,RS,PS,Exc extends java.lang.Exception>
extends java.lang.Object
implements io.micronaut.context.ApplicationContextProvider
| Modifier and Type | Class and Description |
|---|---|
protected class |
AbstractSqlRepositoryOperations.BaseOperations<T>
The base entity operations class.
|
protected static class |
AbstractSqlRepositoryOperations.CascadeContext
The cascade context.
|
protected static class |
AbstractSqlRepositoryOperations.CascadeManyOp
The cascade operation of multiple entities - @Many mappings.
|
protected static class |
AbstractSqlRepositoryOperations.CascadeOneOp
The cascade operation of one entity.
|
protected static class |
AbstractSqlRepositoryOperations.CascadeOp
The base cascade operation.
|
protected static interface |
AbstractSqlRepositoryOperations.DBOperation1<In,Exc extends java.lang.Exception>
Simple function interface without return type.
|
protected static interface |
AbstractSqlRepositoryOperations.DBOperation2<In1,In2,Exc extends java.lang.Exception>
Simple function interface with two inputs and without return type.
|
protected class |
AbstractSqlRepositoryOperations.EntitiesOperations<T>
The entities operations container.
|
protected class |
AbstractSqlRepositoryOperations.EntityOperations<T>
The entity operations container.
|
protected class |
AbstractSqlRepositoryOperations.SqlOperation
The sql operation.
|
protected static interface |
AbstractSqlRepositoryOperations.StatementSupplier<PS>
Functional interface used to supply a statement.
|
protected class |
AbstractSqlRepositoryOperations.StoredAnnotationMetadataSqlOperation
Implementation of
AbstractSqlRepositoryOperations.StoredSqlOperation that retrieves data from AnnotationMetadata. |
protected class |
AbstractSqlRepositoryOperations.StoredSqlOperation
Implementation of
AbstractSqlRepositoryOperations.SqlOperation that uses bindging paths. |
| Modifier and Type | Field and Description |
|---|---|
protected ResultReader<RS,java.lang.Integer> |
columnIndexResultSetReader |
protected ResultReader<RS,java.lang.String> |
columnNameResultSetReader |
protected DateTimeProvider |
dateTimeProvider |
protected static SqlQueryBuilder |
DEFAULT_SQL_BUILDER |
protected EntityEventListener<java.lang.Object> |
entityEventRegistry |
protected io.micronaut.http.codec.MediaTypeCodec |
jsonCodec |
protected QueryStatement<PS,java.lang.Integer> |
preparedStatementWriter |
protected static org.slf4j.Logger |
QUERY_LOG |
protected java.util.Map<java.lang.Class,SqlQueryBuilder> |
queryBuilders |
protected RuntimeEntityRegistry |
runtimeEntityRegistry |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSqlRepositoryOperations(java.lang.String dataSourceName,
ResultReader<RS,java.lang.String> columnNameResultSetReader,
ResultReader<RS,java.lang.Integer> columnIndexResultSetReader,
QueryStatement<PS,java.lang.Integer> preparedStatementWriter,
java.util.List<io.micronaut.http.codec.MediaTypeCodec> codecs,
DateTimeProvider<java.lang.Object> dateTimeProvider,
io.micronaut.context.BeanContext beanContext)
|
protected |
AbstractSqlRepositoryOperations(java.lang.String dataSourceName,
ResultReader<RS,java.lang.String> columnNameResultSetReader,
ResultReader<RS,java.lang.Integer> columnIndexResultSetReader,
QueryStatement<PS,java.lang.Integer> preparedStatementWriter,
java.util.List<io.micronaut.http.codec.MediaTypeCodec> codecs,
DateTimeProvider<java.lang.Object> dateTimeProvider,
RuntimeEntityRegistry runtimeEntityRegistry,
io.micronaut.context.BeanContext beanContext)
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected <T> T |
afterCascadedMany(T entity,
java.util.List<Association> associations,
java.lang.Iterable<java.lang.Object> prevChildren,
java.util.List<java.lang.Object> newChildren)
Process after a children element has been cascaded.
|
protected <T> T |
afterCascadedOne(T entity,
java.util.List<Association> associations,
java.lang.Object prevChild,
java.lang.Object newChild)
Process after a child element has been cascaded.
|
protected <T> void |
cascade(Dialect dialect,
io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
java.lang.Class<?> repositoryType,
boolean fkOnly,
Relation.Cascade cascadeType,
AbstractSqlRepositoryOperations.CascadeContext ctx,
RuntimePersistentEntity<T> persistentEntity,
T entity,
java.util.List<AbstractSqlRepositoryOperations.CascadeOp> cascadeOps)
Cascade on the entity instance and collect cascade operations.
|
protected void |
checkOptimisticLocking(int expected,
int received)
Compare the expected modifications and the received rows count.
|
protected <T> void |
deleteInBatch(Cnt connection,
Dialect dialect,
io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
AbstractSqlRepositoryOperations.EntitiesOperations<T> op)
Delete batch operation.
|
protected <T> void |
deleteOne(Cnt connection,
Dialect dialect,
io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
AbstractSqlRepositoryOperations.EntityOperations<T> op,
SqlQueryBuilder queryBuilder)
Delete one operation.
|
io.micronaut.context.ApplicationContext |
getApplicationContext() |
<T> RuntimePersistentEntity<T> |
getEntity(java.lang.Class<T> type) |
protected RuntimePersistentProperty<java.lang.Object> |
getIdReader(java.lang.Object o)
Obtain an ID reader for the given object.
|
protected boolean |
isOnlySingleEndedJoins(RuntimePersistentEntity<?> rootPersistentEntity,
java.util.Set<JoinPath> joinFetchPaths)
Check if joined associated are all single ended (Can produce only one result).
|
protected boolean |
isSqlServerWithoutOrderBy(java.lang.String query,
Dialect dialect)
In the dialect SQL server and is order by required.
|
protected boolean |
isSupportsBatchDelete(PersistentEntity persistentEntity,
Dialect dialect)
Does supports batch for delete queries.
|
protected boolean |
isSupportsBatchInsert(PersistentEntity persistentEntity,
Dialect dialect)
Does supports batch for update queries.
|
protected boolean |
isSupportsBatchUpdate(PersistentEntity persistentEntity,
Dialect dialect)
Does supports batch for update queries.
|
protected <T> void |
persistInBatch(Cnt connection,
io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
java.lang.Class<?> repositoryType,
AbstractSqlRepositoryOperations.SqlOperation sqlOperation,
java.util.List<Association> associations,
java.util.Set<java.lang.Object> persisted,
AbstractSqlRepositoryOperations.EntitiesOperations<T> op)
Persist batch operation.
|
protected <T> void |
persistJoinTableAssociation(Cnt connection,
java.lang.Class<?> repositoryType,
Dialect dialect,
Association association,
java.lang.Object parent,
AbstractSqlRepositoryOperations.BaseOperations<T> op)
Persist join table assocation.
|
protected <T> void |
persistOne(Cnt connection,
io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
java.lang.Class<?> repositoryType,
AbstractSqlRepositoryOperations.SqlOperation sqlOperation,
java.util.List<Association> associations,
java.util.Set<java.lang.Object> persisted,
AbstractSqlRepositoryOperations.EntityOperations<T> op)
Persist one operation.
|
protected <T,R> PS |
prepareStatement(AbstractSqlRepositoryOperations.StatementSupplier<PS> statementFunction,
PreparedQuery<T,R> preparedQuery,
boolean isUpdate,
boolean isSingleResult)
Prepare a statement for execution.
|
protected abstract void |
prepareStatement(Cnt connection,
Dialect dialect,
PersistentProperty identity,
boolean hasGeneratedID,
java.lang.String insertSql,
AbstractSqlRepositoryOperations.DBOperation1<PS,Exc> fn)
Prepare a statement and run a function.
|
protected abstract void |
prepareStatement(Cnt connection,
java.lang.String query,
AbstractSqlRepositoryOperations.DBOperation1<PS,Exc> fn)
Prepare a statement and run a function.
|
protected <T> java.lang.String |
resolveAssociationInsert(java.lang.Class repositoryType,
RuntimePersistentEntity<T> persistentEntity,
RuntimeAssociation<T> association)
Builds a join table insert.
|
protected AbstractSqlRepositoryOperations.SqlOperation |
resolveEntityInsert(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
java.lang.Class<?> repositoryType,
java.lang.Class<?> rootEntity,
RuntimePersistentEntity<?> persistentEntity)
Resolves a stored insert for the given entity.
|
protected AbstractSqlRepositoryOperations.SqlOperation |
resolveEntityUpdate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
java.lang.Class<?> repositoryType,
java.lang.Class<?> rootEntity,
RuntimePersistentEntity<?> persistentEntity)
Resolves a stored update for the given entity.
|
protected void |
setStatementParameter(PS preparedStatement,
int index,
DataType dataType,
java.lang.Object value,
Dialect dialect)
Set the parameter value on the given statement.
|
protected int |
shiftIndex(int i)
Used to define the index whether it is 1 based (JDBC) or 0 based (R2DBC).
|
protected int |
sizeOf(java.lang.Object value)
Compute the size of the given object.
|
protected <T> Sort |
sortById(RuntimePersistentEntity<T> persistentEntity)
Build a sort for ID for the given entity.
|
protected <T> T |
triggerPostLoad(T entity,
RuntimePersistentEntity<T> pe,
io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
Trigger the post load event.
|
protected <T> void |
updateInBatch(Cnt connection,
io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
java.lang.Class<?> repositoryType,
AbstractSqlRepositoryOperations.StoredSqlOperation sqlOperation,
java.util.List<Association> associations,
java.util.Set<java.lang.Object> persisted,
AbstractSqlRepositoryOperations.EntitiesOperations<T> op)
Update batch operation.
|
protected <T> void |
updateOne(Cnt connection,
io.micronaut.core.annotation.AnnotationMetadata annotationMetadata,
java.lang.Class<?> repositoryType,
AbstractSqlRepositoryOperations.SqlOperation sqlOperation,
java.util.List<Association> associations,
java.util.Set<java.lang.Object> persisted,
AbstractSqlRepositoryOperations.EntityOperations<T> op)
Update one operation.
|
protected static final org.slf4j.Logger QUERY_LOG
protected static final SqlQueryBuilder DEFAULT_SQL_BUILDER
protected final ResultReader<RS,java.lang.String> columnNameResultSetReader
protected final ResultReader<RS,java.lang.Integer> columnIndexResultSetReader
protected final QueryStatement<PS,java.lang.Integer> preparedStatementWriter
protected final java.util.Map<java.lang.Class,SqlQueryBuilder> queryBuilders
protected final io.micronaut.http.codec.MediaTypeCodec jsonCodec
protected final EntityEventListener<java.lang.Object> entityEventRegistry
protected final DateTimeProvider dateTimeProvider
protected final RuntimeEntityRegistry runtimeEntityRegistry
@Deprecated
protected AbstractSqlRepositoryOperations(java.lang.String dataSourceName,
ResultReader<RS,java.lang.String> columnNameResultSetReader,
ResultReader<RS,java.lang.Integer> columnIndexResultSetReader,
QueryStatement<PS,java.lang.Integer> preparedStatementWriter,
java.util.List<io.micronaut.http.codec.MediaTypeCodec> codecs,
DateTimeProvider<java.lang.Object> dateTimeProvider,
io.micronaut.context.BeanContext beanContext)
AbstractSqlRepositoryOperations(String, ResultReader, ResultReader, QueryStatement, List, DateTimeProvider, RuntimeEntityRegistry, BeanContext)dataSourceName - The datasource namecolumnNameResultSetReader - The column name result readercolumnIndexResultSetReader - The column index result readerpreparedStatementWriter - The prepared statement writercodecs - The media type codecsdateTimeProvider - The date time providerbeanContext - The bean contextprotected AbstractSqlRepositoryOperations(java.lang.String dataSourceName,
ResultReader<RS,java.lang.String> columnNameResultSetReader,
ResultReader<RS,java.lang.Integer> columnIndexResultSetReader,
QueryStatement<PS,java.lang.Integer> preparedStatementWriter,
java.util.List<io.micronaut.http.codec.MediaTypeCodec> codecs,
DateTimeProvider<java.lang.Object> dateTimeProvider,
RuntimeEntityRegistry runtimeEntityRegistry,
io.micronaut.context.BeanContext beanContext)
dataSourceName - The datasource namecolumnNameResultSetReader - The column name result readercolumnIndexResultSetReader - The column index result readerpreparedStatementWriter - The prepared statement writercodecs - The media type codecsdateTimeProvider - The date time providerruntimeEntityRegistry - The entity registrybeanContext - The bean contextpublic io.micronaut.context.ApplicationContext getApplicationContext()
getApplicationContext in interface io.micronaut.context.ApplicationContextProvider@NonNull public final <T> RuntimePersistentEntity<T> getEntity(@NonNull java.lang.Class<T> type)
protected <T,R> PS prepareStatement(AbstractSqlRepositoryOperations.StatementSupplier<PS> statementFunction, @NonNull PreparedQuery<T,R> preparedQuery, boolean isUpdate, boolean isSingleResult) throws Exc extends java.lang.Exception
T - The query declaring typeR - The query result typestatementFunction - The statement functionpreparedQuery - The prepared queryisUpdate - Is this an updateisSingleResult - Is it a single resultExc extends java.lang.Exceptionprotected abstract void prepareStatement(Cnt connection, java.lang.String query, AbstractSqlRepositoryOperations.DBOperation1<PS,Exc> fn) throws Exc extends java.lang.Exception
connection - The connection.query - The queryfn - The function to be run with a statementExc - The exception typeExc extends java.lang.Exceptionprotected abstract void prepareStatement(Cnt connection, Dialect dialect, PersistentProperty identity, boolean hasGeneratedID, java.lang.String insertSql, AbstractSqlRepositoryOperations.DBOperation1<PS,Exc> fn) throws Exc extends java.lang.Exception
connection - The connectiondialect - The dialectidentity - The identity propertyhasGeneratedID - Is genereted idenntityinsertSql - Te queryfn - The function to be run with a statementExc - The exception typeExc extends java.lang.Exceptionprotected <T> T afterCascadedOne(T entity,
java.util.List<Association> associations,
java.lang.Object prevChild,
java.lang.Object newChild)
T - The entity typeentity - The parent entity.associations - The association leading to the childprevChild - The previous child valuenewChild - The new child valueprotected <T> T afterCascadedMany(T entity,
java.util.List<Association> associations,
java.lang.Iterable<java.lang.Object> prevChildren,
java.util.List<java.lang.Object> newChildren)
T - The entity typeentity - The parent entity.associations - The association leading to the childprevChildren - The previous children valuenewChildren - The new children valueprotected <T> T triggerPostLoad(@NonNull
T entity,
RuntimePersistentEntity<T> pe,
io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
T - The generic typeentity - The entitype - The persistent entityannotationMetadata - The annotation metadataprotected <T> void persistOne(Cnt connection, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, AbstractSqlRepositoryOperations.SqlOperation sqlOperation, java.util.List<Association> associations, java.util.Set<java.lang.Object> persisted, AbstractSqlRepositoryOperations.EntityOperations<T> op)
T - The entity typeconnection - The connectionannotationMetadata - The annotationMetadatarepositoryType - The repositoryTypesqlOperation - The sql operationassociations - The associationspersisted - Already persisted valuesop - The operationprotected <T> void persistInBatch(Cnt connection, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, AbstractSqlRepositoryOperations.SqlOperation sqlOperation, java.util.List<Association> associations, java.util.Set<java.lang.Object> persisted, AbstractSqlRepositoryOperations.EntitiesOperations<T> op)
T - The entity typeconnection - The connectionannotationMetadata - The annotationMetadatarepositoryType - The repositoryTypesqlOperation - The sql operationassociations - The associationspersisted - Already persisted valuesop - The operationprotected <T> void deleteOne(Cnt connection, Dialect dialect, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, AbstractSqlRepositoryOperations.EntityOperations<T> op, SqlQueryBuilder queryBuilder)
T - The entity typeconnection - The connectiondialect - The dialectannotationMetadata - The annotationMetadataop - The operationqueryBuilder - The queryBuilderprotected <T> void deleteInBatch(Cnt connection, Dialect dialect, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, AbstractSqlRepositoryOperations.EntitiesOperations<T> op)
T - The entity typeconnection - The connectiondialect - The dialectannotationMetadata - The annotationMetadataop - The operationprotected <T> void updateOne(Cnt connection, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, AbstractSqlRepositoryOperations.SqlOperation sqlOperation, java.util.List<Association> associations, java.util.Set<java.lang.Object> persisted, AbstractSqlRepositoryOperations.EntityOperations<T> op)
T - The entity typeconnection - The connectionannotationMetadata - The annotationMetadatarepositoryType - The repositoryTypesqlOperation - The sql operationassociations - The associationspersisted - Already persisted valuesop - The operationprotected <T> void updateInBatch(Cnt connection, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, AbstractSqlRepositoryOperations.StoredSqlOperation sqlOperation, java.util.List<Association> associations, java.util.Set<java.lang.Object> persisted, AbstractSqlRepositoryOperations.EntitiesOperations<T> op)
T - The entity typeconnection - The connectionannotationMetadata - The annotationMetadatarepositoryType - The repositoryTypesqlOperation - The sql operationassociations - The associationspersisted - Already persisted valuesop - The operationprotected int shiftIndex(int i)
i - The index to shift@NonNull protected final RuntimePersistentProperty<java.lang.Object> getIdReader(@NonNull java.lang.Object o)
o - The object@NonNull protected final <T> Sort sortById(RuntimePersistentEntity<T> persistentEntity)
T - The entity typepersistentEntity - The entityprotected final boolean isSqlServerWithoutOrderBy(java.lang.String query,
Dialect dialect)
query - The querydialect - The dialectprotected final int sizeOf(java.lang.Object value)
value - The valueprotected final void setStatementParameter(PS preparedStatement, int index, DataType dataType, java.lang.Object value, Dialect dialect)
preparedStatement - The prepared statementindex - The indexdataType - The data typevalue - The valuedialect - The dialect@NonNull protected AbstractSqlRepositoryOperations.SqlOperation resolveEntityInsert(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, @NonNull java.lang.Class<?> rootEntity, @NonNull RuntimePersistentEntity<?> persistentEntity)
annotationMetadata - The repository annotation metadatarepositoryType - The repository typerootEntity - The root entitypersistentEntity - The persistent entityprotected <T> java.lang.String resolveAssociationInsert(java.lang.Class repositoryType,
RuntimePersistentEntity<T> persistentEntity,
RuntimeAssociation<T> association)
T - The entity generic typerepositoryType - The repository typepersistentEntity - The entityassociation - The associationprotected <T> void cascade(Dialect dialect, io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, boolean fkOnly, Relation.Cascade cascadeType, AbstractSqlRepositoryOperations.CascadeContext ctx, RuntimePersistentEntity<T> persistentEntity, T entity, java.util.List<AbstractSqlRepositoryOperations.CascadeOp> cascadeOps)
T - The entity typedialect - The dialectannotationMetadata - The annotationMetadatarepositoryType - The repositoryTypefkOnly - Is FK onlycascadeType - The cascadeTypectx - The cascade contextpersistentEntity - The persistent entityentity - The entity instancecascadeOps - The cascade operationsprotected <T> void persistJoinTableAssociation(Cnt connection, java.lang.Class<?> repositoryType, Dialect dialect, Association association, java.lang.Object parent, AbstractSqlRepositoryOperations.BaseOperations<T> op)
T - The entity typeconnection - The connectionrepositoryType - The repositoryTypedialect - The dialectassociation - The associationparent - The parentop - The operationprotected boolean isSupportsBatchInsert(PersistentEntity persistentEntity, Dialect dialect)
persistentEntity - The persistent entitydialect - The dialectprotected boolean isSupportsBatchUpdate(PersistentEntity persistentEntity, Dialect dialect)
persistentEntity - The persistent entitydialect - The dialectprotected boolean isSupportsBatchDelete(PersistentEntity persistentEntity, Dialect dialect)
persistentEntity - The persistent entitydialect - The dialect@NonNull protected AbstractSqlRepositoryOperations.SqlOperation resolveEntityUpdate(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, java.lang.Class<?> repositoryType, @NonNull java.lang.Class<?> rootEntity, @NonNull RuntimePersistentEntity<?> persistentEntity)
annotationMetadata - The repository annotation metadatarepositoryType - The repository typerootEntity - The root entitypersistentEntity - The persistent entityprotected void checkOptimisticLocking(int expected,
int received)
OptimisticLockException.expected - The expected valuereceived - THe received valueprotected boolean isOnlySingleEndedJoins(RuntimePersistentEntity<?> rootPersistentEntity, java.util.Set<JoinPath> joinFetchPaths)
rootPersistentEntity - The root entityjoinFetchPaths - The join paths