blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java
return useLightweightEdges;
  public void setUseLightweightEdges(boolean useDynamicEdges) {
    this.useLightweightEdges = useDynamicEdges;
  public boolean isKeepInMemoryReferences() {
    return keepInMemoryReferences;
  public void setKeepInMemoryReferences(boolean useReferences) {
    this.keepInMemoryReferences = useReferences;

  public boolean isUseVertexFieldsForEdgeLabels() {
    return useVertexFieldsForEdgeLabels;
boolean isUseLightweightEdges()
boolean useVertexFieldsForEdgeLabels
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java
this.useVertexFieldsForEdgeLabels = useVertexFieldsForEdgeLabels;
void setUseVertexFieldsForEdgeLabels(boolean useVertexFieldsForEdgeLabels)
final String iClassName
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java
return iClassName.replace(' ', '-');
String encodeClassName(final String iClassName)
final String iClassName
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java
return iClassName.replace('-', ' ');
String decodeClassName(final String iClassName)
final Class<T> elementClass
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java
String className = null;

    if (elementClass.isAssignableFrom(Vertex.class))
      className = OrientVertex.CLASS_NAME;
    else if (elementClass.isAssignableFrom(Edge.class))
      className = OrientEdge.CLASS_NAME;
    return className;
String getClassName(final Class<T> elementClass)
final String[] iLabels
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientEdge.java
return isLabeled(getLabel(), iLabels);
boolean isLabeled(final String[] iLabels)
final String iEdgeLabel  final String[] iLabels
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientEdge.java
if (iLabels != null && iLabels.length > 0) {
      // FILTER LABEL
      if (iEdgeLabel != null)
        for (String l : iLabels)
          if (l.equals(iEdgeLabel))
            // FOUND
            return true;

      // NOT FOUND
      return false;
boolean isLabeled(final String iEdgeLabel, final String[] iLabels)
final OIdentifiable iEdge
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientEdge.java
if (iEdge == null)
      return null;

    final ODocument edge = iEdge.getRecord();
    if (edge == null)
      return null;

    return edge.field(LABEL_FIELD_NAME);
String getRecordLabel(final OIdentifiable iEdge)
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientElement.java
return graph;
OrientBaseGraph getGraph()
String label  final Vertex inVertex  String iClassName  final Object... fields
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
label = OrientBaseGraph.encodeClassName(label);

    final boolean useVertexFieldsForEdgeLabels = graph.isUseVertexFieldsForEdgeLabels();
    final String outFieldName = getConnectionFieldName(Direction.OUT, label, useVertexFieldsForEdgeLabels);
    final String inFieldName = getConnectionFieldName(Direction.IN, label, useVertexFieldsForEdgeLabels);
    if (canCreateDynamicEdge(outDocument, inDocument, outFieldName, inFieldName, fields, label)) {
        iClassName = label;
      if (graph.isKeepInMemoryReferences())
    if (graph.isKeepInMemoryReferences()) {
      final String iInFieldName, final Object[] fields, final String label) {

    if (!graph.isUseVertexFieldsForEdgeLabels() && label != null)
      return false;

    if (graph.isUseLightweightEdges() && (fields == null || fields.length == 0)) {
    if (graph.isUseVertexFieldsForEdgeLabels() || iLabels == null || iLabels.length == 0) {
      // VERY FAST
      final ODocument doc = getRecord();
      for (String fieldName : doc.fieldNames()) {
        final OPair<Direction, String> connection = getConnection(iDirection, fieldName, iLabels);
        if (connection == null)
          // SKIP THIS FIELD
          continue;

        final Object fieldValue = doc.field(fieldName);
        if (fieldValue != null)
          if (fieldValue instanceof Collection<?>)
            counter += ((Collection<?>) fieldValue).size();
          else if (fieldValue instanceof Map<?, ?>)
            counter += ((Map<?, ?>) fieldValue).size();
          else
            counter++;
OrientEdge addEdge(String label, final Vertex inVertex, String iClassName, final Object... fields)
String clsName : iClassNames
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
clsName = OrientBaseGraph.encodeClassName(clsName);

            if (iFieldName.equals(CONNECTION_OUT_PREFIX + clsName))
              return new OPair<Direction, String>(Direction.OUT, clsName);
NAMES
          for (String clsName : iClassNames)
String clsName : iClassNames
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
if (iFieldName.equals(CONNECTION_IN_PREFIX + clsName))
              return new OPair<Direction, String>(Direction.IN, clsName);
NAMES
          for (String clsName : iClassNames)
final Direction iDirection  final String iClassName 
      final boolean useVertexFieldsForEdgeLabels
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
if (useVertexFieldsForEdgeLabels) {
      // PREFIX "out_" or "in_" TO THE FIELD NAME
      final String prefix = iDirection == Direction.OUT ? CONNECTION_OUT_PREFIX : CONNECTION_IN_PREFIX;
      if (iClassName == null || iClassName.isEmpty() || iClassName.equals(OrientEdge.CLASS_NAME))
        return prefix;
      return prefix + iClassName;
String getConnectionFieldName(final Direction iDirection, final String iClassName,
      final boolean useVertexFieldsForEdgeLabels)
final String iConnectionField  final boolean useVertexFieldsForEdgeLabels
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
if (useVertexFieldsForEdgeLabels) {
      if (iConnectionField.startsWith(CONNECTION_OUT_PREFIX))
        return Direction.OUT;
      else if (iConnectionField.startsWith(CONNECTION_IN_PREFIX))
        return Direction.IN;
Direction getConnectionDirection(final String iConnectionField, final boolean useVertexFieldsForEdgeLabels)
final Direction iDirection  final String iFieldName
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
public static String getInverseConnectionFieldName(final String iFieldName, final boolean useVertexFieldsForEdgeLabels) {
    if (useVertexFieldsForEdgeLabels) {
      if (iFieldName.startsWith(CONNECTION_OUT_PREFIX)) {
        if (iFieldName.length() == CONNECTION_OUT_PREFIX.length())
          // "OUT" CASE
          return CONNECTION_IN_PREFIX;
        return CONNECTION_IN_PREFIX + iFieldName.substring(CONNECTION_OUT_PREFIX.length());
String getConnectionClass(final Direction iDirection, final String iFieldName)
final ODocument doc  final OMultiCollectionIterator<Vertex> iterable  String fieldName 
      final OPair<Direction  String> connection  final Object fieldValue  final String[] iLabels
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
final OrientVertex toAdd;

    final ODocument fieldRecord = ((OIdentifiable) fieldValue).getRecord();
    if (fieldRecord.getSchemaClass().isSubClassOf(CLASS_NAME)) {
      // DIRECT VERTEX
      toAdd = new OrientVertex(graph, fieldRecord);
void addSingleVertex(final ODocument doc, final OMultiCollectionIterator<Vertex> iterable, String fieldName,
      final OPair<Direction, String> connection, final Object fieldValue, final String[] iLabels)
final Class<T> elementClass
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java
String className = null;

    if (elementClass.isAssignableFrom(Vertex.class))
      className = OrientVertex.CLASS_NAME;
    else if (elementClass.isAssignableFrom(Edge.class))
      className = OrientEdge.CLASS_NAME;
    return className;
String getClassName(final Class<T> elementClass)
final Object iObject
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
// CREATE THE OBJECT LAZILY
        return iObject instanceof Vertex ? (Vertex) iObject : new OrientVertex(graph, (OIdentifiable) iObject);
Vertex createWrapper(final Object iObject)
final String label  final Vertex inVertex  String iClassName  final Object... fields
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
final String outFieldName = getConnectionFieldName(Direction.OUT, label);
    final String inFieldName = getConnectionFieldName(Direction.IN, label);
    if (canCreateDynamicEdge(outDocument, inDocument, outFieldName, inFieldName, fields)) {
        iClassName = null;
      if (graph.isUseReferences())
    if (graph.isUseReferences()) {
      final String iInFieldName, final Object[] fields) {
    if (graph.isUseDynamicEdges() && (fields == null || fields.length == 0)) {
    final ODocument doc = getRecord();


    for (String fieldName : doc.fieldNames()) {
      final OPair<Direction, String> connection = getConnection(iDirection, fieldName, iLabels);
      if (connection == null)
        // SKIP THIS FIELD
        continue;

      final Object fieldValue = doc.field(fieldName);
      if (fieldValue != null)
        if (fieldValue instanceof Collection<?>)
          counter += ((Collection<?>) fieldValue).size();
        else if (fieldValue instanceof Map<?, ?>)
          counter += ((Map<?, ?>) fieldValue).size();
        else

          addSingleItem(doc, iterable, fieldName, connection, fieldValue);
              addSingleItem(doc, iterable, fieldName, connection, ((ORecordLazyMultiValue) coll).rawIterator().next());
              addSingleItem(doc, iterable, fieldName, connection, ((List<?>) coll).get(0));
              addSingleItem(doc, iterable, fieldName, connection, coll.iterator().next());

            iterable.add(new OLazyWrapperIterator<OrientEdge>(it, connection) {
              @Override
              public OrientEdge createWrapper(final Object iObject) {
                if (iObject instanceof OrientEdge)
                  return (OrientEdge) iObject;

                final ODocument value = ((OIdentifiable) iObject).getRecord();
                if (value.getSchemaClass().isSubClassOf(CLASS_NAME)) {
                  // DIRECT VERTEX, CREATE DUMMY EDGE
                  final OPair<Direction, String> conn = (OPair<Direction, String>) additionalData;
                  if (conn.getKey() == Direction.OUT)
                    return new OrientEdge(graph, doc, value, conn.getValue());
                  else
                    return new OrientEdge(graph, value, doc, conn.getValue());
OrientEdge addEdge(final String label, final Vertex inVertex, String iClassName, final Object... fields)
String clsName : iClassNames
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
if (iFieldName.equals(CONNECTION_OUT_PREFIX + clsName))
          return new OPair<Direction, String>(Direction.OUT, clsName);
NAMES
      for (String clsName : iClassNames)
String clsName : iClassNames
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
if (iFieldName.equals(CONNECTION_IN_PREFIX + clsName))
          return new OPair<Direction, String>(Direction.IN, clsName);
NAMES
      for (String clsName : iClassNames)
final Direction iDirection  final String iClassName
blueprints-orient-graph/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
final String prefix = iDirection == Direction.OUT ? CONNECTION_OUT_PREFIX : CONNECTION_IN_PREFIX;
    if (iClassName == null || iClassName.isEmpty() || iClassName.equals(OrientEdge.CLASS_NAME))
      return prefix;
    return prefix + iClassName;
  public static Direction getConnectionDirection(final String iConnectionField) {
    if (iConnectionField.startsWith(CONNECTION_OUT_PREFIX))
      return Direction.OUT;
    else if (iConnectionField.startsWith(CONNECTION_IN_PREFIX))
      return Direction.IN;
  public static String getConnectionClass(final Direction iDirection, final String iFieldName) {
  public static String getInverseConnectionFieldName(final String iFieldName) {
    if (iFieldName.startsWith(CONNECTION_OUT_PREFIX)) {
      if (iFieldName.length() == CONNECTION_OUT_PREFIX.length())
        // "OUT" CASE
        return CONNECTION_IN_PREFIX;
      return CONNECTION_IN_PREFIX + iFieldName.substring(CONNECTION_OUT_PREFIX.length());
String getConnectionFieldName(final Direction iDirection, final String iClassName)
final String graphDirectoryName
blueprints-orient-graph/src/test/java/com/tinkerpop/blueprints/impls/orient/OrientGraphTest.java
String directory = getWorkingDirectory();
    this.currentGraph = new OrientGraph("local:" + directory + "/" + graphDirectoryName);
    return this.currentGraph;
Graph generateGraph(final String graphDirectoryName)