Search in sources :

Example 1 with ColumnQueryParams

use of jakarta.nosql.column.ColumnQueryParams in project jnosql-diana by eclipse.

the class SelectQueryParser method apply.

@Override
public ColumnQueryParams apply(SelectQuery selectQuery, ColumnObserverParser observer) {
    Objects.requireNonNull(selectQuery, "selectQuery is required");
    Objects.requireNonNull(observer, "observer is required");
    Params params = Params.newParams();
    ColumnQuery columnQuery = getColumnQuery(params, selectQuery, observer);
    return new DefaultColumnQueryParams(columnQuery, params);
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnQueryParams(jakarta.nosql.column.ColumnQueryParams) Params(jakarta.nosql.Params)

Example 2 with ColumnQueryParams

use of jakarta.nosql.column.ColumnQueryParams 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 3 with ColumnQueryParams

use of jakarta.nosql.column.ColumnQueryParams 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 4 with ColumnQueryParams

use of jakarta.nosql.column.ColumnQueryParams 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)

Aggregations

Params (jakarta.nosql.Params)4 ColumnQuery (jakarta.nosql.column.ColumnQuery)4 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)4 SelectQuery (jakarta.nosql.query.SelectQuery)3 SelectMethodProvider (org.eclipse.jnosql.communication.query.method.SelectMethodProvider)3 ColumnCondition (jakarta.nosql.column.ColumnCondition)2 SelectQueryConverter (jakarta.nosql.column.SelectQueryConverter)2 Method (java.lang.reflect.Method)2 ClassMapping (org.eclipse.jnosql.mapping.reflection.ClassMapping)2 ParamsBinder (org.eclipse.jnosql.mapping.util.ParamsBinder)2 Test (org.junit.jupiter.api.Test)2 Value (jakarta.nosql.Value)1 Column (jakarta.nosql.column.Column)1 ColumnDeleteQueryParams (jakarta.nosql.column.ColumnDeleteQueryParams)1 List (java.util.List)1