Search in sources :

Example 1 with SelectQuery

use of jakarta.nosql.query.SelectQuery 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 2 with SelectQuery

use of jakarta.nosql.query.SelectQuery 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 3 with SelectQuery

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

the class SelectQueryParser method getDocumentQuery.

private DocumentQuery getDocumentQuery(String query, DocumentObserverParser observer) {
    SelectQuery selectQuery = selectQueryProvider.apply(query);
    String collection = observer.fireEntity(selectQuery.getEntity());
    long limit = selectQuery.getLimit();
    long skip = selectQuery.getSkip();
    List<String> documents = selectQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
    List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, collection)).collect(toList());
    DocumentCondition condition = null;
    Params params = Params.newParams();
    if (selectQuery.getWhere().isPresent()) {
        condition = selectQuery.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 DefaultDocumentQuery(limit, skip, collection, documents, sorts, condition);
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) SelectQuery(jakarta.nosql.query.SelectQuery) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) Objects(java.util.Objects) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) DocumentQuery(jakarta.nosql.document.DocumentQuery) SelectQueryConverter(jakarta.nosql.document.SelectQueryConverter) QueryException(jakarta.nosql.QueryException) SelectQueryProvider(jakarta.nosql.query.SelectQuery.SelectQueryProvider) Sort(jakarta.nosql.Sort) DocumentObserverParser(jakarta.nosql.document.DocumentObserverParser) Params(jakarta.nosql.Params) QueryException(jakarta.nosql.QueryException) Sort(jakarta.nosql.Sort) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) Params(jakarta.nosql.Params) DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 4 with SelectQuery

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

the class SelectQueryParser method getDocumentQuery.

private DocumentQuery getDocumentQuery(Params params, SelectQuery selectQuery, DocumentObserverParser observer) {
    String collection = observer.fireEntity(selectQuery.getEntity());
    long limit = selectQuery.getLimit();
    long skip = selectQuery.getSkip();
    List<String> documents = selectQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
    List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, collection)).collect(toList());
    DocumentCondition condition = null;
    if (selectQuery.getWhere().isPresent()) {
        condition = selectQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
    }
    return new DefaultDocumentQuery(limit, skip, collection, documents, sorts, condition);
}
Also used : DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) SelectQuery(jakarta.nosql.query.SelectQuery) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) Objects(java.util.Objects) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) DocumentQuery(jakarta.nosql.document.DocumentQuery) SelectQueryConverter(jakarta.nosql.document.SelectQueryConverter) QueryException(jakarta.nosql.QueryException) SelectQueryProvider(jakarta.nosql.query.SelectQuery.SelectQueryProvider) Sort(jakarta.nosql.Sort) DocumentObserverParser(jakarta.nosql.document.DocumentObserverParser) Params(jakarta.nosql.Params) Sort(jakarta.nosql.Sort) DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 5 with SelectQuery

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

the class SelectQueryProviderTest method shouldReturnParserQuery15.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name = \"diana\"" })
public void shouldReturnParserQuery15(String query) {
    SelectQuery selectQuery = checkSelectFromStart(query);
    assertTrue(selectQuery.getWhere().isPresent());
    Where where = selectQuery.getWhere().get();
    Condition condition = where.getCondition();
    QueryValue<?> value = condition.getValue();
    Assertions.assertEquals(Operator.EQUALS, condition.getOperator());
    assertEquals("name", condition.getName());
    assertTrue(value instanceof StringQueryValue);
    assertEquals("diana", value.get());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) StringQueryValue(jakarta.nosql.query.StringQueryValue) Where(jakarta.nosql.query.Where) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SelectQuery (jakarta.nosql.query.SelectQuery)55 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 ValueSource (org.junit.jupiter.params.provider.ValueSource)36 Where (jakarta.nosql.query.Where)32 Condition (jakarta.nosql.query.Condition)31 Params (jakarta.nosql.Params)12 ConditionQueryValue (jakarta.nosql.query.ConditionQueryValue)11 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)11 StringQueryValue (jakarta.nosql.query.StringQueryValue)10 Sort (jakarta.nosql.Sort)9 ParamQueryValue (jakarta.nosql.query.ParamQueryValue)8 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)7 JsonObject (javax.json.JsonObject)7 SelectMethodProvider (org.eclipse.jnosql.communication.query.method.SelectMethodProvider)7 ColumnQuery (jakarta.nosql.column.ColumnQuery)6 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)6 DocumentQuery (jakarta.nosql.document.DocumentQuery)6 DocumentQueryParams (jakarta.nosql.document.DocumentQueryParams)6 List (java.util.List)6 SelectQueryConverter (jakarta.nosql.document.SelectQueryConverter)5