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 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(); } }
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(); } }
@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<>(); }
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 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 ) ); }
@Test public void makeSureIndexNamesCanBeRead() { beginTx(); assertEquals( 0, graphDb.index().nodeIndexNames().length ); String name1 = "my-index-1"; Index<Node> nodeIndex1 = graphDb.index().forNodes( name1 ); assertContains( Arrays.asList( graphDb.index().nodeIndexNames() ), name1 ); String name2 = "my-index-2"; graphDb.index().forNodes( name2 ); assertContains( Arrays.asList( graphDb.index().nodeIndexNames() ), name1, name2 ); graphDb.index().forRelationships( name1 ); assertContains( Arrays.asList( graphDb.index().nodeIndexNames() ), name1, name2 ); assertContains( Arrays.asList( graphDb.index().relationshipIndexNames() ), name1 ); finishTx( true ); restartTx(); assertContains( Arrays.asList( graphDb.index().nodeIndexNames() ), name1, name2 ); assertContains( Arrays.asList( graphDb.index().relationshipIndexNames() ), name1 ); nodeIndex1.delete(); assertContains( Arrays.asList( graphDb.index().nodeIndexNames() ), name1, name2 ); assertContains( Arrays.asList( graphDb.index().relationshipIndexNames() ), name1 ); finishTx( true ); beginTx(); assertContains( Arrays.asList( graphDb.index().nodeIndexNames() ), name2 ); assertContains( Arrays.asList( graphDb.index().relationshipIndexNames() ), name1 ); finishTx( false ); } }
@Override public void run() { while ( !start.get() ) { // spin } sleep(); try ( Transaction tx = db.beginTx() ) { // it is acceptable to either see a node with correct property or not see it at all Node node = db.index().forNodes( INDEX_NAME ).get( propertyKey, propertyValue ).getSingle(); if ( node != null ) { assertEquals( propertyValue, node.getProperty( propertyKey ) ); } tx.success(); } }
@Override public void createTestGraph( GraphDatabaseService graphDb ) { try ( Transaction tx = graphDb.beginTx() ) { graphDb.index().forNodes( "foo" ).add( graphDb.createNode(), "bar", "this is it" ); Relationship edge = graphDb.createNode().createRelationshipTo( graphDb.createNode(), withName( "LALA" ) ); graphDb.index().forRelationships( "rels" ).add( edge, "alpha", "betting on the wrong string" ); tx.success(); } }
@Test void validateExplicitIndexedNodeProperties() { setUp(); Label label = Label.label( "explicitIndexedNodePropertiesTestLabel" ); String propertyName = "explicitIndexedNodeProperties"; String explicitIndexedNodeIndex = "explicitIndexedNodeIndex"; try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( label ); database.index().forNodes( explicitIndexedNodeIndex ) .add( node, propertyName, "shortString" ); transaction.success(); } IllegalArgumentException argumentException = assertThrows( IllegalArgumentException.class, () -> { try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( label ); String longValue = StringUtils.repeat( "a", IndexWriter.MAX_TERM_LENGTH + 1 ); database.index().forNodes( explicitIndexedNodeIndex ).add( node, propertyName, longValue ); transaction.success(); } } ); assertEquals( "Property value size is too large for index. Please see index documentation for limitations.", argumentException.getMessage() ); }