Search in sources :

Example 1 with InsertOperation

use of io.micronaut.data.model.runtime.InsertOperation in project micronaut-data by micronaut-projects.

the class DefaultJdbcRepositoryOperations method persist.

@NonNull
@Override
public <T> T persist(@NonNull InsertOperation<T> operation) {
    final AnnotationMetadata annotationMetadata = operation.getAnnotationMetadata();
    final Class<?> repositoryType = operation.getRepositoryType();
    SqlQueryBuilder queryBuilder = queryBuilders.getOrDefault(repositoryType, DEFAULT_SQL_BUILDER);
    return executeWrite(connection -> {
        JdbcOperationContext ctx = new JdbcOperationContext(annotationMetadata, repositoryType, queryBuilder.dialect(), connection);
        JdbcEntityOperations<T> op = new JdbcEntityOperations<>(ctx, new StoredQuerySqlOperation(queryBuilder, operation.getStoredQuery()), getEntity(operation.getRootEntity()), operation.getEntity(), true);
        op.persist();
        return op;
    }).getEntity();
}
Also used : DataType(io.micronaut.data.model.DataType) Arrays(java.util.Arrays) ExecutorReactiveOperations(io.micronaut.data.runtime.operations.ExecutorReactiveOperations) Internal(io.micronaut.core.annotation.Internal) ResultSet(java.sql.ResultSet) Map(java.util.Map) DataJdbcConfiguration(io.micronaut.data.jdbc.config.DataJdbcConfiguration) ArgumentUtils(io.micronaut.core.util.ArgumentUtils) RuntimePersistentProperty(io.micronaut.data.model.runtime.RuntimePersistentProperty) DBOperation(io.micronaut.data.runtime.operations.internal.DBOperation) Set(java.util.Set) PreparedStatement(java.sql.PreparedStatement) Executors(java.util.concurrent.Executors) PreparedQuery(io.micronaut.data.model.runtime.PreparedQuery) Serializable(java.io.Serializable) Stream(java.util.stream.Stream) Dialect(io.micronaut.data.model.query.builder.sql.Dialect) Parameter(io.micronaut.context.annotation.Parameter) SqlDTOMapper(io.micronaut.data.runtime.mapper.sql.SqlDTOMapper) BeanProperty(io.micronaut.core.beans.BeanProperty) ArrayList(java.util.ArrayList) TypeMapper(io.micronaut.data.runtime.mapper.TypeMapper) SQLException(java.sql.SQLException) OperationContext(io.micronaut.data.runtime.operations.internal.OperationContext) Nullable(io.micronaut.core.annotation.Nullable) ReactiveCapableRepository(io.micronaut.data.operations.reactive.ReactiveCapableRepository) ExecutorAsyncOperations(io.micronaut.data.runtime.operations.ExecutorAsyncOperations) StreamSupport(java.util.stream.StreamSupport) Argument(io.micronaut.core.type.Argument) AbstractConversionContext(io.micronaut.data.runtime.support.AbstractConversionContext) JdbcConversionContext(io.micronaut.data.jdbc.convert.JdbcConversionContext) AttributeConverterRegistry(io.micronaut.data.model.runtime.AttributeConverterRegistry) ReactiveRepositoryOperations(io.micronaut.data.operations.reactive.ReactiveRepositoryOperations) StoredQuerySqlOperation(io.micronaut.data.runtime.operations.internal.StoredQuerySqlOperation) InsertBatchOperation(io.micronaut.data.model.runtime.InsertBatchOperation) JoinPath(io.micronaut.data.model.query.JoinPath) Statement(java.sql.Statement) InsertOperation(io.micronaut.data.model.runtime.InsertOperation) AbstractSyncEntitiesOperations(io.micronaut.data.runtime.operations.internal.AbstractSyncEntitiesOperations) UpdateBatchOperation(io.micronaut.data.model.runtime.UpdateBatchOperation) UpdateOperation(io.micronaut.data.model.runtime.UpdateOperation) RuntimePersistentPropertyConversionContext(io.micronaut.data.runtime.convert.RuntimePersistentPropertyConversionContext) Connection(java.sql.Connection) BeanContext(io.micronaut.context.BeanContext) Spliterators(java.util.Spliterators) LoggerFactory(org.slf4j.LoggerFactory) DataSourceUtils(io.micronaut.transaction.jdbc.DataSourceUtils) PreDestroy(javax.annotation.PreDestroy) EachBean(io.micronaut.context.annotation.EachBean) SqlQueryBuilder(io.micronaut.data.model.query.builder.sql.SqlQueryBuilder) DataAccessException(io.micronaut.data.exceptions.DataAccessException) DeleteOperation(io.micronaut.data.model.runtime.DeleteOperation) RuntimeAssociation(io.micronaut.data.model.runtime.RuntimeAssociation) AsyncCapableRepository(io.micronaut.data.operations.async.AsyncCapableRepository) DTOMapper(io.micronaut.data.runtime.mapper.DTOMapper) ConnectionCallback(io.micronaut.data.jdbc.runtime.ConnectionCallback) Predicate(java.util.function.Predicate) SqlResultConsumer(io.micronaut.data.jdbc.mapper.SqlResultConsumer) AbstractSqlRepositoryOperations(io.micronaut.data.runtime.operations.internal.AbstractSqlRepositoryOperations) PreparedStatementCallback(io.micronaut.data.jdbc.runtime.PreparedStatementCallback) Collectors(java.util.stream.Collectors) StoredSqlOperation(io.micronaut.data.runtime.operations.internal.StoredSqlOperation) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) SqlTypeMapper(io.micronaut.data.runtime.mapper.sql.SqlTypeMapper) Spliterator(java.util.Spliterator) Named(jakarta.inject.Named) ColumnIndexResultSetReader(io.micronaut.data.jdbc.mapper.ColumnIndexResultSetReader) QueryParameterBinding(io.micronaut.data.model.runtime.QueryParameterBinding) TransactionOperations(io.micronaut.transaction.TransactionOperations) ArgumentConversionContext(io.micronaut.core.convert.ArgumentConversionContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RuntimeEntityRegistry(io.micronaut.data.model.runtime.RuntimeEntityRegistry) Function(java.util.function.Function) DelegatingDataSource(io.micronaut.transaction.jdbc.DelegatingDataSource) JdbcQueryStatement(io.micronaut.data.jdbc.mapper.JdbcQueryStatement) Page(io.micronaut.data.model.Page) DataSource(javax.sql.DataSource) OpContext(io.micronaut.data.runtime.operations.internal.OpContext) NoSuchElementException(java.util.NoSuchElementException) DateTimeProvider(io.micronaut.data.runtime.date.DateTimeProvider) ExecutorService(java.util.concurrent.ExecutorService) MediaTypeCodec(io.micronaut.http.codec.MediaTypeCodec) PagedQuery(io.micronaut.data.model.runtime.PagedQuery) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) AbstractSyncEntityOperations(io.micronaut.data.runtime.operations.internal.AbstractSyncEntityOperations) DataConversionService(io.micronaut.data.runtime.convert.DataConversionService) ResultConsumer(io.micronaut.data.runtime.mapper.ResultConsumer) SyncCascadeOperations(io.micronaut.data.runtime.operations.internal.SyncCascadeOperations) Consumer(java.util.function.Consumer) NonNull(io.micronaut.core.annotation.NonNull) ConversionContext(io.micronaut.core.convert.ConversionContext) ColumnNameResultSetReader(io.micronaut.data.jdbc.mapper.ColumnNameResultSetReader) DeleteBatchOperation(io.micronaut.data.model.runtime.DeleteBatchOperation) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) RuntimePersistentEntity(io.micronaut.data.model.runtime.RuntimePersistentEntity) ResultReader(io.micronaut.data.runtime.mapper.ResultReader) SqlResultEntityTypeMapper(io.micronaut.data.runtime.mapper.sql.SqlResultEntityTypeMapper) SqlQueryBuilder(io.micronaut.data.model.query.builder.sql.SqlQueryBuilder) StoredQuerySqlOperation(io.micronaut.data.runtime.operations.internal.StoredQuerySqlOperation) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) NonNull(io.micronaut.core.annotation.NonNull)

