All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jnosql.lite.mapping.entities.PersonPhonesFieldMetaData Maven / Gradle / Ivy

/*
 *  Copyright (c) 2023 Otávio Santana and others
 *   All rights reserved. This program and the accompanying materials
 *   are made available under the terms of the Eclipse Public License v1.0
 *   and Apache License v2.0 which accompanies this distribution.
 *   The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 *   and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
 *
 *   You may elect to redistribute this code under either of these licenses.
 *
 *   Contributors:
 *
 *   Otavio Santana
 */
package org.eclipse.jnosql.lite.mapping.entities;

import java.lang.annotation.Annotation;

import org.eclipse.jnosql.communication.Value;
import org.eclipse.jnosql.mapping.AttributeConverter;
import org.eclipse.jnosql.mapping.metadata.GenericFieldMetadata;
import org.eclipse.jnosql.mapping.metadata.MappingType;
import org.eclipse.jnosql.communication.TypeSupplier;
import org.eclipse.jnosql.communication.TypeReference;

import javax.annotation.processing.Generated;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

@Generated(value= "JNoSQL Lite FieldMetadata Generator", date = "2023-12-02T14:20:40.666096196")
public final class PersonPhonesFieldMetaData implements GenericFieldMetadata {

    private final AttributeConverter converter;

    private final Class> typeConverter;

    private final Map, String> valueByAnnotation;

    private final TypeSupplier> typeSupplier = new TypeReference<>(){};

    public PersonPhonesFieldMetaData() {
        this.converter = null;
        this.typeConverter = null;
        this.valueByAnnotation = java.util.Collections.emptyMap();
    }

    @Override
    public boolean isId() {
        return false;
    }

    @Override
    public  Optional value(Class type) {
        Objects.requireNonNull(type, "type is required");
        return Optional.ofNullable(this.valueByAnnotation.get(type));
    }

    @Override
    public > Optional> converter() {
        return Optional.ofNullable((Class) typeConverter);
    }

    @Override
    public > Optional newConverter() {
        return (Optional) Optional.ofNullable(converter);
    }

    @Override
    public MappingType mappingType() {
        return MappingType.COLLECTION;
    }

    @Override
    public String name() {
        return "phones";
    }

    @Override
    public String fieldName() {
        return "phones";
    }

    @Override
    public Object value(Value value) {
        Objects.requireNonNull(value, "value is required");
        if(value.get() instanceof Iterable) {
            return value.get(typeSupplier);
        } else {
            return Value.of(java.util.Collections.singletonList(value.get())).get(typeSupplier);
        }
    }

    @Override
    public void write(Object bean, Object value) {
        ((Person) bean).setPhones((java.util.List)value);
    }

    @Override
    public Object read(Object bean) {
        return ((Person) bean).getPhones();
    }

    @Override
    public Class type() {
        return java.util.List.class;
    }

    @Override
    public boolean isEmbeddable() {
        return false;
    }

    @Override
    public Class elementType() {
        return java.lang.String.class;
    }

    @Override
    public java.util.Collection collectionInstance() {
        return new java.util.ArrayList<>();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy