Search in sources :

Example 11 with ColumnCondition

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

the class SelectQueryParser method getColumnQuery.

private ColumnQuery getColumnQuery(Params params, SelectQuery selectQuery, ColumnObserverParser observer) {
    String columnFamily = observer.fireEntity(selectQuery.getEntity());
    long limit = selectQuery.getLimit();
    long skip = selectQuery.getSkip();
    List<String> columns = selectQuery.getFields().stream().map(f -> observer.fireField(columnFamily, f)).collect(Collectors.toList());
    List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, columnFamily)).collect(toList());
    ColumnCondition condition = null;
    if (selectQuery.getWhere().isPresent()) {
        condition = selectQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).get();
    }
    return new DefaultColumnQuery(limit, skip, columnFamily, columns, sorts, condition);
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) SelectQuery(jakarta.nosql.query.SelectQuery) ColumnFamilyManager(jakarta.nosql.column.ColumnFamilyManager) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams) ColumnCondition(jakarta.nosql.column.ColumnCondition) Collectors(java.util.stream.Collectors) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) SelectQueryConverter(jakarta.nosql.column.SelectQueryConverter) Objects(java.util.Objects) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) SelectQueryProvider(jakarta.nosql.query.SelectQuery.SelectQueryProvider) ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) ColumnQuery(jakarta.nosql.column.ColumnQuery) Sort(jakarta.nosql.Sort) ColumnObserverParser(jakarta.nosql.column.ColumnObserverParser) Params(jakarta.nosql.Params) Sort(jakarta.nosql.Sort) ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 12 with ColumnCondition

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

the class SelectQueryParser method getColumnQuery.

private ColumnQuery getColumnQuery(String query, ColumnObserverParser observer) {
    SelectQuery selectQuery = selectQueryProvider.apply(query);
    String columnFamily = observer.fireEntity(selectQuery.getEntity());
    long limit = selectQuery.getLimit();
    long skip = selectQuery.getSkip();
    List<String> columns = selectQuery.getFields().stream().map(f -> observer.fireField(columnFamily, f)).collect(Collectors.toList());
    List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, columnFamily)).collect(toList());
    ColumnCondition condition = null;
    Params params = Params.newParams();
    if (selectQuery.getWhere().isPresent()) {
        condition = selectQuery.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 DefaultColumnQuery(limit, skip, columnFamily, columns, sorts, condition);
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) SelectQuery(jakarta.nosql.query.SelectQuery) ColumnFamilyManager(jakarta.nosql.column.ColumnFamilyManager) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams) ColumnCondition(jakarta.nosql.column.ColumnCondition) Collectors(java.util.stream.Collectors) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) SelectQueryConverter(jakarta.nosql.column.SelectQueryConverter) Objects(java.util.Objects) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) SelectQueryProvider(jakarta.nosql.query.SelectQuery.SelectQueryProvider) ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) ColumnQuery(jakarta.nosql.column.ColumnQuery) Sort(jakarta.nosql.Sort) ColumnObserverParser(jakarta.nosql.column.ColumnObserverParser) Params(jakarta.nosql.Params) QueryException(jakarta.nosql.QueryException) Sort(jakarta.nosql.Sort) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams) Params(jakarta.nosql.Params) ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 13 with ColumnCondition

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

the class BaseQueryBuilder method likeImpl.

protected void likeImpl(String value) {
    requireNonNull(value, "value is required");
    ColumnCondition newCondition = ColumnCondition.like(Column.of(name, value));
    appendCondition(newCondition);
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 14 with ColumnCondition

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

the class BaseQueryBuilder method ltImpl.

protected <T> void ltImpl(T value) {
    requireNonNull(value, "value is required");
    ColumnCondition newCondition = ColumnCondition.lt(Column.of(name, value));
    appendCondition(newCondition);
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 15 with ColumnCondition

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

the class BaseQueryBuilder method gtImpl.

protected <T> void gtImpl(T value) {
    requireNonNull(value, "value is required");
    ColumnCondition newCondition = ColumnCondition.gt(Column.of(name, value));
    appendCondition(newCondition);
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition)

Aggregations

ColumnCondition (jakarta.nosql.column.ColumnCondition)130 Test (org.junit.jupiter.api.Test)68 ColumnQuery (jakarta.nosql.column.ColumnQuery)64 Column (jakarta.nosql.column.Column)57 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 ValueSource (org.junit.jupiter.params.provider.ValueSource)37 List (java.util.List)34 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)33 Person (jakarta.nosql.tck.entities.Person)17 Pagination (jakarta.nosql.mapping.Pagination)13 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)10 TypeReference (jakarta.nosql.TypeReference)7 Params (jakarta.nosql.Params)6 ColumnEntity (jakarta.nosql.column.ColumnEntity)6 Collections.singletonList (java.util.Collections.singletonList)5 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)4 ColumnObserverParser (jakarta.nosql.column.ColumnObserverParser)4 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)4