Search in sources :

Example 6 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class AbstractDocumentTemplate method delete.

@Override
public <T, K> void delete(Class<T> entityClass, K id) {
    requireNonNull(entityClass, "entityClass is required");
    requireNonNull(id, "id is required");
    ClassMapping classMapping = getClassMappings().get(entityClass);
    FieldMapping idField = classMapping.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
    Object value = ConverterUtil.getValue(id, classMapping, idField.getFieldName(), getConverters());
    DocumentDeleteQuery query = DocumentDeleteQuery.delete().from(classMapping.getName()).where(idField.getName()).eq(value).build();
    delete(query);
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) FieldMapping(org.eclipse.jnosql.mapping.reflection.FieldMapping) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery)

Example 7 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class DefaultDocumentQueryMapper method deleteFrom.

@Override
public <T> DocumentMapperDeleteFrom deleteFrom(Class<T> entityClass) {
    requireNonNull(entityClass, "entity is required");
    ClassMapping mapping = mappings.get().get(entityClass);
    return new DefaultDocumentMapperDeleteBuilder(mapping, converters.get());
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping)

Example 8 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping 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 9 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class DeleteQueryConverter method apply.

@Override
public List<Vertex> apply(GraphQueryMethod graphQuery) {
    DeleteMethodProvider provider = DeleteMethodProvider.get();
    DeleteQuery deleteQuery = provider.apply(graphQuery.getMethod(), graphQuery.getEntityName());
    ClassMapping mapping = graphQuery.getMapping();
    GraphTraversal<Vertex, Vertex> traversal = getGraphTraversal(graphQuery, deleteQuery::getWhere, mapping);
    traversal.hasLabel(mapping.getName());
    return traversal.toList();
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DeleteMethodProvider(org.eclipse.jnosql.communication.query.method.DeleteMethodProvider) DeleteQuery(jakarta.nosql.query.DeleteQuery)

Example 10 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class AbstractColumnTemplate method count.

@Override
public <T> long count(Class<T> entityClass) {
    requireNonNull(entityClass, "entity class is required");
    ClassMapping classMapping = getClassMappings().get(entityClass);
    return getManager().count(classMapping.getName());
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping)

Aggregations

ClassMapping (org.eclipse.jnosql.mapping.reflection.ClassMapping)60 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)31 Method (java.lang.reflect.Method)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 ValueSource (org.junit.jupiter.params.provider.ValueSource)19 FieldMapping (org.eclipse.jnosql.mapping.reflection.FieldMapping)12 List (java.util.List)10 Converters (jakarta.nosql.mapping.Converters)8 Edge (org.apache.tinkerpop.gremlin.structure.Edge)8 Graph (org.apache.tinkerpop.gremlin.structure.Graph)8 ClassMappings (org.eclipse.jnosql.mapping.reflection.ClassMappings)8 Collectors (java.util.stream.Collectors)7 Test (org.junit.jupiter.api.Test)7 Value (jakarta.nosql.Value)6 Optional (java.util.Optional)6 EntityNotFoundException (jakarta.nosql.mapping.EntityNotFoundException)5 SelectQuery (jakarta.nosql.query.SelectQuery)5 Iterator (java.util.Iterator)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Function (java.util.function.Function)5