Aggregations

BeanContext (io.micronaut.context.BeanContext)1 EachBean (io.micronaut.context.annotation.EachBean)1 Parameter (io.micronaut.context.annotation.Parameter)1 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)1 Internal (io.micronaut.core.annotation.Internal)1 NonNull (io.micronaut.core.annotation.NonNull)1 Nullable (io.micronaut.core.annotation.Nullable)1 BeanProperty (io.micronaut.core.beans.BeanProperty)1 ArgumentConversionContext (io.micronaut.core.convert.ArgumentConversionContext)1 ConversionContext (io.micronaut.core.convert.ConversionContext)1 Argument (io.micronaut.core.type.Argument)1 ArgumentUtils (io.micronaut.core.util.ArgumentUtils)1 DataAccessException (io.micronaut.data.exceptions.DataAccessException)1 DataJdbcConfiguration (io.micronaut.data.jdbc.config.DataJdbcConfiguration)1 JdbcConversionContext (io.micronaut.data.jdbc.convert.JdbcConversionContext)1 ColumnIndexResultSetReader (io.micronaut.data.jdbc.mapper.ColumnIndexResultSetReader)1 ColumnNameResultSetReader (io.micronaut.data.jdbc.mapper.ColumnNameResultSetReader)1 JdbcQueryStatement (io.micronaut.data.jdbc.mapper.JdbcQueryStatement)1 SqlResultConsumer (io.micronaut.data.jdbc.mapper.SqlResultConsumer)1 ConnectionCallback (io.micronaut.data.jdbc.runtime.ConnectionCallback)1