Skip to content

Commit

Permalink
fixed #4973
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Sep 18, 2015
1 parent 44c7eba commit 2447d8b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
Expand Up @@ -251,7 +251,8 @@ public OrientBaseGraph(final String url, final String username, final String pas
* of graph
*/
public OrientBaseGraph(final Configuration configuration) {
this(configuration.getString("blueprints.orientdb.url", null), configuration.getString("blueprints.orientdb.username", null), configuration.getString("blueprints.orientdb.password", null));
this(configuration.getString("blueprints.orientdb.url", null), configuration.getString("blueprints.orientdb.username", null),
configuration.getString("blueprints.orientdb.password", null));
super.init(configuration);
}

Expand Down Expand Up @@ -785,13 +786,14 @@ public Iterable<Vertex> getVertices(final String iKey, Object iValue) {
String indexName;
final String key;
int pos = iKey.indexOf('.');
OClass clazz = null;
if (pos > -1) {
indexName = iKey;

final String className = iKey.substring(0, pos);
key = iKey.substring(iKey.indexOf('.') + 1);

final OClass clazz = database.getMetadata().getImmutableSchemaSnapshot().getClass(className);
clazz = database.getMetadata().getImmutableSchemaSnapshot().getClass(className);

final Collection<? extends OIndex<?>> indexes = clazz.getIndexes();
for (OIndex<?> index : indexes) {
Expand Down Expand Up @@ -821,7 +823,10 @@ public Iterable<Vertex> getVertices(final String iKey, Object iValue) {
}

// NO INDEX: EXECUTE A QUERY
return query().has(key, iValue).vertices();
OrientGraphQuery query = (OrientGraphQuery) query();
if (clazz != null)
query.labels(clazz.getName());
return query.has(key, iValue).vertices();
}

/**
Expand Down
@@ -1,16 +1,15 @@
package com.tinkerpop.blueprints.impls.orient;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.tinkerpop.blueprints.Vertex;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import com.tinkerpop.blueprints.Vertex;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@RunWith(JUnit4.class)
public class BlueprintsKeyIndexTest {
Expand Down Expand Up @@ -70,6 +69,41 @@ public void test_without_createKeyIndex() throws Exception {
}
}

@Test
public void test_without_createKeyIndexVertexType() throws Exception {
final OrientGraph graph = new OrientGraph("memory:" + BlueprintsKeyIndexTest.class.getSimpleName());
graph.setWarnOnForceClosingTx(false);
graph.createVertexType("Test");

graph.createVertexType("Test1");
try {
/* create key index */
// graph.createKeyIndex("name", Vertex.class);

/* create the root vertex */{
Vertex v = graph.addVertex("class:Test");
v.setProperty(KEY_NAME, ROOT_NODE_NAME); /* as key index */

v = graph.addVertex("class:Test1");
v.setProperty(KEY_NAME, ROOT_NODE_NAME);

v = graph.addVertex("class:Test1");
v.setProperty(KEY_NAME, "Fail");

graph.commit();

final Object rootVertexId = v.getId();
assertNotNull(rootVertexId);
}

/* get rootNode */
final List<Vertex> rootNodes = toArrayList(graph.getVertices("Test." + KEY_NAME, ROOT_NODE_NAME));
assertEquals(1, rootNodes.size()); // ########## no problem
} finally {
graph.drop();
}
}

// ///

public static <E> ArrayList<E> toArrayList(final Iterable<E> iterable) {
Expand Down

0 comments on commit 2447d8b

Please sign in to comment.