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);
}
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);
}
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;
}
}
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;
}
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);
}
Aggregations