use of jakarta.nosql.query.SelectQuery in project jnosql-diana by eclipse.
the class ParamsBinderTest method shouldConvert2.
@Test
public void shouldConvert2() {
Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals("findByAgeAndName")).findFirst().get();
ClassMapping classMapping = mappings.get(Person.class);
RepositoryDocumentObserverParser parser = new RepositoryDocumentObserverParser(classMapping);
paramsBinder = new ParamsBinder(classMapping, converters);
SelectMethodProvider selectMethodFactory = SelectMethodProvider.get();
SelectQuery selectQuery = selectMethodFactory.apply(method, classMapping.getName());
SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
DocumentQueryParams queryParams = converter.apply(selectQuery, parser);
Params params = queryParams.getParams();
paramsBinder.bind(params, new Object[] { 10L, "Ada" }, method);
DocumentQuery query = queryParams.getQuery();
DocumentCondition columnCondition = query.getCondition().get();
List<DocumentCondition> conditions = columnCondition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
});
List<Object> values = conditions.stream().map(DocumentCondition::getDocument).map(Document::getValue).map(Value::get).collect(Collectors.toList());
assertEquals(10, values.get(0));
assertEquals("Ada", values.get(1));
}
use of jakarta.nosql.query.SelectQuery in project jnosql-diana by eclipse.
the class SelectQueryParser method prepare.
DocumentPreparedStatement prepare(String query, DocumentCollectionManager collectionManager, DocumentObserverParser observer) {
Params params = Params.newParams();
SelectQuery selectQuery = selectQueryProvider.apply(query);
DocumentQuery documentQuery = getDocumentQuery(params, selectQuery, observer);
return DefaultDocumentPreparedStatement.select(documentQuery, params, query, collectionManager);
}
use of jakarta.nosql.query.SelectQuery in project jnosql-diana by eclipse.
the class SelectQueryParser method prepare.
ColumnPreparedStatement prepare(String query, ColumnFamilyManager manager, ColumnObserverParser observer) {
Params params = Params.newParams();
SelectQuery selectQuery = selectQueryProvider.apply(query);
ColumnQuery columnQuery = getColumnQuery(params, selectQuery, observer);
return DefaultColumnPreparedStatement.select(columnQuery, params, query, manager);
}
use of jakarta.nosql.query.SelectQuery in project jnosql-diana by eclipse.
the class SelectQueryProviderTest method shouldReturnParserQuery18.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where name = {\"diana\", 17, 20.21}" })
public void shouldReturnParserQuery18(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 ArrayQueryValue);
List<?> values = Stream.of(ArrayQueryValue.class.cast(value).get()).map(QueryValue::get).collect(toList());
assertThat(values, contains("diana", 17L, 20.21));
}
use of jakarta.nosql.query.SelectQuery in project jnosql-diana by eclipse.
the class SelectQueryProviderTest method shouldReturnParserQuery6.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God skip 12" })
public void shouldReturnParserQuery6(String query) {
SelectQuery selectQuery = selectQueryProvider.apply(query);
assertEquals("God", selectQuery.getEntity());
assertTrue(selectQuery.getFields().isEmpty());
assertTrue(selectQuery.getOrderBy().isEmpty());
assertEquals(0, selectQuery.getLimit());
assertEquals(12, selectQuery.getSkip());
assertFalse(selectQuery.getWhere().isPresent());
}
Aggregations