Search in sources :

Example 26 with ClassRepresentation

use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.

the class AbstractDocumentEntityConverter method toEntity.

@Override
public <T> T toEntity(T entityInstance, DocumentEntity entity) {
    requireNonNull(entity, "entity is required");
    requireNonNull(entityInstance, "entityInstance is required");
    ClassRepresentation representation = getClassRepresentations().get(entityInstance.getClass());
    return convertEntity(entity.getDocuments(), representation, entityInstance);
}
Also used : ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 27 with ClassRepresentation

use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.

the class AbstractDocumentEntityConverter method toEntity.

protected <T> T toEntity(Class<T> entityClass, List<Document> documents) {
    ClassRepresentation representation = getClassRepresentations().get(entityClass);
    T instance = getReflections().newInstance(representation.getConstructor());
    return convertEntity(documents, representation, instance);
}
Also used : ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 28 with ClassRepresentation

use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.

the class AbstractDocumentTemplate method find.

@Override
public <T, ID> Optional<T> find(Class<T> entityClass, ID id) {
    requireNonNull(entityClass, "entityClass is required");
    requireNonNull(id, "id is required");
    ClassRepresentation classRepresentation = getClassRepresentations().get(entityClass);
    FieldRepresentation idField = classRepresentation.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
    Object value = ConverterUtil.getValue(id, classRepresentation, idField.getFieldName(), getConverters());
    DocumentQuery query = DocumentQueryBuilder.select().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
    return singleResult(query);
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 29 with ClassRepresentation

use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.

the class AbstractDocumentTemplateAsync method getDeleteQuery.

private <T, ID> DocumentDeleteQuery getDeleteQuery(Class<T> entityClass, ID id) {
    ClassRepresentation classRepresentation = getClassRepresentations().get(entityClass);
    FieldRepresentation idField = classRepresentation.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
    Object value = ConverterUtil.getValue(id, classRepresentation, idField.getFieldName(), getConverters());
    return DocumentQueryBuilder.delete().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Aggregations

ClassRepresentation (org.jnosql.artemis.reflection.ClassRepresentation)29 FieldRepresentation (org.jnosql.artemis.reflection.FieldRepresentation)11 Test (org.junit.jupiter.api.Test)6 Field (java.lang.reflect.Field)2 Optional (java.util.Optional)2 Converters (org.jnosql.artemis.Converters)2 Money (org.jnosql.artemis.model.Money)2 Value (org.jnosql.diana.api.Value)2 ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)2 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)2 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)1 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)1 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)1 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)1