<commit_before>package org.apache.tinkerpop.gremlin.orientdb;

import com.orientechnologies.common.concur.ONeedRetryException;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.util.OCallable;
import com.orientechnologies.orient.core.command.OCommandRequest;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.ORecordNotFoundException;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexManager;
import com.orientechnologies.orient.core.index.OPropertyIndexDefinition;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.OElement;
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.ODocumentInternal;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.NotImplementedException;
import org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet;
import org.apache.tinkerpop.gremlin.orientdb.traversal.strategy.optimization.OrientGraphCountStrategy;
import org.apache.tinkerpop.gremlin.orientdb.traversal.strategy.optimization.OrientGraphMatchStepStrategy;
import org.apache.tinkerpop.gremlin.orientdb.traversal.strategy.optimization.OrientGraphStepStrategy;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
import org.apache.tinkerpop.gremlin.structure.*;
import org.apache.tinkerpop.gremlin.structure.io.Io;
import org.apache.tinkerpop.gremlin.structure.io.Io.Builder;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;

import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static org.apache.tinkerpop.gremlin.orientdb.StreamUtils.asStream;

@Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_STANDARD)
@Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_INTEGRATE)
@Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_PERFORMANCE)
@Graph.OptIn(Graph.OptIn.SUITE_PROCESS_STANDARD)
@Graph.OptIn(Graph.OptIn.SUITE_PROCESS_COMPUTER)
@Graph.OptIn(Graph.OptIn.SUITE_PROCESS_PERFORMANCE)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_PROCESS_STANDARD)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_PROCESS_COMPUTER)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_INTEGRATE)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_PERFORMANCE)
@Graph.OptIn("org.apache.tinkerpop.gremlin.orientdb.gremlintest.suite.OrientDBDebugSuite")
public final class OrientGraph implements Graph {
  static {
    TraversalStrategies.GlobalCache.registerStrategies(OrientGraph.class,
        TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone()
            .addStrategies(OrientGraphStepStrategy.instance(), OrientGraphCountStrategy.instance(),
                OrientGraphMatchStepStrategy.instance()));
  }

  private static final Map<String, String> INTERNAL_CLASSES_TO_TINKERPOP_CLASSES;

  static {
    INTERNAL_CLASSES_TO_TINKERPOP_CLASSES = new HashMap<>();
    INTERNAL_CLASSES_TO_TINKERPOP_CLASSES.put(OClass.VERTEX_CLASS_NAME, Vertex.DEFAULT_LABEL);
    INTERNAL_CLASSES_TO_TINKERPOP_CLASSES.put(OClass.EDGE_CLASS_NAME, Edge.DEFAULT_LABEL);
  }

  public static String CONFIG_URL                = "orient-url";
  public static String CONFIG_DB_NAME            = "orient-db-name";
  public static String CONFIG_USER               = "orient-user";
  public static String CONFIG_PASS               = "<PASSWORD>";
  public static String CONFIG_CREATE             = "orient-create";
  public static String CONFIG_OPEN               = "orient-open";
  public static String CONFIG_TRANSACTIONAL      = "orient-transactional";
  public static String CONFIG_POOL_SIZE          = "orient-max-poolsize";
  public static String CONFIG_MAX_PARTITION_SIZE = "orient-max-partitionsize";
  public static String CONFIG_LABEL_AS_CLASSNAME = "orient-label-as-classname";

  protected       boolean            connectionFailed;
  protected       ODatabaseDocument  database;
  protected final Features           features;
  protected final Configuration      configuration;
  protected final String             user;
  protected final String             password;
  protected       OrientGraphFactory factory;
  protected boolean shouldCloseFactory = false;
  protected OrientTransaction tx;

  public static OrientGraph open() {
    return open("memory:orientdb-" + Math.random(), "admin", "admin");
  }

  public static OrientGraph open(String url) {
    return open(url, "admin", "admin");
  }

  public static OrientGraph open(String url, String user, String password) {
    BaseConfiguration configuration = new BaseConfiguration();
    configuration.setProperty(CONFIG_URL, url);
    configuration.setProperty(CONFIG_USER, user);
    configuration.setProperty(CONFIG_PASS, password);

    return open(configuration);

  }

