diff --git a/graphdb/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java b/graphdb/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java index 4dc54a3fdd9..54c06a78f7b 100755 --- a/graphdb/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java +++ b/graphdb/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java @@ -424,6 +424,7 @@ public Index call(final OrientBaseGraph g) { * * @param indexName Index name * @param indexClass Class as one or subclass of Vertex.class and Edge.class + * * @return Index instance */ @SuppressWarnings("unchecked") @@ -494,6 +495,7 @@ public Object call(OrientBaseGraph g) { * Creates a new unconnected vertex with no fields in the Graph. * * @param id Optional, can contains the Vertex's class name by prefixing with "class:" + * * @return The new OrientVertex created */ @Override @@ -528,6 +530,7 @@ public OrientBaseGraph setConflictStrategy(final ORecordConflictStrategy iResolv * * @param id Optional, can contains the Vertex's class name by prefixing with "class:" * @param prop Fields must be a odd pairs of key/value or a single object as Map containing entries as key/value pairs + * * @return The new OrientVertex created */ public OrientVertex addVertex(Object id, final Object... prop) { @@ -577,6 +580,7 @@ else if (s.startsWith(CLUSTER_PREFIX)) * * @param iClassName Vertex class name * @param iClusterName Vertex cluster name + * * @return New vertex created */ public OrientVertex addVertex(final String iClassName, final String iClusterName) { @@ -601,6 +605,7 @@ public OrientVertex addVertex(final String iClassName, final String iClusterName * * @param iClassName Vertex's class name * @param prop Fields must be a odd pairs of key/value or a single object as Map containing entries as key/value pairs + * * @return added vertex */ public OrientVertex addTemporaryVertex(final String iClassName, final Object... prop) { @@ -621,6 +626,7 @@ public OrientVertex addTemporaryVertex(final String iClassName, final Object... * @param outVertex Source vertex * @param inVertex Destination vertex * @param label Edge's label + * * @return */ @Override @@ -738,6 +744,7 @@ public Iterable getVertices() { * Get all the Vertices in Graph specifying if consider or not sub-classes of V. * * @param iPolymorphic If true then get all the vertices of any sub-class + * * @return Vertices as Iterable */ public Iterable getVertices(final boolean iPolymorphic) { @@ -750,6 +757,7 @@ public Iterable getVertices(final boolean iPolymorphic) { * Get all the Vertices in Graph of a specific vertex class and all sub-classes. * * @param iClassName Vertex class name to filter + * * @return Vertices as Iterable */ public Iterable getVerticesOfClass(final String iClassName) { @@ -763,6 +771,7 @@ public Iterable getVerticesOfClass(final String iClassName) { * * @param iClassName Vertex class name to filter * @param iPolymorphic If true consider also Vertex iClassName sub-classes + * * @return Vertices as Iterable */ public Iterable getVerticesOfClass(final String iClassName, final boolean iPolymorphic) { @@ -785,6 +794,7 @@ public Iterable getVerticesOfClass(final String iClassName, final boolea * * @param iKey Field name * @param iValue Field value + * * @return Vertices as Iterable */ public Iterable getVertices(final String iKey, Object iValue) { @@ -843,7 +853,9 @@ public Iterable getVertices(final String iKey, Object iValue) { * * @param iKey Name of the indexed property * @param iValue Field value + * * @return Vertex instance if found, otherwise null + * * @see #getVertices(String, Object) */ @Deprecated @@ -875,6 +887,7 @@ public Vertex getVertexByKey(final String iKey, Object iValue) { * * @param iKey Fields name * @param iValue Fields value + * * @return Vertices as Iterable */ public Iterable getVertices(final String label, final String[] iKey, Object[] iValue) { @@ -899,7 +912,7 @@ public Iterable getVertices(final String label, final String[] iKey, Obj } List keys = Arrays.asList(convertKeys(idx, sortedParams)); Object key; - if (keys.size() == 1) { + if (indexFields.size() == 1) { key = keys.get(0); } else { key = new OCompositeKey(keys); @@ -935,6 +948,7 @@ public Iterable getEdges() { * Get all the Edges in Graph specifying if consider or not sub-classes of E. * * @param iPolymorphic If true then get all the edge of any sub-class + * * @return Edges as Iterable */ public Iterable getEdges(final boolean iPolymorphic) { @@ -947,6 +961,7 @@ public Iterable getEdges(final boolean iPolymorphic) { * Get all the Edges in Graph of a specific edge class and all sub-classes. * * @param iClassName Edge class name to filter + * * @return Edges as Iterable */ public Iterable getEdgesOfClass(final String iClassName) { @@ -960,6 +975,7 @@ public Iterable getEdgesOfClass(final String iClassName) { * * @param iClassName Edge class name to filter * @param iPolymorphic If true consider also iClassName Edge sub-classes + * * @return Edges as Iterable */ public Iterable getEdgesOfClass(final String iClassName, final boolean iPolymorphic) { @@ -982,6 +998,7 @@ public Iterable getEdgesOfClass(final String iClassName, final boolean iPo * * @param iKey Field name * @param iValue Field value + * * @return Edges as Iterable */ public Iterable getEdges(final String iKey, Object iValue) { @@ -1232,6 +1249,7 @@ public OrientVertexType getVertexType(final String iTypeName) { * Creates a new Vertex persistent class. * * @param iClassName Vertex class name + * * @return OrientVertexType instance representing the persistent class */ public OrientVertexType createVertexType(final String iClassName) { @@ -1246,6 +1264,7 @@ public OrientVertexType createVertexType(final String iClassName) { * @param iClassName Vertex class name * @param clusters The number of clusters to create for the new class. By default the MINIMUMCLUSTERS database setting is used. * In v2.2 and later, the number of clusters are proportioned to the amount of cores found on the machine + * * @return OrientVertexType instance representing the persistent class */ public OrientVertexType createVertexType(final String iClassName, final int clusters) { @@ -1258,6 +1277,7 @@ public OrientVertexType createVertexType(final String iClassName, final int clus * * @param iClassName Vertex class name * @param iSuperClassName Vertex class name to extend + * * @return OrientVertexType instance representing the persistent class */ public OrientVertexType createVertexType(final String iClassName, final String iSuperClassName) { @@ -1273,6 +1293,7 @@ public OrientVertexType createVertexType(final String iClassName, final String i * @param clusters The number of clusters to create for the new class. By default the MINIMUMCLUSTERS database setting is * used. In v2.2 and later, the number of clusters are proportioned to the amount of cores found on the * machine + * * @return OrientVertexType instance representing the persistent class */ public OrientVertexType createVertexType(final String iClassName, final String iSuperClassName, final int clusters) { @@ -1285,6 +1306,7 @@ public OrientVertexType createVertexType(final String iClassName, final String i * * @param iClassName Vertex class name * @param iSuperClass OClass Vertex to extend + * * @return OrientVertexType instance representing the persistent class */ public OrientVertexType createVertexType(final String iClassName, final OClass iSuperClass) { @@ -1304,6 +1326,7 @@ public OrientVertexType call(final OrientBaseGraph g) { * * @param iClassName Vertex class name * @param iSuperClass OClass Vertex to extend + * * @return OrientVertexType instance representing the persistent class */ public OrientVertexType createVertexType(final String iClassName, final OClass iSuperClass, final int clusters) { @@ -1370,6 +1393,7 @@ public OrientEdgeType getEdgeType(final String iTypeName) { * Creates a new Edge persistent class. * * @param iClassName Edge class name + * * @return OrientEdgeType instance representing the persistent class */ public OrientEdgeType createEdgeType(final String iClassName) { @@ -1383,6 +1407,7 @@ public OrientEdgeType createEdgeType(final String iClassName) { * @param iClassName Edge class name * @param clusters The number of clusters to create for the new class. By default the MINIMUMCLUSTERS database setting is used. * In v2.2 and later, the number of clusters are proportioned to the amount of cores found on the machine + * * @return OrientEdgeType instance representing the persistent class */ public OrientEdgeType createEdgeType(final String iClassName, final int clusters) { @@ -1395,6 +1420,7 @@ public OrientEdgeType createEdgeType(final String iClassName, final int clusters * * @param iClassName Edge class name * @param iSuperClassName Edge class name to extend + * * @return OrientEdgeType instance representing the persistent class */ public OrientEdgeType createEdgeType(final String iClassName, final String iSuperClassName) { @@ -1410,6 +1436,7 @@ public OrientEdgeType createEdgeType(final String iClassName, final String iSupe * @param clusters The number of clusters to create for the new class. By default the MINIMUMCLUSTERS database setting is * used. In v2.2 and later, the number of clusters are proportioned to the amount of cores found on the * machine + * * @return OrientEdgeType instance representing the persistent class */ public OrientEdgeType createEdgeType(final String iClassName, final String iSuperClassName, final int clusters) { @@ -1424,6 +1451,7 @@ public OrientEdgeType createEdgeType(final String iClassName, final String iSupe * @param iSuperClass OClass Edge to extend * @param clusters The number of clusters to create for the new class. By default the MINIMUMCLUSTERS database setting is used. * In v2.2 and later, the number of clusters are proportioned to the amount of cores found on the machine + * * @return OrientEdgeType instance representing the persistent class */ public OrientEdgeType createEdgeType(final String iClassName, final OClass iSuperClass, final int clusters) { @@ -1443,6 +1471,7 @@ public OrientEdgeType call(final OrientBaseGraph g) { * * @param iClassName Edge class name * @param iSuperClass OClass Edge to extend + * * @return OrientEdgeType instance representing the persistent class */ public OrientEdgeType createEdgeType(final String iClassName, final OClass iSuperClass) { @@ -1481,7 +1510,9 @@ public OClass call(final OrientBaseGraph g) { * Detaches a Graph Element to be used offline. All the changes will be committed on further @attach call. * * @param iElement Graph element to detach + * * @return The detached element + * * @see #attach(OrientElement) */ public OrientElement detach(final OrientElement iElement) { @@ -1495,7 +1526,9 @@ public OrientElement detach(final OrientElement iElement) { * Attaches a previously detached Graph Element to the current Graph. All the pending changes will be committed. * * @param iElement Graph element to attach + * * @return The attached element + * * @see #detach(OrientElement) */ public OrientElement attach(final OrientElement iElement) { @@ -1508,6 +1541,7 @@ public OrientElement attach(final OrientElement iElement) { * Returns a graph element, vertex or edge, starting from an ID. * * @param id Can by a String, ODocument or an OIdentifiable object. + * * @return OrientElement subclass such as OrientVertex or OrientEdge */ public OrientElement getElement(final Object id) { @@ -1642,6 +1676,7 @@ else if (p.getKey().toString().startsWith("metadata.")) { * Returns the indexed properties. * * @param elementClass the element class that the index is for + * * @return Set of String containing the indexed properties */ @Override @@ -1656,6 +1691,7 @@ public Set getIndexedKeys(final Class elementClas * * @param elementClass the element class that the index is for * @param includeClassNames If true includes also the class name as prefix of fields + * * @return Set of String containing the indexed properties */ public Set getIndexedKeys(final Class elementClass, final boolean includeClassNames) { diff --git a/graphdb/src/test/java/com/orientechnologies/orient/graph/blueprints/GraphTest.java b/graphdb/src/test/java/com/orientechnologies/orient/graph/blueprints/GraphTest.java index 06df0f007b1..7d5aff14dfe 100755 --- a/graphdb/src/test/java/com/orientechnologies/orient/graph/blueprints/GraphTest.java +++ b/graphdb/src/test/java/com/orientechnologies/orient/graph/blueprints/GraphTest.java @@ -20,6 +20,7 @@ import com.orientechnologies.orient.core.index.OCompositeKey; import com.orientechnologies.orient.core.index.OIndexException; +import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OType; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.OCommandSQL; @@ -31,9 +32,7 @@ import org.junit.BeforeClass; import org.junit.Test; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.util.*; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; @@ -116,6 +115,41 @@ public void testIndexCollate() { } + @Test + public void testGetCompositeKeyBySingleValue() { + OrientGraph g = new OrientGraph(URL, "admin", "admin"); + + OrientVertexType vComposite = g.createVertexType("VComposite"); + vComposite.createProperty("login", OType.STRING); + vComposite.createProperty("permissions", OType.EMBEDDEDSET, OType.STRING); + + vComposite.createIndex("VComposite_Login_Perm", OClass.INDEX_TYPE.UNIQUE, "login", "permissions"); + + String loginOne = "admin"; + Set permissionsOne = new HashSet(); + permissionsOne.add("perm1"); + permissionsOne.add("perm2"); + + String loginTwo = "user"; + Set permissionsTwo = new HashSet(); + permissionsTwo.add("perm3"); + permissionsTwo.add("perm4"); + + g.addVertex("class:VComposite", "login", loginOne, "permissions", permissionsOne); + g.commit(); + + g.addVertex("class:VComposite", "login", loginTwo, "permissions", permissionsTwo); + g.commit(); + + Iterable vertices = g.getVertices("VComposite", new String[] { "login" }, new String[] { "admin" }); + Iterator verticesIterator = vertices.iterator(); + + Assert.assertTrue(verticesIterator.hasNext()); + Vertex vertex = verticesIterator.next(); + Assert.assertEquals(vertex.getProperty("login"), "admin"); + Assert.assertEquals(vertex.getProperty("permissions"), permissionsOne); + } + @Test public void testEmbeddedListAsVertexProperty() { OrientGraph g = new OrientGraph(URL, "admin", "admin");