Search in sources :

Example 1 with AbstractPersistentEntityCriteriaDelete

use of io.micronaut.data.model.jpa.criteria.impl.AbstractPersistentEntityCriteriaDelete in project micronaut-data by micronaut-projects.

the class DeleteCriteriaMethodMatch method build.

@Override
protected MethodMatchInfo build(MethodMatchContext matchContext) {
    MethodMatchSourcePersistentEntityCriteriaBuilderImpl cb = new MethodMatchSourcePersistentEntityCriteriaBuilderImpl(matchContext);
    PersistentEntityCriteriaDelete<Object> criteriaQuery = cb.createCriteriaDelete(null);
    apply(matchContext, criteriaQuery.from(matchContext.getRootEntity()), criteriaQuery, cb);
    Map.Entry<ClassElement, Class<? extends DataInterceptor>> entry = resolveReturnTypeAndInterceptor(matchContext);
    ClassElement resultType = entry.getKey();
    Class<? extends DataInterceptor> interceptorType = entry.getValue();
    boolean optimisticLock = ((AbstractPersistentEntityCriteriaDelete<?>) criteriaQuery).hasVersionRestriction();
    final AnnotationMetadataHierarchy annotationMetadataHierarchy = new AnnotationMetadataHierarchy(matchContext.getRepositoryClass().getAnnotationMetadata(), matchContext.getAnnotationMetadata());
    QueryBuilder queryBuilder = matchContext.getQueryBuilder();
    QueryModel queryModel = ((QueryModelPersistentEntityCriteriaQuery) criteriaQuery).getQueryModel();
    QueryResult queryResult = queryBuilder.buildDelete(annotationMetadataHierarchy, queryModel);
    return new MethodMatchInfo(DataMethod.OperationType.DELETE, resultType, getInterceptorElement(matchContext, interceptorType)).optimisticLock(optimisticLock).queryResult(queryResult);
}
Also used : DataInterceptor(io.micronaut.data.intercept.DataInterceptor) ClassElement(io.micronaut.inject.ast.ClassElement) QueryBuilder(io.micronaut.data.model.query.builder.QueryBuilder) AnnotationMetadataHierarchy(io.micronaut.data.processor.visitors.AnnotationMetadataHierarchy) QueryModel(io.micronaut.data.model.query.QueryModel) QueryModelPersistentEntityCriteriaQuery(io.micronaut.data.model.jpa.criteria.impl.QueryModelPersistentEntityCriteriaQuery) QueryResult(io.micronaut.data.model.query.builder.QueryResult) MethodMatchInfo(io.micronaut.data.processor.visitors.finders.MethodMatchInfo) MethodMatchSourcePersistentEntityCriteriaBuilderImpl(io.micronaut.data.processor.model.criteria.impl.MethodMatchSourcePersistentEntityCriteriaBuilderImpl) AbstractPersistentEntityCriteriaDelete(io.micronaut.data.model.jpa.criteria.impl.AbstractPersistentEntityCriteriaDelete) Map(java.util.Map)

Aggregations

DataInterceptor (io.micronaut.data.intercept.DataInterceptor)1 AbstractPersistentEntityCriteriaDelete (io.micronaut.data.model.jpa.criteria.impl.AbstractPersistentEntityCriteriaDelete)1 QueryModelPersistentEntityCriteriaQuery (io.micronaut.data.model.jpa.criteria.impl.QueryModelPersistentEntityCriteriaQuery)1 QueryModel (io.micronaut.data.model.query.QueryModel)1 QueryBuilder (io.micronaut.data.model.query.builder.QueryBuilder)1 QueryResult (io.micronaut.data.model.query.builder.QueryResult)1 MethodMatchSourcePersistentEntityCriteriaBuilderImpl (io.micronaut.data.processor.model.criteria.impl.MethodMatchSourcePersistentEntityCriteriaBuilderImpl)1 AnnotationMetadataHierarchy (io.micronaut.data.processor.visitors.AnnotationMetadataHierarchy)1 MethodMatchInfo (io.micronaut.data.processor.visitors.finders.MethodMatchInfo)1 ClassElement (io.micronaut.inject.ast.ClassElement)1 Map (java.util.Map)1