  public static OrientGraph open(final Configuration config) {
    OrientGraphFactory factory = new OrientGraphFactory(config);
    if (config.containsKey(CONFIG_POOL_SIZE))
      factory.setupPool(config.getInt(CONFIG_MAX_PARTITION_SIZE, 64), config.getInt(CONFIG_POOL_SIZE));

    return new OrientGraph(factory, config, true);
  }

  public OrientGraph(OrientGraphFactory factory, final ODatabaseDocument database, final Configuration configuration,
      final String user, final String password) {
    this.factory = factory;
    this.user = user;
    this.password = password;
    this.database = database;
    this.configuration = configuration;
    this.connectionFailed = false;
    if (configuration.getBoolean(CONFIG_TRANSACTIONAL, false)) {
      this.features = ODBFeatures.OrientFeatures.INSTANCE_TX;
      this.tx = new OrientTransaction(this);
    } else {
      this.features = ODBFeatures.OrientFeatures.INSTANCE_NOTX;
      this.tx = new OrientNoTransaction(this);
    }
  }

  public OrientGraph(final OrientGraphFactory factory, final Configuration configuration) {
    this(factory, configuration, false);
  }

  public OrientGraph(final OrientGraphFactory factory, final Configuration configuration, boolean closeFactory) {
    this.factory = factory;
    this.database = factory.getDatabase(true, true);
    this.user = "";
    this.password = "";
    this.connectionFailed = false;
    makeActive();
    this.configuration = configuration;
    if (configuration.getBoolean(CONFIG_TRANSACTIONAL, false)) {
      this.features = ODBFeatures.OrientFeatures.INSTANCE_TX;
      this.tx = new OrientTransaction(this);
    } else {
      this.features = ODBFeatures.OrientFeatures.INSTANCE_NOTX;
      this.tx = new OrientNoTransaction(this);
    }
    this.shouldCloseFactory = closeFactory;
  }

  public Features features() {
    return features;
  }

  public ODatabaseDocument database() {
    return database;
  }

  private void makeActiveDb() {
    final ODatabaseDocument tlDb = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (database != null && tlDb != database) {<commit_msg>Fix compile problem after refactoring of core modules<commit_after>package org.apache.tinkerpop.gremlin.orientdb;

import com.orientechnologies.common.concur.ONeedRetryException;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.util.OCallable;
import com.orientechnologies.orient.core.command.OCommandRequest;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.ORecordNotFoundException;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexManager;
import com.orientechnologies.orient.core.index.OPropertyIndexDefinition;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.OElement;
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.ODocumentInternal;
import com.orientechnologies.orient.core.sql.executor.OResultSet;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.NotImplementedException;
import org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet;
import org.apache.tinkerpop.gremlin.orientdb.traversal.strategy.optimization.OrientGraphCountStrategy;
import org.apache.tinkerpop.gremlin.orientdb.traversal.strategy.optimization.OrientGraphMatchStepStrategy;
import org.apache.tinkerpop.gremlin.orientdb.traversal.strategy.optimization.OrientGraphStepStrategy;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
import org.apache.tinkerpop.gremlin.structure.*;
import org.apache.tinkerpop.gremlin.structure.io.Io;
import org.apache.tinkerpop.gremlin.structure.io.Io.Builder;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;

import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static org.apache.tinkerpop.gremlin.orientdb.StreamUtils.asStream;

@Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_STANDARD)
@Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_INTEGRATE)
@Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_PERFORMANCE)
@Graph.OptIn(Graph.OptIn.SUITE_PROCESS_STANDARD)
@Graph.OptIn(Graph.OptIn.SUITE_PROCESS_COMPUTER)
@Graph.OptIn(Graph.OptIn.SUITE_PROCESS_PERFORMANCE)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_PROCESS_STANDARD)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_PROCESS_COMPUTER)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_INTEGRATE)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_PERFORMANCE)
@Graph.OptIn("org.apache.tinkerpop.gremlin.orientdb.gremlintest.suite.OrientDBDebugSuite")
public final class OrientGraph implements Graph {
  static {
    TraversalStrategies.GlobalCache.registerStrategies(OrientGraph.class,
        TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone()
            .addStrategies(OrientGraphStepStrategy.instance(), OrientGraphCountStrategy.instance(),
                OrientGraphMatchStepStrategy.instance()));
  }

  private static final Map<String, String> INTERNAL_CLASSES_TO_TINKERPOP_CLASSES;

