Search in sources :

Example 1 with SelectMethodProvider

use of org.eclipse.jnosql.communication.query.method.SelectMethodProvider in project jnosql-diana by eclipse.

the class BaseDocumentRepository method getQuery.

protected DocumentQuery getQuery(Method method, Object[] args) {
    SelectMethodProvider methodProvider = SelectMethodProvider.get();
    SelectQuery selectQuery = methodProvider.apply(method, getClassMapping().getName());
    SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
    DocumentQueryParams queryParams = converter.apply(selectQuery, getParser());
    DocumentQuery query = queryParams.getQuery();
    Params params = queryParams.getParams();
    getParamsBinder().bind(params, args, method);
    return getQuerySorts(args, query);
}
Also used : 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) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) Params(jakarta.nosql.Params)

Example 2 with SelectMethodProvider

use of org.eclipse.jnosql.communication.query.method.SelectMethodProvider in project jnosql-diana by eclipse.

the class SelectQueryConverter method apply.

@Override
public Stream<Vertex> apply(GraphQueryMethod graphQuery, Object[] params) {
    SelectMethodProvider selectMethodFactory = SelectMethodProvider.get();
    SelectQuery query = selectMethodFactory.apply(graphQuery.getMethod(), graphQuery.getEntityName());
    ClassMapping mapping = graphQuery.getMapping();
    GraphTraversal<Vertex, Vertex> traversal = getGraphTraversal(graphQuery, query::getWhere, mapping);
    query.getOrderBy().forEach(getSort(traversal, mapping));
    setSort(params, traversal);
    setPagination(params, traversal, query);
    traversal.hasLabel(mapping.getName());
    return traversal.toStream();
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SelectMethodProvider(org.eclipse.jnosql.communication.query.method.SelectMethodProvider)

Example 3 with SelectMethodProvider

use of org.eclipse.jnosql.communication.query.method.SelectMethodProvider 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 4 with SelectMethodProvider

use of org.eclipse.jnosql.communication.query.method.SelectMethodProvider 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 5 with SelectMethodProvider

use of org.eclipse.jnosql.communication.query.method.SelectMethodProvider 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)

Aggregations

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