Search in sources :

Example 76 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParser method getQuery.

private DocumentDeleteQuery getQuery(Params params, DocumentObserverParser observer, DeleteQuery deleteQuery) {
    String collection = observer.fireEntity(deleteQuery.getEntity());
    List<String> documents = deleteQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
    DocumentCondition condition = null;
    if (deleteQuery.getWhere().isPresent()) {
        condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
    }
    return new DefaultDocumentDeleteQuery(collection, condition, documents);
}
Also used : DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) DeleteQueryConverter(jakarta.nosql.document.DeleteQueryConverter) DeleteQuery(jakarta.nosql.query.DeleteQuery) Objects(java.util.Objects) List(java.util.List) DeleteQueryProvider(jakarta.nosql.query.DeleteQuery.DeleteQueryProvider) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) DocumentObserverParser(jakarta.nosql.document.DocumentObserverParser) Params(jakarta.nosql.Params) DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 77 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParser method prepare.

DocumentPreparedStatement prepare(String query, DocumentCollectionManager collectionManager, DocumentObserverParser observer) {
    Params params = Params.newParams();
    DocumentDeleteQuery documentQuery = getQuery(query, params, observer);
    return DefaultDocumentPreparedStatement.delete(documentQuery, params, query, collectionManager);
}
Also used : DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) Params(jakarta.nosql.Params) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery)

Example 78 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.

the class AbstractDocumentRepositoryProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    RepositoryType type = RepositoryType.of(method);
    Class<?> typeClass = getClassMapping().getClassInstance();
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            DocumentQuery query = getQuery(method, args);
            return executeQuery(method, args, typeClass, query);
        case FIND_ALL:
            DocumentQuery queryFindAll = select().from(getClassMapping().getName()).build();
            return executeQuery(method, args, typeClass, getQuerySorts(args, queryFindAll));
        case DELETE_BY:
            DocumentDeleteQuery documentDeleteQuery = getDeleteQuery(method, args);
            getTemplate().delete(documentDeleteQuery);
            return null;
        case OBJECT_METHOD:
            return method.invoke(this, args);
        case JNOSQL_QUERY:
            DynamicQueryMethodReturn methodReturn = DynamicQueryMethodReturn.builder().withArgs(args).withMethod(method).withTypeClass(typeClass).withPrepareConverter(q -> getTemplate().prepare(q)).withQueryConverter(q -> getTemplate().query(q)).build();
            return methodReturn.execute();
        default:
            return Void.class;
    }
}
Also used : DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) Repository(jakarta.nosql.mapping.Repository) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) InvocationHandler(java.lang.reflect.InvocationHandler) Method(java.lang.reflect.Method) DocumentQuery(jakarta.nosql.document.DocumentQuery) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery)

Example 79 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.

the class BaseDocumentRepository method getDeleteQuery.

protected DocumentDeleteQuery getDeleteQuery(Method method, Object[] args) {
    DeleteMethodProvider methodProvider = DeleteMethodProvider.get();
    DeleteQuery deleteQuery = methodProvider.apply(method, getClassMapping().getName());
    DeleteQueryConverter converter = ServiceLoaderProvider.get(DeleteQueryConverter.class);
    DocumentDeleteQueryParams queryParams = converter.apply(deleteQuery, getParser());
    DocumentDeleteQuery query = queryParams.getQuery();
    Params params = queryParams.getParams();
    getParamsBinder().bind(params, args, method);
    return query;
}
Also used : DeleteMethodProvider(org.eclipse.jnosql.communication.query.method.DeleteMethodProvider) DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) DeleteQueryConverter(jakarta.nosql.document.DeleteQueryConverter) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) Params(jakarta.nosql.Params) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) DeleteQuery(jakarta.nosql.query.DeleteQuery) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery)

Example 80 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.

the class DefaultDocumentMapperDeleteBuilderTest method shouldSelectWhereNameEq.

@Test
public void shouldSelectWhereNameEq() {
    DocumentDeleteQuery query = mapperBuilder.deleteFrom(Person.class).where("name").eq("Ada").build();
    DocumentDeleteQuery queryExpected = delete().from("Person").where("name").eq("Ada").build();
    assertEquals(queryExpected, query);
}
Also used : Person(jakarta.nosql.tck.entities.Person) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)114 Test (org.junit.jupiter.api.Test)79 DocumentEntity (jakarta.nosql.document.DocumentEntity)45 DocumentQuery (jakarta.nosql.document.DocumentQuery)43 Document (jakarta.nosql.document.Document)37 DocumentCondition (jakarta.nosql.document.DocumentCondition)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ValueSource (org.junit.jupiter.params.provider.ValueSource)20 List (java.util.List)15 Person (jakarta.nosql.tck.entities.Person)12 Collectors (java.util.stream.Collectors)7 Params (jakarta.nosql.Params)5 DocumentDeleteQueryParams (jakarta.nosql.document.DocumentDeleteQueryParams)5 Duration (java.time.Duration)5 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 StreamSupport (java.util.stream.StreamSupport)5 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)4 Map (java.util.Map)4