Search in sources :

Example 1 with Converters

use of org.jnosql.artemis.Converters in project jnosql-artemis by eclipse.

the class RepositoryAsyncColumnBean method create.

@Override
public RepositoryAsync create(CreationalContext<RepositoryAsync> creationalContext) {
    ClassRepresentations classRepresentations = getInstance(ClassRepresentations.class);
    ColumnTemplateAsync repository = provider.isEmpty() ? getInstance(ColumnTemplateAsync.class) : getInstance(ColumnTemplateAsync.class, provider);
    Reflections reflections = getInstance(Reflections.class);
    Converters converters = getInstance(Converters.class);
    ColumnRepositoryAsyncProxy handler = new ColumnRepositoryAsyncProxy(repository, classRepresentations, type, reflections, converters);
    return (RepositoryAsync) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
Also used : Converters(org.jnosql.artemis.Converters) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) ColumnTemplateAsync(org.jnosql.artemis.column.ColumnTemplateAsync) Reflections(org.jnosql.artemis.reflection.Reflections) RepositoryAsync(org.jnosql.artemis.RepositoryAsync)

Example 2 with Converters

use of org.jnosql.artemis.Converters in project jnosql-artemis by eclipse.

the class RepositoryColumnBean method create.

@Override
public Repository create(CreationalContext<Repository> creationalContext) {
    ClassRepresentations classRepresentations = getInstance(ClassRepresentations.class);
    ColumnTemplate repository = provider.isEmpty() ? getInstance(ColumnTemplate.class) : getInstance(ColumnTemplate.class, provider);
    Reflections reflections = getInstance(Reflections.class);
    Converters converters = getInstance(Converters.class);
    ColumnRepositoryProxy handler = new ColumnRepositoryProxy(repository, classRepresentations, type, reflections, converters);
    return (Repository) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
Also used : Repository(org.jnosql.artemis.Repository) ColumnTemplate(org.jnosql.artemis.column.ColumnTemplate) Converters(org.jnosql.artemis.Converters) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) Reflections(org.jnosql.artemis.reflection.Reflections)

Example 3 with Converters

use of org.jnosql.artemis.Converters in project jnosql-artemis by eclipse.

the class RepositoryDocumentBean method create.

@Override
public Repository create(CreationalContext<Repository> creationalContext) {
    ClassRepresentations classRepresentations = getInstance(ClassRepresentations.class);
    DocumentTemplate repository = provider.isEmpty() ? getInstance(DocumentTemplate.class) : getInstance(DocumentTemplate.class, provider);
    Reflections reflections = getInstance(Reflections.class);
    Converters converters = getInstance(Converters.class);
    DocumentRepositoryProxy handler = new DocumentRepositoryProxy(repository, classRepresentations, type, reflections, converters);
    return (Repository) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
Also used : Repository(org.jnosql.artemis.Repository) Converters(org.jnosql.artemis.Converters) DocumentTemplate(org.jnosql.artemis.document.DocumentTemplate) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) Reflections(org.jnosql.artemis.reflection.Reflections)

Example 4 with Converters

use of org.jnosql.artemis.Converters in project jnosql-artemis by eclipse.

the class ConverterUtil method getValue.

public static Object getValue(Object value, ClassRepresentation representation, String name, Converters converters) {
    Optional<FieldRepresentation> fieldOptional = representation.getFieldRepresentation(name);
    if (fieldOptional.isPresent()) {
        FieldRepresentation field = fieldOptional.get();
        Field nativeField = field.getNativeField();
        if (!nativeField.getType().equals(value.getClass())) {
            return field.getConverter().map(converters::get).map(a -> a.convertToDatabaseColumn(value)).orElseGet(() -> Value.of(value).get(nativeField.getType()));
        }
        return field.getConverter().map(converters::get).map(a -> a.convertToDatabaseColumn(value)).orElse(value);
    }
    return value;
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) Converters(org.jnosql.artemis.Converters) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation) FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) Value(org.jnosql.diana.api.Value) Optional(java.util.Optional) Field(java.lang.reflect.Field) Field(java.lang.reflect.Field)

Example 5 with Converters

use of org.jnosql.artemis.Converters in project jnosql-artemis by eclipse.

the class DocumentRepositoryAsyncBean method create.

@Override
public RepositoryAsync create(CreationalContext<RepositoryAsync> creationalContext) {
    ClassRepresentations classRepresentations = getInstance(ClassRepresentations.class);
    DocumentTemplateAsync repository = provider.isEmpty() ? getInstance(DocumentTemplateAsync.class) : getInstance(DocumentTemplateAsync.class, provider);
    Reflections reflections = getInstance(Reflections.class);
    Converters converters = getInstance(Converters.class);
    DocumentRepositoryAsyncProxy handler = new DocumentRepositoryAsyncProxy(repository, classRepresentations, type, reflections, converters);
    return (RepositoryAsync) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
Also used : DocumentTemplateAsync(org.jnosql.artemis.document.DocumentTemplateAsync) Converters(org.jnosql.artemis.Converters) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) Reflections(org.jnosql.artemis.reflection.Reflections) RepositoryAsync(org.jnosql.artemis.RepositoryAsync)

Aggregations

Converters (org.jnosql.artemis.Converters)6 ClassRepresentations (org.jnosql.artemis.reflection.ClassRepresentations)4 Reflections (org.jnosql.artemis.reflection.Reflections)4 Field (java.lang.reflect.Field)2 Optional (java.util.Optional)2 Repository (org.jnosql.artemis.Repository)2 RepositoryAsync (org.jnosql.artemis.RepositoryAsync)2 ClassRepresentation (org.jnosql.artemis.reflection.ClassRepresentation)2 FieldRepresentation (org.jnosql.artemis.reflection.FieldRepresentation)2 Value (org.jnosql.diana.api.Value)2 ColumnTemplate (org.jnosql.artemis.column.ColumnTemplate)1 ColumnTemplateAsync (org.jnosql.artemis.column.ColumnTemplateAsync)1 DocumentTemplate (org.jnosql.artemis.document.DocumentTemplate)1 DocumentTemplateAsync (org.jnosql.artemis.document.DocumentTemplateAsync)1