/** * Effectively: * * <pre><code> * return single( db.findNodesByLabelAndProperty( label, property, value ), null ); * </code></pre> */ private Node lookUpNode( Object value ) { return db.findNode( label, property, value ); }
@Test public void shouldDisableLegacyStyleQuotingIfToldTo() throws Exception { // GIVEN String nodeId = "me"; String labelName = "Alive"; List<String> lines = new ArrayList<>(); lines.add( ":ID,name,:LABEL" ); lines.add( nodeId + "," + "\"abc\"\"def\\\"\"ghi\"" + "," + labelName ); // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", data( lines.toArray( new String[lines.size()] ) ).getAbsolutePath(), "--legacy-style-quoting", "false", "--stacktrace" ); // THEN GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction tx = db.beginTx() ) { assertNotNull( db.findNode( label( labelName ), "name", "abc\"def\\\"ghi" ) ); } }
private void assertCanCreateAndFind( GraphDatabaseService db, Label label, String propertyKey, Object value ) { Node created = createNode( db, map( propertyKey, value ), label ); try ( Transaction tx = db.beginTx() ) { Node found = db.findNode( label, propertyKey, value ); assertThat( found, equalTo( created ) ); found.delete(); tx.success(); } }
@Test public void shouldThrowWhenMultipleResultsForSingleNode() { // given GraphDatabaseService graph = dbRule.getGraphDatabaseAPI(); Neo4jMatchers.createIndex( graph, LABEL1, "name" ); Node node1; Node node2; try ( Transaction tx = graph.beginTx() ) { node1 = graph.createNode( LABEL1 ); node1.setProperty( "name", "Stefan" ); node2 = graph.createNode( LABEL1 ); node2.setProperty( "name", "Stefan" ); tx.success(); } try ( Transaction tx = graph.beginTx() ) { graph.findNode( LABEL1, "name", "Stefan" ); fail( "Expected MultipleFoundException but got none" ); } catch ( MultipleFoundException e ) { assertThat( e.getMessage(), equalTo( format( "Found multiple nodes with label: '%s', property name: 'name' " + "and property value: 'Stefan' while only one was expected.", LABEL1 ) ) ); } }
@Test void createPointPropertyOnLatestDatabase() { File storeDir = testDirectory.storeDir(); Label pointNode = Label.label( "PointNode" ); String propertyKey = "a"; PointValue pointValue = pointValue( Cartesian, 1.0, 2.0 ); GraphDatabaseService database = startDatabaseWithFormat( storeDir, Standard.LATEST_NAME ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( pointNode ); node.setProperty( propertyKey, pointValue ); transaction.success(); } database.shutdown(); GraphDatabaseService restartedDatabase = startDatabaseWithFormat( storeDir, Standard.LATEST_NAME ); try ( Transaction ignored = restartedDatabase.beginTx() ) { assertNotNull( restartedDatabase.findNode( pointNode, propertyKey, pointValue ) ); } restartedDatabase.shutdown(); }
@Test void createDatePropertyOnLatestDatabase() { File storeDir = testDirectory.storeDir(); Label label = Label.label( "DateNode" ); String propertyKey = "a"; LocalDate date = DateValue.date( 1991, 5, 3 ).asObjectCopy(); GraphDatabaseService database = startDatabaseWithFormat( storeDir, Standard.LATEST_NAME ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( label ); node.setProperty( propertyKey, date ); transaction.success(); } database.shutdown(); GraphDatabaseService restartedDatabase = startDatabaseWithFormat( storeDir, Standard.LATEST_NAME ); try ( Transaction ignored = restartedDatabase.beginTx() ) { assertNotNull( restartedDatabase.findNode( label, propertyKey, date ) ); } restartedDatabase.shutdown(); }
Node node = db.findNode( label, "indexed", "value" ); assertThat( node.getProperty( "random" ), is( 42 ) );
Node node = db.findNode( label, "indexed", "value" ); assertThat( node.getProperty( "random" ), is( 42 ) );
db.findNode( label, property, "" + i ).delete(); tx.success();
@Override public Node call() { Node node = graphdb.findNode(RESOURCE, "uri", entry.getKey()); if (node==null){ node = graphdb.createNode(RESOURCE); node.setProperty("uri",entry.getKey()); } return node; } });
@Override public Node call() { //throws AnyException return graphdb.findNode(RESOURCE, "uri", st.getSubject().stringValue()); } });
@Override public Node call() { //throws AnyException return graphdb.findNode(RESOURCE, "uri", st.getObject().stringValue()); } });
public Optional<Node> getNode(String id, Optional<String> lblHint) { String iriResolved = curieUtil.getIri(id).orElse(id); Optional<Node> node = Optional.empty(); if (lblHint.isPresent()) { Label hintLabel = Label.label(lblHint.get()); Node hit = graphDb.findNode(hintLabel, NodeProperties.IRI, iriResolved); if (hit != null) { node = Optional.of(hit); } } else { String startQuery = "MATCH (n {" + NodeProperties.IRI + ": \"" + iriResolved + "\"}) RETURN n"; Result res = cypherUtil.execute(startQuery); if (res.hasNext()) { node = Optional.of((Node) res.next().get("n")); } } return node; }
private Node getPhraseNode(Phrase phrase) { return database.findNode(configuration().getLabelFor(Labels.Phrase), configuration().getPropertyKeyFor(Properties.CONTENT_VALUE), phrase.getContent() ); }
private static void assertUserExistsUniquelyInGraphDb( GraphDatabaseService graph, Transaction tx, String username ) { Label label = Label.label( "User" ); Node result = graph.findNode( label, "name", username ); assertNotNull( format( "User '%s' not created.", username ), result ); tx.success(); } }
final Node swtch = db.findNode(Labels.Switch, attrubute, name); if (swtch != null) { TraversalDescription td = db.traversalDescription().depthFirst()
GraphDatabaseService database = getDatabase(); Node rootProduct = database.findNode(DynamicLabel.label("Product"), "id", 1);