Search in sources :

Example 1 with ColumnDeleteQuery

use of jakarta.nosql.column.ColumnDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParser method query.

Stream<ColumnEntity> query(String query, ColumnFamilyManager manager, ColumnObserverParser observer) {
    ColumnDeleteQuery columnDeleteQuery = cache.get(query, observer);
    manager.delete(columnDeleteQuery);
    return Stream.empty();
}
Also used : ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery)

Example 2 with ColumnDeleteQuery

use of jakarta.nosql.column.ColumnDeleteQuery 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 3 with ColumnDeleteQuery

use of jakarta.nosql.column.ColumnDeleteQuery 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 4 with ColumnDeleteQuery

use of jakarta.nosql.column.ColumnDeleteQuery in project jnosql-diana by eclipse.

the class DefaultColumnMapperDeleteBuilderTest method shouldExecuteDeleteFrom.

@Test
public void shouldExecuteDeleteFrom() {
    ColumnTemplate template = Mockito.mock(ColumnTemplate.class);
    ArgumentCaptor<ColumnDeleteQuery> queryCaptor = ArgumentCaptor.forClass(ColumnDeleteQuery.class);
    mapperBuilder.deleteFrom(Person.class).delete(template);
    Mockito.verify(template).delete(queryCaptor.capture());
    ColumnDeleteQuery query = queryCaptor.getValue();
    ColumnDeleteQuery queryExpected = delete().from("Person").build();
    assertEquals(queryExpected, query);
}
Also used : ColumnTemplate(jakarta.nosql.mapping.column.ColumnTemplate) Person(jakarta.nosql.tck.entities.Person) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 5 with ColumnDeleteQuery

use of jakarta.nosql.column.ColumnDeleteQuery in project jnosql-diana by eclipse.

the class DefaultColumnMapperDeleteBuilderTest method shouldSelectWhereNameOr.

@Test
public void shouldSelectWhereNameOr() {
    ColumnDeleteQuery query = mapperBuilder.deleteFrom(Person.class).where("id").between(10, 20).or("name").eq("Ada").build();
    ColumnDeleteQuery queryExpected = delete().from("Person").where("_id").between(10L, 20L).or("name").eq("Ada").build();
    assertEquals(queryExpected, query);
}
Also used : Person(jakarta.nosql.tck.entities.Person) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)70 Test (org.junit.jupiter.api.Test)41 ColumnCondition (jakarta.nosql.column.ColumnCondition)33 Column (jakarta.nosql.column.Column)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ValueSource (org.junit.jupiter.params.provider.ValueSource)20 Person (jakarta.nosql.tck.entities.Person)12 List (java.util.List)12 ColumnEntity (jakarta.nosql.column.ColumnEntity)6 Params (jakarta.nosql.Params)5 ColumnDeleteQueryParams (jakarta.nosql.column.ColumnDeleteQueryParams)5 ColumnQuery (jakarta.nosql.column.ColumnQuery)5 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)4 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)3 DeleteQuery (jakarta.nosql.query.DeleteQuery)3 Optional (java.util.Optional)3 QueryException (jakarta.nosql.QueryException)2 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)2 ColumnObserverParser (jakarta.nosql.column.ColumnObserverParser)2 DeleteQueryConverter (jakarta.nosql.column.DeleteQueryConverter)2