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

org.eclipse.jnosql.mapping.graph.spi.TemplateBean Maven / Gradle / Ivy

/*
 *  Copyright (c) 2022 Contributors to the Eclipse Foundation
 *   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.mapping.graph.spi;

import jakarta.nosql.Template;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.eclipse.jnosql.mapping.DatabaseQualifier;
import org.eclipse.jnosql.mapping.DatabaseType;
import org.eclipse.jnosql.mapping.graph.GraphTemplate;
import org.eclipse.jnosql.mapping.graph.GraphTemplateProducer;
import org.eclipse.jnosql.mapping.core.spi.AbstractBean;

import jakarta.enterprise.context.spi.CreationalContext;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Set;

class TemplateBean extends AbstractBean {

    private static final Set TYPES = Set.of(GraphTemplate.class, Template.class);

    private final String provider;

    private final Set qualifiers;

    /**
     * Constructor
     *
     * @param provider    the provider name, that must be a
     */
    public TemplateBean(String provider) {
        this.provider = provider;
        this.qualifiers = Collections.singleton(DatabaseQualifier.ofGraph(provider));
    }

    @Override
    public Class getBeanClass() {
        return GraphTemplate.class;
    }


    @Override
    public GraphTemplate create(CreationalContext context) {

        GraphTemplateProducer producer = getInstance(GraphTemplateProducer.class);
        Graph graph = getGraph();
        return producer.apply(graph);
    }

    private Graph getGraph() {
        return getInstance(Graph.class, DatabaseQualifier.ofGraph(provider));
    }

    @Override
    public Set getTypes() {
        return TYPES;
    }

    @Override
    public Set getQualifiers() {
        return qualifiers;
    }


    @Override
    public String getId() {
        return GraphTemplate.class.getName() + DatabaseType.GRAPH + "-" + provider;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy