<commit_before>package org.unipop.integration.controllermanagers;

import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.elasticsearch.client.Client;
import org.unipop.controller.EdgeController;
import org.unipop.controller.VertexController;
import org.unipop.controllerprovider.TinkerGraphControllerManager;
import org.unipop.elastic.controller.edge.ElasticEdgeController;
import org.unipop.elastic.controller.vertex.ElasticVertexController;
import org.unipop.elastic.helpers.ElasticClientFactory;
import org.unipop.elastic.helpers.ElasticHelper;
import org.unipop.elastic.helpers.ElasticMutations;
import org.unipop.elastic.helpers.TimingAccessor;
import org.unipop.jdbc.controller.star.SqlTableController;
import org.unipop.structure.UniGraph;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class IntegrationControllerManager extends TinkerGraphControllerManager {
    private EdgeController edgeController;
    private VertexController vertexController;
    private Client client;
    private ElasticMutations elasticMutations;
    private TimingAccessor timing;
    private Connection jdbcConnection;

    @Override
    public void init(UniGraph graph, Configuration configuration) throws Exception {
        timing = new TimingAccessor();
        String indexName = configuration.getString("graphName", "unipop");

        client = ElasticClientFactory.create(configuration);
        ElasticHelper.createIndex(indexName, client);

        elasticMutations = new ElasticMutations(false, client, timing);
        edgeController = new ElasticEdgeController(graph, client, elasticMutations, indexName, 500, true, timing);
        vertexController = new ElasticVertexController(graph, client, elasticMutations, indexName, 500, true, timing);

        VertexController personController = vertexController;
        if(configuration.getString("loadGraphWith", "").equals(LoadGraphWith.GraphData.MODERN.toString())){
            Class.forName("org.h2.Driver");
            this.jdbcConnection = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
            personController = new SqlTableController("PERSON", graph, this.jdbcConnection);
        }

        Vertex person = schema.addVertex(T.label, "person", controller, personController);
        person.addEdge("knows", person, controller, edgeController);
        Vertex software = schema.addVertex(T.label, "software", controller, vertexController);
        person.addEdge("created", software, controller, edgeController);

    }

    @Override
    public void commit() {
        elasticMutations.commit();

    }

    @Override
    public void close() {
        client.close();
        try {
            if(jdbcConnection != null)
                jdbcConnection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        timing.print();
    }
//
//    @Override
//    protected GraphTraversal<?, VertexController> defaultVertexControllers() {
//        return inject(vertexController);
//    }
//
//    @Override
//    protected GraphTraversal<?, EdgeController> defaultEdgeControllers() {
//        return inject(edgeController);
//    }
}<commit_msg>temporary patch because of elastic lazy vertices<commit_after>package org.unipop.integration.controllermanagers;

import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.elasticsearch.client.Client;
import org.unipop.controller.EdgeController;
import org.unipop.controller.Predicates;
import org.unipop.controller.VertexController;
import org.unipop.controllerprovider.TinkerGraphControllerManager;
import org.unipop.elastic.controller.edge.ElasticEdgeController;
import org.unipop.elastic.controller.vertex.ElasticVertexController;
import org.unipop.elastic.helpers.ElasticClientFactory;
import org.unipop.elastic.helpers.ElasticHelper;
import org.unipop.elastic.helpers.ElasticMutations;
import org.unipop.elastic.helpers.TimingAccessor;
import org.unipop.jdbc.controller.star.SqlTableController;
import org.unipop.structure.BaseVertex;
import org.unipop.structure.UniGraph;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Iterator;

public class IntegrationControllerManager extends TinkerGraphControllerManager {
    private EdgeController edgeController;
    private VertexController vertexController;
    private Client client;
    private ElasticMutations elasticMutations;
    private TimingAccessor timing;
    private Connection jdbcConnection;

    @Override
    public void init(UniGraph graph, Configuration configuration) throws Exception {
        timing = new TimingAccessor();
        String indexName = configuration.getString("graphName", "unipop");

        client = ElasticClientFactory.create(configuration);
        ElasticHelper.createIndex(indexName, client);

        elasticMutations = new ElasticMutations(false, client, timing);
        edgeController = new ElasticEdgeController(graph, client, elasticMutations, indexName, 500, timing);
        vertexController = new ElasticVertexController(graph, client, elasticMutations, indexName, 500, timing);

        VertexController personController = vertexController;
        if(configuration.getString("loadGraphWith", "").equals(LoadGraphWith.GraphData.MODERN.toString())){
            Class.forName("org.h2.Driver");
            this.jdbcConnection = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
            personController = new SqlTableController("PERSON", graph, this.jdbcConnection);
        }

        Vertex person = schema.addVertex(T.label, "person", controller, personController);
        person.addEdge("knows", person, controller, edgeController);
        Vertex software = schema.addVertex(T.label, "software", controller, vertexController);
        person.addEdge("created", software, controller, edgeController);
    }

    @Override
    public Iterator<BaseVertex> vertices(Object[] ids) {
        //This is a temporary patch because ElasticVertexController always return a lazy vertex, so we get double results with the SqlController
        HasContainer hasContainer = new HasContainer(T.id.getAccessor(), P.eq(ids));
        Predicates predicates = new Predicates();
        predicates.hasContainers.add(hasContainer);
        return this.vertices(predicates, null);
    }

    @Override
    public void commit() {
        elasticMutations.commit();

    }

    @Override
    public void close() {
        client.close();
        try {
            if(jdbcConnection != null)
                jdbcConnection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        timing.print();
    }
}
{'fraction_non_alphanumeric': 0.09797344514325647, 'fraction_numerical': 0.002236198462613557, 'mean_word_length': 4.107780157030692, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6545962', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1857, 'n_words': 384}