Search in sources :

Example 46 with SelectQuery

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

the class ParamsBinderTest method shouldConvert.

@Test
public void shouldConvert() {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals("findByAge")).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 columnQueryParams = converter.apply(selectQuery, parser);
    Params params = columnQueryParams.getParams();
    Object[] args = { 10 };
    paramsBinder.bind(params, args, method);
    DocumentQuery query = columnQueryParams.getQuery();
    DocumentCondition columnCondition = query.getCondition().get();
    Value value = columnCondition.getDocument().getValue();
    assertEquals(10, value.get());
}
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) 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) Value(jakarta.nosql.Value) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 47 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);
    RepositoryColumnObserverParser parser = new RepositoryColumnObserverParser(classMapping);
    paramsBinder = new ParamsBinder(classMapping, converters);
    SelectMethodProvider selectMethodFactory = SelectMethodProvider.get();
    SelectQuery selectQuery = selectMethodFactory.apply(method, classMapping.getName());
    SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
    ColumnQueryParams queryParams = converter.apply(selectQuery, parser);
    Params params = queryParams.getParams();
    paramsBinder.bind(params, new Object[] { 10L, "Ada" }, method);
    ColumnQuery query = queryParams.getQuery();
    ColumnCondition columnCondition = query.getCondition().get();
    List<ColumnCondition> conditions = columnCondition.getColumn().get(new TypeReference<List<ColumnCondition>>() {
    });
    List<Object> values = conditions.stream().map(ColumnCondition::getColumn).map(Column::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) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams) Params(jakarta.nosql.Params) Method(java.lang.reflect.Method) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams) SelectQuery(jakarta.nosql.query.SelectQuery) ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) SelectQueryConverter(jakarta.nosql.column.SelectQueryConverter) SelectMethodProvider(org.eclipse.jnosql.communication.query.method.SelectMethodProvider) List(java.util.List) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 48 with SelectQuery

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

the class ParamsBinderTest method shouldConvert.

@Test
public void shouldConvert() {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals("findByAge")).findFirst().get();
    ClassMapping classMapping = mappings.get(Person.class);
    RepositoryColumnObserverParser parser = new RepositoryColumnObserverParser(classMapping);
    paramsBinder = new ParamsBinder(classMapping, converters);
    SelectMethodProvider selectMethodFactory = SelectMethodProvider.get();
    SelectQuery selectQuery = selectMethodFactory.apply(method, classMapping.getName());
    SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
    ColumnQueryParams columnQueryParams = converter.apply(selectQuery, parser);
    Params params = columnQueryParams.getParams();
    Object[] args = { 10 };
    paramsBinder.bind(params, args, method);
    ColumnQuery query = columnQueryParams.getQuery();
    ColumnCondition columnCondition = query.getCondition().get();
    Value value = columnCondition.getColumn().getValue();
    assertEquals(10, value.get());
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) ParamsBinder(org.eclipse.jnosql.mapping.util.ParamsBinder) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams) Params(jakarta.nosql.Params) Method(java.lang.reflect.Method) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams) SelectQuery(jakarta.nosql.query.SelectQuery) ColumnQuery(jakarta.nosql.column.ColumnQuery) SelectQueryConverter(jakarta.nosql.column.SelectQueryConverter) SelectMethodProvider(org.eclipse.jnosql.communication.query.method.SelectMethodProvider) Value(jakarta.nosql.Value) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 49 with SelectQuery

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

the class BaseColumnRepository method getQuery.

protected ColumnQuery getQuery(Method method, Object[] args) {
    SelectMethodProvider selectMethodFactory = SelectMethodProvider.get();
    SelectQuery selectQuery = selectMethodFactory.apply(method, getClassMapping().getName());
    ColumnQueryParams queryParams = SELECT_CONVERTER.apply(selectQuery, getParser());
    ColumnQuery query = queryParams.getQuery();
    Params params = queryParams.getParams();
    getParamsBinder().bind(params, args, method);
    return getQuerySorts(args, query);
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) ColumnQuery(jakarta.nosql.column.ColumnQuery) SelectMethodProvider(org.eclipse.jnosql.communication.query.method.SelectMethodProvider) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams) ColumnDeleteQueryParams(jakarta.nosql.column.ColumnDeleteQueryParams) Params(jakarta.nosql.Params) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams)

Example 50 with SelectQuery

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

the class FindByMethodQueryProviderTest method checkAppendCondition.

private void checkAppendCondition(String query, Operator operator, Operator operator2, String variable, String variable2, Operator operatorAppender) {
    String entity = "entity";
    SelectQuery selectQuery = queryProvider.apply(query, entity);
    assertNotNull(selectQuery);
    assertEquals(entity, selectQuery.getEntity());
    assertTrue(selectQuery.getFields().isEmpty());
    assertTrue(selectQuery.getOrderBy().isEmpty());
    assertEquals(0, selectQuery.getLimit());
    assertEquals(0, selectQuery.getSkip());
    Optional<Where> where = selectQuery.getWhere();
    assertTrue(where.isPresent());
    Condition condition = where.get().getCondition();
    QueryValue<?> value = condition.getValue();
    assertEquals(operatorAppender, condition.getOperator());
    assertTrue(value instanceof ConditionQueryValue);
    Condition condition1 = ConditionQueryValue.class.cast(value).get().get(0);
    Condition condition2 = ConditionQueryValue.class.cast(value).get().get(1);
    assertEquals(operator, condition1.getOperator());
    QueryValue<?> param = condition1.getValue();
    assertEquals(operator, condition1.getOperator());
    assertTrue(ParamQueryValue.class.cast(param).get().contains(variable));
    assertEquals(operator2, condition2.getOperator());
    QueryValue<?> param2 = condition2.getValue();
    assertEquals(condition2.getOperator(), operator2);
    assertTrue(ParamQueryValue.class.cast(param2).get().contains(variable2));
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) Condition(jakarta.nosql.query.Condition) ParamQueryValue(jakarta.nosql.query.ParamQueryValue) ConditionQueryValue(jakarta.nosql.query.ConditionQueryValue) Where(jakarta.nosql.query.Where)

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