Refine search
/** * Create a new {@link UniqueFactory} for nodes. * * @param graphdb the graph database to get the index from. * @param index the name of the index to store entities uniquely in. */ @Deprecated public UniqueNodeFactory( GraphDatabaseService graphdb, String index ) { super( graphdb.index().forNodes( index ) ); }
private static void createRelationshipExplicitIndexWithSingleRelationship( GraphDatabaseService db, String indexName ) { try ( Transaction tx = db.beginTx() ) { Relationship relationship = db.createNode().createRelationshipTo( db.createNode(), TYPE ); Index<Relationship> relationshipIndexIndex = db.index().forRelationships( indexName ); relationshipIndexIndex.add( relationship, "key", System.currentTimeMillis() ); tx.success(); } }
private static void createNodeExplicitIndexWithSingleNode( GraphDatabaseService db, String indexName ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.add( node, "key", System.currentTimeMillis() ); tx.success(); } }
@Test public void shouldCreateExplicitNodeIndexEagerly() throws Exception { // When try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); HashMap<String,String> config = new HashMap<>(); config.put( "type", "exact" ); config.put( "provider", "lucene" ); indexWrite.nodeExplicitIndexCreate( INDEX_NAME, config ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) { assertTrue( graphDb.index().existsForNodes( INDEX_NAME ) ); ctx.success(); } }
private Map<String,Map<String,Serializable>> checkIndex( GraphDatabaseService db ) { Map<String,Map<String,Serializable>> result = new HashMap<>(); for ( String indexName : db.index().nodeIndexNames() ) { Map<String,Serializable> thisIndex = new HashMap<>(); Index<Node> tempIndex = db.index().forNodes( indexName ); for ( Map.Entry<String,Serializable> property : properties.props.entrySet() ) { try ( IndexHits<Node> content = tempIndex.get( property.getKey(), property.getValue() ) ) { if ( content.hasNext() ) { for ( Node hit : content ) { if ( hit.getId() == id ) { thisIndex.put( property.getKey(), property.getValue() ); break; } } } } } result.put( indexName, thisIndex ); } return result; }
private void assertNodeIsIndexed( final Node commonNode ) throws Exception { final Collection<Exception> problems = new HashSet<>(); Thread thread = new Thread( () -> { try ( Transaction ignored = graphDatabaseService.beginTx() ) { Node node = graphDatabaseService.index().forNodes( INDEX_NAME ).get( INDEX_KEY, INDEX_VALUE ) .getSingle(); assertThat( node, is( commonNode ) ); } catch ( Throwable t ) { problems.add( new Exception( t ) ); } } ); thread.start(); thread.join(); if ( problems.size() > 0 ) { throw problems.iterator().next(); } }
@Test public void shouldCreateExplicitRelationshipIndexEagerly() throws Exception { // When try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); HashMap<String,String> config = new HashMap<>(); config.put( "type", "exact" ); config.put( "provider", "lucene" ); indexWrite.relationshipExplicitIndexCreate( INDEX_NAME, config ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) { assertTrue( graphDb.index().existsForRelationships( INDEX_NAME ) ); ctx.success(); } }
@Test public void makeSureYouCanAskIfAnIndexExistsOrNot() { String name = currentIndexName(); assertFalse( graphDb.index().existsForNodes( name ) ); graphDb.index().forNodes( name ); assertTrue( graphDb.index().existsForNodes( name ) ); assertFalse( graphDb.index().existsForRelationships( name ) ); graphDb.index().forRelationships( name ); assertTrue( graphDb.index().existsForRelationships( name ) ); }
private void assertNodeIsNotIndexedOutsideThisTransaction() throws Exception { final Collection<Exception> problems = new HashSet<>(); Thread thread = new Thread( () -> { try ( Transaction ignored = graphDatabaseService.beginTx(); IndexHits<Node> indexHits = graphDatabaseService.index() .forNodes( INDEX_NAME ).get( INDEX_KEY, INDEX_VALUE ) ) { assertThat( indexHits.size(), is( 0 ) ); } catch ( Throwable t ) { problems.add( new Exception( t ) ); } } ); thread.start(); thread.join(); if ( problems.size() > 0 ) { throw problems.iterator().next(); } }
@Test public void shouldCreateExplicitRelationshipIndexLazily() throws Exception { // When try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); HashMap<String,String> config = new HashMap<>(); config.put( "type", "exact" ); config.put( "provider", "lucene" ); indexWrite.relationshipExplicitIndexCreateLazily( INDEX_NAME, config ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) { assertTrue( graphDb.index().existsForRelationships( INDEX_NAME ) ); ctx.success(); } }
@Before public void createInitialData() { beginTx(); index = graphDb.index().forNodes( INDEX_NAME ); index.delete(); restartTx(); index = graphDb.index().forNodes( INDEX_NAME ); key = "key"; value = "my own value"; node = graphDb.createNode(); index.add( node, key, value ); workers = new ArrayList<>(); }
@Test public void shouldCreateExplicitNodeIndexLazily() throws Exception { // When try ( Transaction tx = beginTransaction() ) { ExplicitIndexWrite indexWrite = tx.indexWrite(); HashMap<String,String> config = new HashMap<>(); config.put( "type", "exact" ); config.put( "provider", "lucene" ); indexWrite.nodeExplicitIndexCreateLazily( INDEX_NAME, config ); tx.success(); } // Then try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) { assertTrue( graphDb.index().existsForNodes( INDEX_NAME ) ); ctx.success(); } }