  static {
    INTERNAL_CLASSES_TO_TINKERPOP_CLASSES = new HashMap<>();
    INTERNAL_CLASSES_TO_TINKERPOP_CLASSES.put(OClass.VERTEX_CLASS_NAME, Vertex.DEFAULT_LABEL);
    INTERNAL_CLASSES_TO_TINKERPOP_CLASSES.put(OClass.EDGE_CLASS_NAME, Edge.DEFAULT_LABEL);
  }

  public static String CONFIG_URL                = "orient-url";
  public static String CONFIG_DB_NAME            = "orient-db-name";
  public static String CONFIG_USER               = "orient-user";
  public static String CONFIG_PASS               = "<PASSWORD>";
  public static String CONFIG_CREATE             = "orient-create";
  public static String CONFIG_OPEN               = "orient-open";
  public static String CONFIG_TRANSACTIONAL      = "orient-transactional";
  public static String CONFIG_POOL_SIZE          = "orient-max-poolsize";
  public static String CONFIG_MAX_PARTITION_SIZE = "orient-max-partitionsize";
  public static String CONFIG_LABEL_AS_CLASSNAME = "orient-label-as-classname";

  protected       boolean            connectionFailed;
  protected       ODatabaseDocument  database;
  protected final Features           features;
  protected final Configuration      configuration;
  protected final String             user;
  protected final String             password;
  protected       OrientGraphFactory factory;
  protected boolean shouldCloseFactory = false;
  protected OrientTransaction tx;

  public static OrientGraph open() {
    return open("memory:orientdb-" + Math.random(), "admin", "admin");
  }

  public static OrientGraph open(String url) {
    return open(url, "admin", "admin");
  }

  public static OrientGraph open(String url, String user, String password) {
    BaseConfiguration configuration = new BaseConfiguration();
    configuration.setProperty(CONFIG_URL, url);
    configuration.setProperty(CONFIG_USER, user);
    configuration.setProperty(CONFIG_PASS, password);

    return open(configuration);

  }

  public static OrientGraph open(final Configuration config) {
    OrientGraphFactory factory = new OrientGraphFactory(config);
    if (config.containsKey(CONFIG_POOL_SIZE))
      factory.setupPool(config.getInt(CONFIG_MAX_PARTITION_SIZE, 64), config.getInt(CONFIG_POOL_SIZE));

    return new OrientGraph(factory, config, true);
  }

  public OrientGraph(OrientGraphFactory factory, final ODatabaseDocument database, final Configuration configuration,
      final String user, final String password) {
    this.factory = factory;
    this.user = user;
    this.password = password;
    this.database = database;
    this.configuration = configuration;
    this.connectionFailed = false;
    if (configuration.getBoolean(CONFIG_TRANSACTIONAL, false)) {
      this.features = ODBFeatures.OrientFeatures.INSTANCE_TX;
      this.tx = new OrientTransaction(this);
    } else {
      this.features = ODBFeatures.OrientFeatures.INSTANCE_NOTX;
      this.tx = new OrientNoTransaction(this);
    }
  }

  public OrientGraph(final OrientGraphFactory factory, final Configuration configuration) {
    this(factory, configuration, false);
  }

  public OrientGraph(final OrientGraphFactory factory, final Configuration configuration, boolean closeFactory) {
    this.factory = factory;
    this.database = factory.getDatabase(true, true);
    this.user = "";
    this.password = "";
    this.connectionFailed = false;
    makeActive();
    this.configuration = configuration;
    if (configuration.getBoolean(CONFIG_TRANSACTIONAL, false)) {
      this.features = ODBFeatures.OrientFeatures.INSTANCE_TX;
      this.tx = new OrientTransaction(this);
    } else {
      this.features = ODBFeatures.OrientFeatures.INSTANCE_NOTX;
      this.tx = new OrientNoTransaction(this);
    }
    this.shouldCloseFactory = closeFactory;
  }

  public Features features() {
    return features;
  }

  public ODatabaseDocument database() {
    return database;
  }

  private void makeActiveDb() {
    final ODatabaseDocument tlDb = ODatabaseRecordThreadLocal.instance().getIfDefined();
    if (database != null && tlDb != database) {
{'fraction_non_alphanumeric': 0.09230194319880418, 'fraction_numerical': 0.00024912805181863477, 'mean_word_length': 5.045557228915663, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4503794', 'n_tokens_mistral': 4884, 'n_tokens_neox': 4748, 'n_words': 767}