public Representation getAutoIndexedRelationships( String key, String value ) { final ReadableIndex<Relationship> index = graphDb.index().getRelationshipAutoIndexer().getAutoIndex(); return toListRelationshipRepresentation( index.get( key, value ), null ); }
@Test public void testConfigAndAPICompatibility() { stopDb(); config = new HashMap<>(); config.put( GraphDatabaseSettings.node_keys_indexable.name(), "nodeProp1, nodeProp2" ); config.put( GraphDatabaseSettings.relationship_keys_indexable.name(), "relProp1, relProp2" ); config.put( GraphDatabaseSettings.node_auto_indexing.name(), "true" ); config.put( GraphDatabaseSettings.relationship_auto_indexing.name(), "true" ); startDb(); newTransaction(); assertTrue( graphDb.index().getNodeAutoIndexer().isEnabled() ); assertTrue( graphDb.index().getRelationshipAutoIndexer().isEnabled() ); AutoIndexer<Node> autoNodeIndexer = graphDb.index().getNodeAutoIndexer(); // Start auto indexing a new and an already auto indexed autoNodeIndexer.startAutoIndexingProperty( "nodeProp1" ); autoNodeIndexer.startAutoIndexingProperty( "nodeProp3" ); assertEquals( 3, autoNodeIndexer.getAutoIndexedProperties().size() ); assertTrue( autoNodeIndexer.getAutoIndexedProperties().contains( "nodeProp1" ) ); assertTrue( autoNodeIndexer.getAutoIndexedProperties().contains( "nodeProp2" ) ); assertTrue( autoNodeIndexer.getAutoIndexedProperties().contains( "nodeProp3" ) ); }
for ( String k : indexManager.getRelationshipAutoIndexer().getAutoIndexedProperties() ) indexManager.getRelationshipAutoIndexer().stopAutoIndexingProperty( k ); indexManager.getRelationshipAutoIndexer().setEnabled( false );
@Test @Graph( nodes = { @NODE( name = "I", properties = { @PROP( key = "name", value = "me" ), @PROP( key = "bool", value = "true", type = GraphDescription.PropType.BOOLEAN ) } ), @NODE( name = "you", setNameProperty = true ) }, relationships = { @REL( start = "I", end = "you", type = "knows", properties = { @PROP( key = "name", value = "relProp" ), @PROP( key = "valid", value = "true", type = GraphDescription.PropType.BOOLEAN ) } ) }, autoIndexRelationships = true ) public void canCreateMoreInvolvedGraphWithPropertiesAndAutoIndex() { data.get(); verifyIKnowYou( "knows", "me" ); try ( Transaction ignored = graphdb.beginTx() ) { assertEquals( true, data.get().get( "I" ).getProperty( "bool" ) ); assertFalse( "node autoindex enabled.", graphdb().index().getNodeAutoIndexer().isEnabled() ); try ( IndexHits<Relationship> relationships = graphdb().index() .getRelationshipAutoIndexer().getAutoIndex().get( "name", "relProp" ) ) { assertTrue( "can't look up rel.", relationships.hasNext() ); } assertTrue( "relationship autoindex enabled.", graphdb().index().getRelationshipAutoIndexer().isEnabled() ); } }
public <T extends Element> void createKeyIndex(final String key, final Class<T> elementClass, final Parameter... indexParameters) { if (elementClass == null) throw ExceptionFactory.classForElementCannotBeNull(); if (Vertex.class.isAssignableFrom(elementClass)) { this.autoStartTransaction(true); if (!this.rawGraph.index().getNodeAutoIndexer().isEnabled()) this.rawGraph.index().getNodeAutoIndexer().setEnabled(true); this.rawGraph.index().getNodeAutoIndexer().startAutoIndexingProperty(key); if (!this.getInternalIndexKeys(Vertex.class).contains(key)) { KeyIndexableGraphHelper.reIndexElements(this, this.getVertices(), new HashSet<String>(Arrays.asList(key))); this.autoStartTransaction(true); this.createInternalIndexKey(key, elementClass); } } else if (Edge.class.isAssignableFrom(elementClass)) { this.autoStartTransaction(true); if (!this.rawGraph.index().getRelationshipAutoIndexer().isEnabled()) this.rawGraph.index().getRelationshipAutoIndexer().setEnabled(true); this.rawGraph.index().getRelationshipAutoIndexer().startAutoIndexingProperty(key); if (!this.getInternalIndexKeys(Edge.class).contains(key)) { KeyIndexableGraphHelper.reIndexElements(this, this.getEdges(), new HashSet<String>(Arrays.asList(key))); this.autoStartTransaction(true); this.createInternalIndexKey(key, elementClass); } } else { throw ExceptionFactory.classIsNotIndexable(elementClass); } }
@Before public void startDb() { graphDb = (GraphDatabaseAPI) new TestGraphDatabaseFactory(). newImpermanentDatabaseBuilder().setConfig(new HashMap<>()).newGraphDatabase(); try ( Transaction tx = graphDb.beginTx() ) { // 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( "type"); tx.success(); } try ( Transaction tx = graphDb.beginTx() ) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); Node node3 = graphDb.createNode(); id1 = node1.getId(); id2 = node2.getId(); id3 = node3.getId(); Relationship rel = node1.createRelationshipTo(node2, RelationshipType.withName("FOO")); rel.setProperty("type", "FOO"); tx.success(); } }
public <T extends Element> Set<String> getIndexedKeys(final Class<T> elementClass) { if (elementClass == null) throw ExceptionFactory.classForElementCannotBeNull(); if (Vertex.class.isAssignableFrom(elementClass)) { if (!this.rawGraph.index().getNodeAutoIndexer().isEnabled()) return Collections.emptySet(); return this.rawGraph.index().getNodeAutoIndexer().getAutoIndexedProperties(); } else if (Edge.class.isAssignableFrom(elementClass)) { if (!this.rawGraph.index().getRelationshipAutoIndexer().isEnabled()) return Collections.emptySet(); return this.rawGraph.index().getRelationshipAutoIndexer().getAutoIndexedProperties(); } else { throw ExceptionFactory.classIsNotIndexable(elementClass); } }
public <T extends Element> void dropKeyIndex(final String key, final Class<T> elementClass) { if (elementClass == null) throw ExceptionFactory.classForElementCannotBeNull(); this.autoStartTransaction(true); if (Vertex.class.isAssignableFrom(elementClass)) { if (!this.rawGraph.index().getNodeAutoIndexer().isEnabled()) return; this.rawGraph.index().getNodeAutoIndexer().stopAutoIndexingProperty(key); } else if (Edge.class.isAssignableFrom(elementClass)) { if (!this.rawGraph.index().getRelationshipAutoIndexer().isEnabled()) return; this.rawGraph.index().getRelationshipAutoIndexer().stopAutoIndexingProperty(key); } else { throw ExceptionFactory.classIsNotIndexable(elementClass); } this.dropInternalIndexKey(key, elementClass); }
@Override public Map<String, Node> create( GraphDatabaseService graphdb ) { Map<String, Node> result = new HashMap<>(); try ( Transaction tx = graphdb.beginTx() ) { graphdb.index().getRelationshipAutoIndexer().setEnabled( autoIndexRelationships ); for ( NODE def : nodes ) { Node node = init( graphdb.createNode(), def.setNameProperty() ? def.name() : null, def.properties(), graphdb.index().getNodeAutoIndexer(), autoIndexNodes ); for ( LABEL label : def.labels() ) { node.addLabel( label( label.value() ) ); } result.put( def.name(), node ); } for ( REL def : rels ) { init( result.get( def.start() ).createRelationshipTo( result.get( def.end() ), RelationshipType.withName( def.type() ) ), def.setNameProperty() ? def.name() : null, def.properties(), graphdb.index().getRelationshipAutoIndexer(), autoIndexRelationships ); } tx.success(); } return result; }
public Set<String> getRelationsipIndexedProperties(GraphDatabaseService graphDb) { return graphDb.index().getRelationshipAutoIndexer().getAutoIndexedProperties(); }
graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty( "nodeProp" ); graphDb.index().getRelationshipAutoIndexer().setEnabled( true ); graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty( "relProp" );
public Set<String> getRelationsipIndexedProperties(GraphDatabaseService graphDb) { return graphDb.index().getRelationshipAutoIndexer().getAutoIndexedProperties(); }
public ListRepresentation getAutoIndexedRelationshipsByQuery( String query ) { final ReadableIndex<Relationship> index = graphDb.index().getRelationshipAutoIndexer().getAutoIndex(); final IndexHits<Relationship> results = query != null ? index.query( query ) : null; return toListRelationshipRepresentation( results, null ); }
public boolean isRelationshipAutoIndexingEnabled(GraphDatabaseService graphDb) { return graphDb.index().getRelationshipAutoIndexer().isEnabled(); }
private ReadableRelationshipIndex relationShipAutoIndex() { return graphDb.index().getRelationshipAutoIndexer().getAutoIndex(); }
assertTrue( graphDb.index().getRelationshipAutoIndexer().isEnabled() );
@Test public void testDefaultsAreSeparateForNodesAndRelationships() { stopDb(); config = new HashMap<>(); config.put( GraphDatabaseSettings.node_keys_indexable.name(), "propName" ); config.put( GraphDatabaseSettings.node_auto_indexing.name(), "true" ); // Now only node properties named propName should be indexed. startDb(); newTransaction(); Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); node1.setProperty( "propName", "node1" ); node2.setProperty( "propName", "node2" ); node2.setProperty( "propName_", "node2" ); Relationship rel = node1.createRelationshipTo( node2, RelationshipType.withName( "DYNAMIC" ) ); rel.setProperty( "propName", "rel1" ); newTransaction(); ReadableIndex<Node> autoIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex(); assertEquals( node1, autoIndex.get( "propName", "node1" ).getSingle() ); assertEquals( node2, autoIndex.get( "propName", "node2" ).getSingle() ); assertFalse( graphDb.index().getRelationshipAutoIndexer().getAutoIndex().get( "propName", "rel1" ).hasNext() ); }
public boolean isRelationshipAutoIndexingEnabled(GraphDatabaseService graphDb) { return graphDb.index().getRelationshipAutoIndexer().isEnabled(); }
db.index().getRelationshipAutoIndexer().getAutoIndex(); Node start = db.getNodeById( startId ); Node end = db.getNodeById( endId ); assertEquals( 1, hits.size() ); rel.delete(); autoRelationshipIndex = db.index().getRelationshipAutoIndexer().getAutoIndex(); hits = autoRelationshipIndex.get( "Type", type.name(), start, end ); assertEquals( 0, count( hits ) );
/** * It is not allowed to add items manually to automatic indexes. */ @Test @Graph( nodes = {@NODE( name = "I" ), @NODE( name = "you" )}, relationships = {@REL( start = "I", end = "you", type = "know", properties = {@PROP( key = "since", value = "today" )} )}, autoIndexRelationships = true ) public void items_can_not_be_added_manually_to_a_Relationship_AutoIndex() { data.get(); String indexName; try ( Transaction tx = graphdb().beginTx() ) { indexName = graphdb().index().getRelationshipAutoIndexer().getAutoIndex().getName(); tx.success(); } try ( Transaction tx = graphdb().beginTx() ) { ResourceIterable<Relationship> relationships = (ResourceIterable<Relationship>) data.get().get( "I" ).getRelationships(); try ( ResourceIterator<Relationship> resourceIterator = relationships.iterator() ) { gen.get().expectedStatus( 405 ) .payload( createJsonStringFor( getRelationshipUri( resourceIterator.next() ), "name", "I" ) ) .post( postRelationshipIndexUri( indexName ) ).entity(); } } }