use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.
the class TestAutoIndexing method testGettingAutoIndexByNameReturnsSomethingReadOnly.
@Test
public void testGettingAutoIndexByNameReturnsSomethingReadOnly() {
// Create the node and relationship auto-indexes
graphDb.index().getNodeAutoIndexer().setEnabled(true);
graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty("nodeProp");
graphDb.index().getRelationshipAutoIndexer().setEnabled(true);
graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty("relProp");
newTransaction();
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Relationship rel = node1.createRelationshipTo(node2, RelationshipType.withName("FOO"));
node1.setProperty("nodeProp", "nodePropValue");
rel.setProperty("relProp", "relPropValue");
newTransaction();
assertEquals(1, graphDb.index().nodeIndexNames().length);
assertEquals(1, graphDb.index().relationshipIndexNames().length);
assertEquals("node_auto_index", graphDb.index().nodeIndexNames()[0]);
assertEquals("relationship_auto_index", graphDb.index().relationshipIndexNames()[0]);
Index<Node> nodeIndex = graphDb.index().forNodes("node_auto_index");
RelationshipIndex relIndex = graphDb.index().forRelationships("relationship_auto_index");
assertEquals(node1, nodeIndex.get("nodeProp", "nodePropValue").getSingle());
assertEquals(rel, relIndex.get("relProp", "relPropValue").getSingle());
try {
nodeIndex.add(null, null, null);
fail("Auto indexes should not allow external manipulation");
} catch (UnsupportedOperationException e) {
// good
}
try {
relIndex.add(null, null, null);
fail("Auto indexes should not allow external manipulation");
} catch (UnsupportedOperationException e) {
// good
}
}
use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.
the class TestLuceneIndex method makeSureYouCanRemoveFromRelationshipIndex.
@Test
public void makeSureYouCanRemoveFromRelationshipIndex() {
Node n1 = graphDb.createNode();
Node n2 = graphDb.createNode();
Relationship r = n1.createRelationshipTo(n2, withName("foo"));
RelationshipIndex index = graphDb.index().forRelationships("rel-index");
String key = "bar";
index.remove(r, key, "value");
index.add(r, key, "otherValue");
for (int i = 0; i < 2; i++) {
assertThat(index.get(key, "value"), emptyIterable());
assertThat(index.get(key, "otherValue"), Contains.contains(r));
restartTx();
}
}
use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.
the class TestLuceneIndex method shouldNotBeAbleToAddNullValuesToRelationshipIndex.
@Test
public void shouldNotBeAbleToAddNullValuesToRelationshipIndex() throws Exception {
// GIVEN
RelationshipIndex index = relationshipIndex(EXACT_CONFIG);
// WHEN single null
try {
index.add(graphDb.createNode().createRelationshipTo(graphDb.createNode(), MyRelTypes.TEST), "key", null);
fail("Should have failed");
} catch (IllegalArgumentException e) {
// THEN Good
}
// WHEN null in array
try {
index.add(graphDb.createNode().createRelationshipTo(graphDb.createNode(), MyRelTypes.TEST), "key", new String[] { "a", null, "c" });
fail("Should have failed");
} catch (IllegalArgumentException e) {
// THEN Good
}
}
use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.
the class GraphDbHelper method createRelationshipIndex.
public Index<Relationship> createRelationshipIndex(String named) {
try (Transaction transaction = database.getGraph().beginTransaction(implicit, AUTH_DISABLED)) {
RelationshipIndex relationshipIndex = database.getGraph().index().forRelationships(named);
transaction.success();
return relationshipIndex;
}
}
use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j-mobile-android by neo4j-contrib.
the class DbWrapper method removeRelationshipFromIndex.
@Override
public void removeRelationshipFromIndex(String name, long relationshipId, ParcelableError err) throws RemoteException {
try {
checkCallerHasWritePermission();
resumeTrx();
try {
Relationship rel = mDb.getRelationshipById(relationshipId);
// this
RelationshipIndex index = mDb.index().forRelationships(name);
// will
// create
// the
// index
index.remove(rel);
} finally {
suspendCurrentTrx("removeRelationshipFromIndex");
}
} catch (Exception e) {
Log.e(TAG, "Failed to add relationship to index '" + name + "'", e);
err.setError(Errors.TRANSACTION, e.getMessage());
}
}
Aggregations