Search in sources :

Example 1 with DeleteQuery

use of jakarta.nosql.query.DeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParser method getQuery.

private ColumnDeleteQuery getQuery(Params params, ColumnObserverParser observer, DeleteQuery deleteQuery) {
    String columnFamily = observer.fireEntity(deleteQuery.getEntity());
    List<String> columns = deleteQuery.getFields().stream().map(f -> observer.fireField(columnFamily, f)).collect(Collectors.toList());
    ColumnCondition condition = null;
    if (deleteQuery.getWhere().isPresent()) {
        condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).get();
    }
    return new DefaultColumnDeleteQuery(columnFamily, condition, columns);
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) DeleteQueryConverter(jakarta.nosql.column.DeleteQueryConverter) ColumnFamilyManager(jakarta.nosql.column.ColumnFamilyManager) ColumnCondition(jakarta.nosql.column.ColumnCondition) Collectors(java.util.stream.Collectors) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) DeleteQuery(jakarta.nosql.query.DeleteQuery) List(java.util.List) DeleteQueryProvider(jakarta.nosql.query.DeleteQuery.DeleteQueryProvider) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnDeleteQueryParams(jakarta.nosql.column.ColumnDeleteQueryParams) ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) ColumnObserverParser(jakarta.nosql.column.ColumnObserverParser) Params(jakarta.nosql.Params) ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 2 with DeleteQuery

use of jakarta.nosql.query.DeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParser method getQuery.

private ColumnDeleteQuery getQuery(String query, ColumnObserverParser observer) {
    DeleteQuery deleteQuery = deleteQueryProvider.apply(query);
    String columnFamily = observer.fireEntity(deleteQuery.getEntity());
    List<String> columns = deleteQuery.getFields().stream().map(f -> observer.fireField(columnFamily, f)).collect(Collectors.toList());
    ColumnCondition condition = null;
    Params params = Params.newParams();
    if (deleteQuery.getWhere().isPresent()) {
        condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).get();
    }
    if (params.isNotEmpty()) {
        throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
    }
    return new DefaultColumnDeleteQuery(columnFamily, condition, columns);
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) DeleteQueryConverter(jakarta.nosql.column.DeleteQueryConverter) ColumnFamilyManager(jakarta.nosql.column.ColumnFamilyManager) ColumnCondition(jakarta.nosql.column.ColumnCondition) Collectors(java.util.stream.Collectors) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) DeleteQuery(jakarta.nosql.query.DeleteQuery) List(java.util.List) DeleteQueryProvider(jakarta.nosql.query.DeleteQuery.DeleteQueryProvider) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnDeleteQueryParams(jakarta.nosql.column.ColumnDeleteQueryParams) ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) ColumnObserverParser(jakarta.nosql.column.ColumnObserverParser) Params(jakarta.nosql.Params) QueryException(jakarta.nosql.QueryException) ColumnDeleteQueryParams(jakarta.nosql.column.ColumnDeleteQueryParams) Params(jakarta.nosql.Params) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) DeleteQuery(jakarta.nosql.query.DeleteQuery) ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 3 with DeleteQuery

use of jakarta.nosql.query.DeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParser method getQuery.

private DocumentDeleteQuery getQuery(String query, DocumentObserverParser observer) {
    DeleteQuery deleteQuery = deleteQueryProvider.apply(query);
    String collection = observer.fireEntity(deleteQuery.getEntity());
    List<String> documents = deleteQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
    DocumentCondition condition = null;
    Params params = Params.newParams();
    if (deleteQuery.getWhere().isPresent()) {
        condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
    }
    if (params.isNotEmpty()) {
        throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
    }
    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) QueryException(jakarta.nosql.QueryException) DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) Params(jakarta.nosql.Params) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) DeleteQuery(jakarta.nosql.query.DeleteQuery) DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 4 with DeleteQuery

use of jakarta.nosql.query.DeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryConverter method apply.

@Override
public List<Vertex> apply(GraphQueryMethod graphQuery) {
    DeleteMethodProvider provider = DeleteMethodProvider.get();
    DeleteQuery deleteQuery = provider.apply(graphQuery.getMethod(), graphQuery.getEntityName());
    ClassMapping mapping = graphQuery.getMapping();
    GraphTraversal<Vertex, Vertex> traversal = getGraphTraversal(graphQuery, deleteQuery::getWhere, mapping);
    traversal.hasLabel(mapping.getName());
    return traversal.toList();
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DeleteMethodProvider(org.eclipse.jnosql.communication.query.method.DeleteMethodProvider) DeleteQuery(jakarta.nosql.query.DeleteQuery)

Example 5 with DeleteQuery

use of jakarta.nosql.query.DeleteQuery in project jnosql-diana by eclipse.

the class DeleteByMethodQueryProviderTest method shouldRunQuery29.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "deleteBySalary_Currency" })
public void shouldRunQuery29(String query) {
    String entity = "entity";
    DeleteQuery deleteQuery = queryProvider.apply(query, entity);
    assertNotNull(deleteQuery);
    assertEquals(entity, deleteQuery.getEntity());
    assertTrue(deleteQuery.getFields().isEmpty());
    Optional<Where> where = deleteQuery.getWhere();
    assertTrue(where.isPresent());
    Condition condition = where.get().getCondition();
    Assertions.assertEquals("salary.currency", condition.getName());
}
Also used : Condition(jakarta.nosql.query.Condition) DeleteQuery(jakarta.nosql.query.DeleteQuery) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DeleteQuery (jakarta.nosql.query.DeleteQuery)40 Where (jakarta.nosql.query.Where)30 Condition (jakarta.nosql.query.Condition)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 ValueSource (org.junit.jupiter.params.provider.ValueSource)28 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)11 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)11 StringQueryValue (jakarta.nosql.query.StringQueryValue)9 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)8 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)7 JsonObject (javax.json.JsonObject)7 Params (jakarta.nosql.Params)6 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)4 DeleteQueryProvider (jakarta.nosql.query.DeleteQuery.DeleteQueryProvider)4 FunctionQueryValue (jakarta.nosql.query.FunctionQueryValue)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4