Search in sources :

Example 26 with SelectQuery

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));
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) ParamsBinder(org.eclipse.jnosql.mapping.util.ParamsBinder) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) Params(jakarta.nosql.Params) Method(java.lang.reflect.Method) Document(jakarta.nosql.document.Document) SelectQuery(jakarta.nosql.query.SelectQuery) DocumentQuery(jakarta.nosql.document.DocumentQuery) SelectQueryConverter(jakarta.nosql.document.SelectQueryConverter) SelectMethodProvider(org.eclipse.jnosql.communication.query.method.SelectMethodProvider) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) List(java.util.List) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 27 with SelectQuery

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);
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) Params(jakarta.nosql.Params)

Example 28 with SelectQuery

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);
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams) Params(jakarta.nosql.Params)

Example 29 with SelectQuery

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));
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) Where(jakarta.nosql.query.Where) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with SelectQuery

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());
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) 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