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