Skip to content

Commit

Permalink
Issue #7484 was fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii0lomakin committed Jul 13, 2017
1 parent 2058f3e commit ca988b1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public Index<T> 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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -738,6 +744,7 @@ public Iterable<Vertex> 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<Vertex> getVertices(final boolean iPolymorphic) {
Expand All @@ -750,6 +757,7 @@ public Iterable<Vertex> 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<Vertex> getVerticesOfClass(final String iClassName) {
Expand All @@ -763,6 +771,7 @@ public Iterable<Vertex> 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<Vertex> getVerticesOfClass(final String iClassName, final boolean iPolymorphic) {
Expand All @@ -785,6 +794,7 @@ public Iterable<Vertex> getVerticesOfClass(final String iClassName, final boolea
*
* @param iKey Field name
* @param iValue Field value
*
* @return Vertices as Iterable
*/
public Iterable<Vertex> getVertices(final String iKey, Object iValue) {
Expand Down Expand Up @@ -843,7 +853,9 @@ public Iterable<Vertex> 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
Expand Down Expand Up @@ -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<Vertex> getVertices(final String label, final String[] iKey, Object[] iValue) {
Expand All @@ -899,7 +912,7 @@ public Iterable<Vertex> getVertices(final String label, final String[] iKey, Obj
}
List<Object> 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);
Expand Down Expand Up @@ -935,6 +948,7 @@ public Iterable<Edge> 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<Edge> getEdges(final boolean iPolymorphic) {
Expand All @@ -947,6 +961,7 @@ public Iterable<Edge> 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<Edge> getEdgesOfClass(final String iClassName) {
Expand All @@ -960,6 +975,7 @@ public Iterable<Edge> 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<Edge> getEdgesOfClass(final String iClassName, final boolean iPolymorphic) {
Expand All @@ -982,6 +998,7 @@ public Iterable<Edge> getEdgesOfClass(final String iClassName, final boolean iPo
*
* @param iKey Field name
* @param iValue Field value
*
* @return Edges as Iterable
*/
public Iterable<Edge> getEdges(final String iKey, Object iValue) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -1656,6 +1691,7 @@ public <T extends Element> Set<String> getIndexedKeys(final Class<T> 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 <T extends Element> Set<String> getIndexedKeys(final Class<T> elementClass, final boolean includeClassNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> permissionsOne = new HashSet<String>();
permissionsOne.add("perm1");
permissionsOne.add("perm2");

String loginTwo = "user";
Set<String> permissionsTwo = new HashSet<String>();
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<Vertex> vertices = g.getVertices("VComposite", new String[] { "login" }, new String[] { "admin" });
Iterator<Vertex> 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");
Expand Down

0 comments on commit ca988b1

Please sign in to comment.