diff --git a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/ODBFeatures.java b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/ODBFeatures.java index a2b3d98e..3f0a4dad 100644 --- a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/ODBFeatures.java +++ b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/ODBFeatures.java @@ -13,7 +13,8 @@ public static class OrientFeatures implements Features { static final OrientFeatures INSTANCE_NOTX = new OrientFeatures(false); static final OrientFeatures INSTANCE_TX = new OrientFeatures(true); - private OrientGraphFeatures graphFeatures; + private OrientGraphFeatures graphFeatures; + private OrientFeatures(boolean transactionalGraph) { this.graphFeatures = new OrientGraphFeatures(transactionalGraph); } @@ -41,7 +42,6 @@ public String toString() { public static abstract class OrientElementFeatures implements Features.ElementFeatures { - @Override public boolean supportsAnyIds() { return false; @@ -54,22 +54,22 @@ public boolean supportsCustomIds() { @Override public boolean supportsNumericIds() { - return false; + return false; } @Override public boolean supportsStringIds() { - return false; + return false; } @Override public boolean supportsUserSuppliedIds() { - return false; + return false; } @Override public boolean supportsUuidIds() { - return false; + return false; } @Override @@ -109,7 +109,8 @@ private OrientEdgeFeatures() { public static class OrientGraphFeatures implements Features.GraphFeatures { - protected final boolean transactionalGraph; + protected final boolean transactionalGraph; + private OrientGraphFeatures(boolean transactionalGraph) { this.transactionalGraph = transactionalGraph; } @@ -238,37 +239,37 @@ public boolean supportsUniformListValues() { public static class OrientVertexPropertyFeatures implements Features.VertexPropertyFeatures { - static final OrientVertexPropertyFeatures INSTANCE = new OrientVertexPropertyFeatures(); - - @Override - public boolean supportsAnyIds() { - return false; - } - - @Override - public boolean supportsCustomIds() { - return false; - } - - @Override - public boolean supportsNumericIds() { - return false; - } - - @Override - public boolean supportsUserSuppliedIds() { - return false; - } - - @Override - public boolean supportsUuidIds() { - return false; - } - - @Override - public boolean willAllowId(Object id) { - return false; - } + static final OrientVertexPropertyFeatures INSTANCE = new OrientVertexPropertyFeatures(); + + @Override + public boolean supportsAnyIds() { + return false; + } + + @Override + public boolean supportsCustomIds() { + return false; + } + + @Override + public boolean supportsNumericIds() { + return false; + } + + @Override + public boolean supportsUserSuppliedIds() { + return false; + } + + @Override + public boolean supportsUuidIds() { + return false; + } + + @Override + public boolean willAllowId(Object id) { + return false; + } } diff --git a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdge.java b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdge.java index f9d6afb8..c277ce09 100644 --- a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdge.java +++ b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdge.java @@ -19,12 +19,12 @@ import java.util.List; public class OrientEdge extends OrientElement implements Edge { - - private static final List INTERNAL_FIELDS = Arrays.asList("@rid", "@class", "in", "out"); - - protected OIdentifiable vOut; - protected OIdentifiable vIn; - protected String label; + + private static final List INTERNAL_FIELDS = Arrays.asList("@rid", "@class", "in", "out"); + + protected OIdentifiable vOut; + protected OIdentifiable vIn; + protected String label; public OrientEdge(OrientGraph graph, OIdentifiable rawElement, final OIdentifiable out, final OIdentifiable in, final String iLabel) { super(graph, rawElement); @@ -38,16 +38,15 @@ public OrientEdge(OrientGraph graph, String className, final OIdentifiable out, } public OrientEdge(OrientGraph graph, final OIdentifiable out, final OIdentifiable in, final String iLabel) { - this(graph, (OIdentifiable) null, out, in, iLabel); + this(graph, (OIdentifiable) null, out, in, iLabel); } public OrientEdge(OrientGraph graph, ODocument rawDocument, String label) { this(graph, rawDocument, rawDocument.field("out", OIdentifiable.class), rawDocument.field("in", OIdentifiable.class), label); } - public OrientEdge(OrientGraph graph, ODocument rawDocument) - { - this(graph, rawDocument, rawDocument.getClassName()); + public OrientEdge(OrientGraph graph, ODocument rawDocument) { + this(graph, rawDocument, rawDocument.getClassName()); } public static OIdentifiable getConnection(final ODocument iEdgeRecord, final Direction iDirection) { @@ -61,24 +60,20 @@ protected static ODocument createRawElement(OrientGraph graph, String className) @Override public Iterator vertices(Direction direction) { - switch (direction) - { - case OUT: - return graph.vertices(vOut.getIdentity()); - case IN: - return graph.vertices(vIn.getIdentity()); - case BOTH: - default: - return graph.vertices(vOut.getIdentity(), vIn.getIdentity()); - } + switch (direction) { + case OUT: + return graph.vertices(vOut.getIdentity()); + case IN: + return graph.vertices(vIn.getIdentity()); + case BOTH: + default: + return graph.vertices(vOut.getIdentity(), vIn.getIdentity()); + } } public Iterator> properties(final String... propertyKeys) { Iterator> properties = super.properties(propertyKeys); - return StreamUtils.asStream(properties).filter(p -> - !INTERNAL_FIELDS.contains(p.key()) ).map(p -> - (Property) p - ).iterator(); + return StreamUtils.asStream(properties).filter(p -> !INTERNAL_FIELDS.contains(p.key())).map(p -> (Property) p).iterator(); } public OrientVertex getVertex(final Direction direction) { @@ -102,18 +97,17 @@ public void remove() { } @SuppressWarnings("unchecked") - private void removeLink( Direction direction) { + private void removeLink(Direction direction) { final String fieldName = OrientVertex.getConnectionFieldName(direction, this.label()); ODocument doc = this.getVertex(direction).getRawDocument(); Object found = doc.field(fieldName); - if(found instanceof ORidBag) { - ORidBag bag = (ORidBag)found; + if (found instanceof ORidBag) { + ORidBag bag = (ORidBag) found; bag.remove(this.getRawElement()); - if(bag.size() == 0) doc.removeField(fieldName); - } - else if (found instanceof Collection) { + if (bag.size() == 0) doc.removeField(fieldName); + } else if (found instanceof Collection) { ((Collection) found).remove(this.getRawElement()); - if(((Collection) found).size() == 0) doc.removeField(fieldName); + if (((Collection) found).size() == 0) doc.removeField(fieldName); } else throw new IllegalStateException("Relationship content is invalid on field " + fieldName + ". Found: " + found); doc.save(); @@ -128,11 +122,11 @@ public OIdentifiable getOutVertex() { if (doc == null) return null; -// if (settings != null && settings.isKeepInMemoryReferences()) - // AVOID LAZY RESOLVING+SETTING OF RECORD -// return doc.rawField(OrientGraphUtils.CONNECTION_OUT); -// else - return doc.field(OrientGraphUtils.CONNECTION_OUT); + // if (settings != null && settings.isKeepInMemoryReferences()) + // AVOID LAZY RESOLVING+SETTING OF RECORD + // return doc.rawField(OrientGraphUtils.CONNECTION_OUT); + // else + return doc.field(OrientGraphUtils.CONNECTION_OUT); } /** @@ -147,11 +141,11 @@ public OIdentifiable getInVertex() { if (doc == null) return null; -// if (settings != null && settings.isKeepInMemoryReferences()) - // AVOID LAZY RESOLVING+SETTING OF RECORD -// return doc.rawField(OrientGraphUtils.CONNECTION_IN); -// else - return doc.field(OrientGraphUtils.CONNECTION_IN); + // if (settings != null && settings.isKeepInMemoryReferences()) + // AVOID LAZY RESOLVING+SETTING OF RECORD + // return doc.rawField(OrientGraphUtils.CONNECTION_IN); + // else + return doc.field(OrientGraphUtils.CONNECTION_IN); } @Override diff --git a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdgeIterator.java b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdgeIterator.java index 92428b22..a17aa0ce 100644 --- a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdgeIterator.java +++ b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdgeIterator.java @@ -20,8 +20,8 @@ public class OrientEdgeIterator extends OLazyWrapperIterator { private final String[] labels; public OrientEdgeIterator(final OrientVertex iSourceVertex, final OrientVertex iTargetVertex, - final Object iMultiValue, final Iterator iterator, - final OPair connection, final String[] iLabels, final int iSize) { + final Object iMultiValue, final Iterator iterator, + final OPair connection, final String[] iLabels, final int iSize) { super(iterator, iSize, iMultiValue); this.sourceVertex = iSourceVertex; this.targetVertex = iTargetVertex; @@ -52,9 +52,9 @@ public OrientEdge createGraphElement(final Object iObject) { if (!(record instanceof ODocument)) { // SKIP IT OLogManager.instance().warn(this, - "Found a record (%s) that is not an edge. Source vertex : %s, Target vertex : %s, Database : %s .", rec, - sourceVertex != null ? sourceVertex.id() : null, targetVertex != null ? targetVertex.id() : null, - record.getDatabase().getURL()); + "Found a record (%s) that is not an edge. Source vertex : %s, Target vertex : %s, Database : %s .", rec, + sourceVertex != null ? sourceVertex.id() : null, targetVertex != null ? targetVertex.id() : null, + record.getDatabase().getURL()); return null; } @@ -80,13 +80,13 @@ public OrientEdge createGraphElement(final Object iObject) { final OrientEdge edge; if (immutableSchema.isVertexType()) { -// DIRECT VERTEX, CREATE DUMMY EDGE + // DIRECT VERTEX, CREATE DUMMY EDGE if (connection.getKey() == Direction.OUT) edge = new OrientEdge(this.sourceVertex.getGraph(), (OIdentifiable) this.sourceVertex.id(), rec.getIdentity(), - connection.getValue()); + connection.getValue()); else edge = new OrientEdge(this.sourceVertex.getGraph(), rec.getIdentity(), (OIdentifiable) this.sourceVertex.id(), - connection.getValue()); + connection.getValue()); } else if (immutableSchema.isEdgeType()) { edge = new OrientEdge(this.sourceVertex.getGraph(), value, connection.getValue()); } else @@ -96,17 +96,20 @@ public OrientEdge createGraphElement(final Object iObject) { } public boolean filter(final OrientEdge edge) { -// return targetVertex == null || targetVertex.equals(edge.getVertex(connection.getKey().opposite())); -// throw new NotImplementedException(); - //TODO simplify + // return targetVertex == null || + // targetVertex.equals(edge.getVertex(connection.getKey().opposite())); + // throw new NotImplementedException(); + // TODO simplify if (targetVertex != null && !targetVertex.equals(edge.getVertex(connection.getKey().opposite()))) return false; else return true; -// if (targetVertex != null && !targetVertex.equals(iObject.getVertex(connection.getKey().opposite()))) -// return false; -// -// return this.sourceVertex.settings.isUseVertexFieldsForEdgeLabels() || iObject.isLabeled(labels); + // if (targetVertex != null && + // !targetVertex.equals(iObject.getVertex(connection.getKey().opposite()))) + // return false; + // + // return this.sourceVertex.settings.isUseVertexFieldsForEdgeLabels() || + // iObject.isLabeled(labels); } @Override diff --git a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdgeType.java b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdgeType.java index b4836498..619641a1 100644 --- a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdgeType.java +++ b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientEdgeType.java @@ -4,7 +4,8 @@ import com.orientechnologies.orient.core.metadata.schema.OImmutableClass; public class OrientEdgeType extends OrientElementType { - // Keeping the name in Immutable class because i cannot do the other way around + // Keeping the name in Immutable class because i cannot do the other way + // around public static final String CLASS_NAME = OImmutableClass.EDGE_CLASS_NAME; public OrientEdgeType(final OrientGraph graph, final OClass delegate) { diff --git a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientElement.java b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientElement.java index 76f9dbba..8cbe681d 100644 --- a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientElement.java +++ b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientElement.java @@ -17,10 +17,10 @@ import java.util.Map; import java.util.stream.Stream; - public abstract class OrientElement implements Element { private static final Map INTERNAL_CLASSES_TO_TINKERPOP_CLASSES; + static { INTERNAL_CLASSES_TO_TINKERPOP_CLASSES = new HashMap<>(); INTERNAL_CLASSES_TO_TINKERPOP_CLASSES.put(OImmutableClass.VERTEX_CLASS_NAME, Vertex.DEFAULT_LABEL); @@ -43,7 +43,8 @@ public ORID id() { public String label() { String internalClassName = getRawDocument().getClassName(); - // User labels on edges/vertices are prepended with E_ or V_ . The user should not see that. + // User labels on edges/vertices are prepended with E_ or V_ . The user + // should not see that. return internalClassName.length() == 1 ? INTERNAL_CLASSES_TO_TINKERPOP_CLASSES.get(internalClassName) : graph.classNameToLabel(internalClassName); } @@ -52,22 +53,24 @@ public Graph graph() { } public Property property(final String key, final V value) { - return property(key, value, true); //save after setting + return property(key, value, true); // save after setting } private Property property(final String key, final V value, boolean saveDocument) { - if(key == null) + if (key == null) throw Property.Exceptions.propertyKeyCanNotBeNull(); - if(value == null) + if (value == null) throw Property.Exceptions.propertyValueCanNotBeNull(); - if(Graph.Hidden.isHidden(key)) + if (Graph.Hidden.isHidden(key)) throw Property.Exceptions.propertyKeyCanNotBeAHiddenKey(key); ODocument doc = getRawDocument(); doc.field(key, value); - // when setting multiple properties at once, it makes sense to only save them in the end - // for performance reasons and so that the schema checker only kicks in at the end + // when setting multiple properties at once, it makes sense to only save + // them in the end + // for performance reasons and so that the schema checker only kicks in + // at the end if (saveDocument) doc.save(); return new OrientProperty<>(key, value, this); } @@ -77,7 +80,8 @@ public void property(Object... keyValues) { if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported(); // copied from ElementHelper.attachProperties - // can't use ElementHelper here because we only want to save the document at the very end + // can't use ElementHelper here because we only want to save the + // document at the very end for (int i = 0; i < keyValues.length; i = i + 2) { if (!keyValues[i].equals(T.id) && !keyValues[i].equals(T.label)) property((String) keyValues[i], keyValues[i + 1], false); @@ -104,7 +108,7 @@ record = new ODocument(); } public void save() { - ((ODocument)rawElement).save(); + ((ODocument) rawElement).save(); } public ODocument getRawDocument() { @@ -131,5 +135,4 @@ public final boolean equals(final Object object) { return ElementHelper.areEqual(this, object); } - } diff --git a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientElementType.java b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientElementType.java index 79505631..df2ebfa8 100644 --- a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientElementType.java +++ b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientElementType.java @@ -11,90 +11,112 @@ public OrientElementType(final OrientGraph graph, final OClass delegate) { this.graph = graph; } -// @Override -// public OProperty createProperty(final String iPropertyName, final OType iType, final OClass iLinkedClass) { -// return graph.executeOutsideTx(new OCallable() { -// @Override -// public OProperty call(final OrientGraph g) { -// return OrientElementType.super.createProperty(iPropertyName, iType, iLinkedClass); -// } -// }, "create ", getTypeName(), " property '", iPropertyName, "' as type '", iType.toString(), "' linked class '", -// iLinkedClass.getName(), "'"); -// } -// -// @Override -// public OProperty createProperty(final String iPropertyName, final OType iType, final OType iLinkedType) { -// return graph.executeOutsideTx(new OCallable() { -// @Override -// public OProperty call(final OrientGraph g) { -// return OrientElementType.super.createProperty(iPropertyName, iType, iLinkedType); -// } -// }, "create ", getTypeName(), " property '", iPropertyName, "' as type '", iType.toString(), "' linked type '", -// iLinkedType.toString(), "'"); -// } -// -// @Override -// public OProperty createProperty(final String iPropertyName, final OType iType) { -// return graph.executeOutsideTx(new OCallable() { -// @Override -// public OProperty call(final OrientGraph g) { -// return OrientElementType.super.createProperty(iPropertyName, iType); -// } -// }, "create ", getTypeName(), " property '", iPropertyName, "' as type '", iType.toString(), "'"); -// } -// -// @Override -// public OIndex createIndex(final String iName, final INDEX_TYPE iType, final String... fields) { -// return graph.executeOutsideTx(new OCallable, OrientGraph>() { -// @Override -// public OIndex call(final OrientGraph g) { -// return OrientElementType.super.createIndex(iName, iType, fields); -// } -// }, "create index '", iName, "' as type '", iType.toString(), "' on fields: " + Arrays.toString(fields)); -// } -// -// @Override -// public OIndex createIndex(final String iName, final String iType, final String... fields) { -// return graph.executeOutsideTx(new OCallable, OrientGraph>() { -// @Override -// public OIndex call(final OrientGraph g) { -// return OrientElementType.super.createIndex(iName, iType, fields); -// } -// }, "create index '", iName, "' as type '", iType.toString(), "' on fields: " + Arrays.toString(fields)); -// } -// -// @Override -// public OIndex createIndex(final String iName, final INDEX_TYPE iType, final OProgressListener iProgressListener, -// final String... fields) { -// return graph.executeOutsideTx(new OCallable, OrientGraph>() { -// @Override -// public OIndex call(final OrientGraph g) { -// return OrientElementType.super.createIndex(iName, iType, iProgressListener, fields); -// } -// }, "create index '", iName, "' as type '", iType.toString(), "' on fields: " + Arrays.toString(fields)); -// } -// -// @Override -// public OIndex createIndex(final String iName, final String iType, final OProgressListener iProgressListener, -// final ODocument metadata, final String algorithm, final String... fields) { -// return graph.executeOutsideTx(new OCallable, OrientGraph>() { -// @Override -// public OIndex call(final OrientGraph g) { -// return OrientElementType.super.createIndex(iName, iType, iProgressListener, metadata, algorithm, fields); -// } -// }, "create index '", iName, "' as type '", iType.toString(), "' on fields: " + Arrays.toString(fields)); -// } -// -// @Override -// public OIndex createIndex(final String iName, final String iType, final OProgressListener iProgressListener, -// final ODocument metadata, final String... fields) { -// return graph.executeOutsideTx(new OCallable, OrientGraph>() { -// @Override -// public OIndex call(final OrientGraph g) { -// return OrientElementType.super.createIndex(iName, iType, iProgressListener, metadata, fields); -// } -// }, "create index '", iName, "' as type '", iType.toString(), "' on fields: " + Arrays.toString(fields)); -// } + // @Override + // public OProperty createProperty(final String iPropertyName, final OType + // iType, final OClass iLinkedClass) { + // return graph.executeOutsideTx(new OCallable() { + // @Override + // public OProperty call(final OrientGraph g) { + // return OrientElementType.super.createProperty(iPropertyName, iType, + // iLinkedClass); + // } + // }, "create ", getTypeName(), " property '", iPropertyName, "' as type '", + // iType.toString(), "' linked class '", + // iLinkedClass.getName(), "'"); + // } + // + // @Override + // public OProperty createProperty(final String iPropertyName, final OType + // iType, final OType iLinkedType) { + // return graph.executeOutsideTx(new OCallable() { + // @Override + // public OProperty call(final OrientGraph g) { + // return OrientElementType.super.createProperty(iPropertyName, iType, + // iLinkedType); + // } + // }, "create ", getTypeName(), " property '", iPropertyName, "' as type '", + // iType.toString(), "' linked type '", + // iLinkedType.toString(), "'"); + // } + // + // @Override + // public OProperty createProperty(final String iPropertyName, final OType + // iType) { + // return graph.executeOutsideTx(new OCallable() { + // @Override + // public OProperty call(final OrientGraph g) { + // return OrientElementType.super.createProperty(iPropertyName, iType); + // } + // }, "create ", getTypeName(), " property '", iPropertyName, "' as type '", + // iType.toString(), "'"); + // } + // + // @Override + // public OIndex createIndex(final String iName, final INDEX_TYPE iType, + // final String... fields) { + // return graph.executeOutsideTx(new OCallable, OrientGraph>() { + // @Override + // public OIndex call(final OrientGraph g) { + // return OrientElementType.super.createIndex(iName, iType, fields); + // } + // }, "create index '", iName, "' as type '", iType.toString(), "' on + // fields: " + Arrays.toString(fields)); + // } + // + // @Override + // public OIndex createIndex(final String iName, final String iType, + // final String... fields) { + // return graph.executeOutsideTx(new OCallable, OrientGraph>() { + // @Override + // public OIndex call(final OrientGraph g) { + // return OrientElementType.super.createIndex(iName, iType, fields); + // } + // }, "create index '", iName, "' as type '", iType.toString(), "' on + // fields: " + Arrays.toString(fields)); + // } + // + // @Override + // public OIndex createIndex(final String iName, final INDEX_TYPE iType, + // final OProgressListener iProgressListener, + // final String... fields) { + // return graph.executeOutsideTx(new OCallable, OrientGraph>() { + // @Override + // public OIndex call(final OrientGraph g) { + // return OrientElementType.super.createIndex(iName, iType, + // iProgressListener, fields); + // } + // }, "create index '", iName, "' as type '", iType.toString(), "' on + // fields: " + Arrays.toString(fields)); + // } + // + // @Override + // public OIndex createIndex(final String iName, final String iType, + // final OProgressListener iProgressListener, + // final ODocument metadata, final String algorithm, final String... fields) + // { + // return graph.executeOutsideTx(new OCallable, OrientGraph>() { + // @Override + // public OIndex call(final OrientGraph g) { + // return OrientElementType.super.createIndex(iName, iType, + // iProgressListener, metadata, algorithm, fields); + // } + // }, "create index '", iName, "' as type '", iType.toString(), "' on + // fields: " + Arrays.toString(fields)); + // } + // + // @Override + // public OIndex createIndex(final String iName, final String iType, + // final OProgressListener iProgressListener, + // final ODocument metadata, final String... fields) { + // return graph.executeOutsideTx(new OCallable, OrientGraph>() { + // @Override + // public OIndex call(final OrientGraph g) { + // return OrientElementType.super.createIndex(iName, iType, + // iProgressListener, metadata, fields); + // } + // }, "create index '", iName, "' as type '", iType.toString(), "' on + // fields: " + Arrays.toString(fields)); + // } protected abstract String getTypeName(); } diff --git a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientGraph.java b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientGraph.java index 91a57b75..377dd274 100644 --- a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientGraph.java +++ b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientGraph.java @@ -54,9 +54,9 @@ public final class OrientGraph implements Graph { static { TraversalStrategies.GlobalCache.registerStrategies( - OrientGraph.class, - TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone() - .addStrategies(OrientGraphStepStrategy.instance())); + OrientGraph.class, + TraversalStrategies.GlobalCache.getStrategies(Graph.class).clone() + .addStrategies(OrientGraphStepStrategy.instance())); } public static String CONFIG_URL = "orient-url"; @@ -160,30 +160,30 @@ public GraphComputer compute() throws IllegalArgumentException { public Iterator vertices(Object... vertexIds) { makeActive(); return elements( - OImmutableClass.VERTEX_CLASS_NAME, - r -> new OrientVertex(this, getRawDocument(r)), - vertexIds); + OImmutableClass.VERTEX_CLASS_NAME, + r -> new OrientVertex(this, getRawDocument(r)), + vertexIds); } /** * Convert a label to orientdb class name */ public String labelToClassName(String label, String prefix) { - if (configuration.getBoolean(CONFIG_LABEL_AS_CLASSNAME, false)) { - return label; - } - return label.equals(prefix) ? prefix : prefix + "_" + label; + if (configuration.getBoolean(CONFIG_LABEL_AS_CLASSNAME, false)) { + return label; + } + return label.equals(prefix) ? prefix : prefix + "_" + label; } - + /** * Convert a orientdb class name to label */ public String classNameToLabel(String className) { - if (configuration.getBoolean(CONFIG_LABEL_AS_CLASSNAME, false)) { - return className; - } - return className.substring(2); - } + if (configuration.getBoolean(CONFIG_LABEL_AS_CLASSNAME, false)) { + return className; + } + return className.substring(2); + } protected Object convertValue(final OIndex idx, Object iValue) { if (iValue != null) { @@ -199,12 +199,12 @@ protected Object convertValue(final OIndex idx, Object iValue) { public Stream getIndexedVertices(OIndex index, Optional valueOption) { makeActive(); -// if (iKey.equals("@class")) -// return getVerticesOfClass(iValue.toString()); + // if (iKey.equals("@class")) + // return getVerticesOfClass(iValue.toString()); if (index == null) { // NO INDEX - return Collections.emptyList().stream(); + return Collections. emptyList().stream(); } else { if (!valueOption.isPresent()) { return index.cursor().toValues().stream().map(id -> new OrientVertex(this, id)); @@ -212,7 +212,7 @@ public Stream getIndexedVertices(OIndex index, OptionalemptyList().stream(); + return Collections. emptyList().stream(); } else if (!(indexValue instanceof Iterable)) { indexValue = Collections.singletonList(indexValue); } @@ -228,12 +228,11 @@ public Stream getIndexedVertices(OIndex index, Optional getIndexedKeys(String className) { Iterator> indexes = getIndexManager().getClassIndexes(className).iterator(); HashSet indexedKeys = new HashSet<>(); @@ -265,29 +264,29 @@ public Set getIndexedKeys(final Class elementClass) { public Set getVertexIndexedKeys(final String label) { String className = labelToClassName(label, OImmutableClass.VERTEX_CLASS_NAME); - OClass cls = getSchema().getClass(className); - if (cls != null && cls.isSubClassOf(OImmutableClass.VERTEX_CLASS_NAME)) { - return getIndexedKeys(className); - } - return new HashSet(); + OClass cls = getSchema().getClass(className); + if (cls != null && cls.isSubClassOf(OImmutableClass.VERTEX_CLASS_NAME)) { + return getIndexedKeys(className); + } + return new HashSet(); } public Set getEdgeIndexedKeys(final String label) { String className = labelToClassName(label, OImmutableClass.EDGE_CLASS_NAME); - OClass cls = getSchema().getClass(className); - if (cls != null && cls.isSubClassOf(OImmutableClass.EDGE_CLASS_NAME)) { - return getIndexedKeys(className); - } - return new HashSet(); + OClass cls = getSchema().getClass(className); + if (cls != null && cls.isSubClassOf(OImmutableClass.EDGE_CLASS_NAME)) { + return getIndexedKeys(className); + } + return new HashSet(); } @Override public Iterator edges(Object... edgeIds) { makeActive(); return elements( - OImmutableClass.EDGE_CLASS_NAME, - r -> new OrientEdge(this, getRawDocument(r)), - edgeIds); + OImmutableClass.EDGE_CLASS_NAME, + r -> new OrientEdge(this, getRawDocument(r)), + edgeIds); } protected Iterator elements(String elementClass, Function toA, Object... elementIds) { @@ -321,7 +320,7 @@ protected static ORID createRecordId(Object id) { return (ORecordId) id; if (id instanceof String) return new ORecordId((String) id); - if(id instanceof OrientElement) + if (id instanceof OrientElement) return ((OrientElement) id).id(); throw new IllegalArgumentException("Orient IDs have to be a String or ORecordId - you provided a " + id.getClass()); @@ -336,7 +335,7 @@ record = record.getRecord(); currentDocument.load(); if (ODocumentInternal.getImmutableSchemaClass(currentDocument) == null) throw new IllegalArgumentException( - "Cannot determine the graph element type because the document class is null. Probably this is a projection, use the EXPAND() function"); + "Cannot determine the graph element type because the document class is null. Probably this is a projection, use the EXPAND() function"); return currentDocument; } @@ -385,7 +384,7 @@ public void commit() { public void rollback() { makeActive(); - + if (!features.graph().supportsTransactions()) { return; } @@ -405,7 +404,6 @@ public boolean isAutoStartTx() { return true; } - @Override public Variables variables() { makeActive(); @@ -473,20 +471,16 @@ public void createClass(final String className, final OClass superClass) { OSchemaProxy schema = database.getMetadata().getSchema(); OClass cls = schema.getClass(className); if (cls == null) { - try - { - schema.createClass(className, superClass); - } - catch (OException e) - { - throw new IllegalArgumentException(e); + try { + schema.createClass(className, superClass); + } catch (OException e) { + throw new IllegalArgumentException(e); } OLogManager.instance().info(this, "created class '" + className + "' as subclass of '" + superClass + "'"); - } - else { - if (!cls.isSubClassOf(superClass)) { - throw new IllegalArgumentException("unable to create class '" + className + "' as subclass of '" + superClass + "'. different super class."); - } + } else { + if (!cls.isSubClassOf(superClass)) { + throw new IllegalArgumentException("unable to create class '" + className + "' as subclass of '" + superClass + "'. different super class."); + } } } @@ -496,9 +490,11 @@ public ODatabaseDocumentTx getRawDatabase() { } /** - * Returns the persistent class for type iTypeName as OrientEdgeType instance. + * Returns the persistent class for type iTypeName as OrientEdgeType + * instance. * - * @param iTypeName Edge class name + * @param iTypeName + * Edge class name */ public final OrientEdgeType getEdgeType(final String iTypeName) { makeActive(); @@ -537,14 +533,12 @@ protected void prepareIndexConfiguration(Configuration config) { config.setProperty("metadata", defaultMetadata); } - public void createVertexIndex(final String key, final String label, final Configuration configuration) { String className = labelToClassName(label, OrientVertexType.CLASS_NAME); createVertexClass(className); createIndex(key, className, configuration); } - public void createEdgeIndex(final String key, final String label, final Configuration configuration) { String className = labelToClassName(label, OrientEdgeType.CLASS_NAME); createEdgeClass(className); @@ -565,7 +559,6 @@ public OClass call(final OrientGraph g) { String collate = configuration.getString("collate"); ODocument metadata = (ODocument) configuration.getProperty("metadata"); - final ODatabaseDocumentTx db = getRawDatabase(); final OSchema schema = db.getMetadata().getSchema(); @@ -578,7 +571,7 @@ public OClass call(final OrientGraph g) { if (collate != null) indexDefinition.setCollate(collate); db.getMetadata().getIndexManager() - .createIndex(className + "." + key, indexType, indexDefinition, cls.getPolymorphicClusterIds(), null, metadata); + .createIndex(className + "." + key, indexType, indexDefinition, cls.getPolymorphicClusterIds(), null, metadata); return null; } }; @@ -596,16 +589,15 @@ public RET execute(final OCallable iCallable, final Stri // ASSURE PENDING TX IF ANY IS COMMITTED OLogManager.instance().warn( - this, - msg.toString()); + this, + msg.toString()); } return iCallable.call(this); } @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public I io(Builder builder) - { + @Override + public I io(Builder builder) { return (I) Graph.super.io(builder.registry(OrientIoRegistry.getInstance())); } diff --git a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientGraphFactory.java b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientGraphFactory.java index 1c21b2d5..7001dfa2 100644 --- a/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientGraphFactory.java +++ b/driver/src/main/java/org/apache/tinkerpop/gremlin/orientdb/OrientGraphFactory.java @@ -9,7 +9,6 @@ import org.apache.commons.configuration.Configuration; import org.apache.tinkerpop.gremlin.structure.Graph; - public final class OrientGraphFactory { public static String ADMIN = "admin"; protected final String url; @@ -36,15 +35,17 @@ public OrientGraphFactory(Configuration config) { } /** - * Gets transactional graph with the database from pool if pool is configured. Otherwise creates a graph with new db instance. The - * Graph instance inherits the factory's configuration. + * Gets transactional graph with the database from pool if pool is + * configured. Otherwise creates a graph with new db instance. The Graph + * instance inherits the factory's configuration. * * @param create - * if true automatically creates database if database with given URL does not exist + * if true automatically creates database if database with given + * URL does not exist * @param open - * if true automatically opens the database + * if true automatically opens the database */ - //TODO: allow to open with these properties + // TODO: allow to open with these properties public OrientGraph getNoTx(boolean create, boolean open) { return getGraph(create, open, false); } @@ -90,7 +91,7 @@ protected void initGraph(OrientGraph g) { if (txActive) { // REOPEN IT AGAIN db.begin(); -// db.getTransaction().setUsingLog(settings.isUseLog()); + // db.getTransaction().setUsingLog(settings.isUseLog()); } } @@ -98,26 +99,32 @@ protected Configuration getConfiguration(boolean create, boolean open, boolean t if (configuration != null) return configuration; else - return new BaseConfiguration() {{ - setProperty(Graph.GRAPH, OrientGraph.class.getName()); - setProperty(OrientGraph.CONFIG_URL, url); - setProperty(OrientGraph.CONFIG_USER, user); - setProperty(OrientGraph.CONFIG_PASS, password); - setProperty(OrientGraph.CONFIG_CREATE, create); - setProperty(OrientGraph.CONFIG_OPEN, open); - setProperty(OrientGraph.CONFIG_TRANSACTIONAL, transactional); - setProperty(OrientGraph.CONFIG_LABEL_AS_CLASSNAME, labelAsClassName); - }}; + return new BaseConfiguration() { + { + setProperty(Graph.GRAPH, OrientGraph.class.getName()); + setProperty(OrientGraph.CONFIG_URL, url); + setProperty(OrientGraph.CONFIG_USER, user); + setProperty(OrientGraph.CONFIG_PASS, password); + setProperty(OrientGraph.CONFIG_CREATE, create); + setProperty(OrientGraph.CONFIG_OPEN, open); + setProperty(OrientGraph.CONFIG_TRANSACTIONAL, transactional); + setProperty(OrientGraph.CONFIG_LABEL_AS_CLASSNAME, labelAsClassName); + } + }; } /** - * @param create if true automatically creates database if database with given URL does not exist - * @param open if true automatically opens the database + * @param create + * if true automatically creates database if database with given + * URL does not exist + * @param open + * if true automatically opens the database */ protected ODatabaseDocumentTx getDatabase(boolean create, boolean open) { final ODatabaseDocumentTx db = new ODatabaseFactory().createDatabase("graph", url); if (!db.getURL().startsWith("remote:") && !db.exists()) { - if (create) db.create(); + if (create) + db.create(); else if (open) throw new ODatabaseException("Database '" + url + "' not found"); } else if (open) db.open(user, password); @@ -125,9 +132,12 @@ protected ODatabaseDocumentTx getDatabase(boolean create, boolean open) { } /** - * Enable or disable the prefixing of class names with V_