private static Node createNode( GraphDatabaseService db, String propertyKey, Object value ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( label( LABEL ) ); node.setProperty( propertyKey, value ); tx.success(); return node; } }
private void createIndex() { try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { graphDb.schema().indexFor( Label.label( "Node" ) ).on( "prop" ).create(); tx.success(); } try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { graphDb.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); } }
@Test public void mustBeAbleToConsistencyCheckNodeIndexWithMultipleLabelsAndOneProperty() throws Exception { GraphDatabaseService db = createDatabase(); try ( Transaction tx = db.beginTx() ) { db.execute( format( NODE_CREATE, "nodes", array( "L1", "L2" ), array( "prop" ) ) ).close(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); db.createNode( Label.label( "L1" ), Label.label( "L2" ) ).setProperty( "prop", "value" ); db.createNode( Label.label( "L2" ) ).setProperty( "prop", "value" ); db.createNode( Label.label( "L1" ) ).setProperty( "prop", "value" ); tx.success(); } db.shutdown(); assertIsConsistent( checkConsistency() ); }
private void addConstraints( String... labelProps ) { assert labelProps.length % 2 == 0; try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { for ( int i = 0; i < labelProps.length; i += 2 ) { graphDb.schema().constraintFor( label( labelProps[i] ) ).assertPropertyIsUnique( labelProps[i + 1] ) .create(); } tx.success(); } } }
@Test public void shouldNotWarnOnSmallLabelScansWithLoadCVS() { try ( Transaction tx = db().beginTx() ) { db().createNode().addLabel( label( "A" ) ); tx.success(); } Stream.of( "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> { shouldNotNotifyInStream( version, "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MATCH (a:A) RETURN *" ); shouldNotNotifyInStream( version, "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MERGE (a:A) RETURN *" ); } ); }
@Before public void prepDB() { try ( Transaction transaction = db.beginTx() ) { node1 = db.createNode( label( "hej" ), label( "ha" ), label( "he" ) ); node1.setProperty( "hej", "value" ); node1.setProperty( "ha", "value1" ); node1.setProperty( "he", "value2" ); node1.setProperty( "ho", "value3" ); node1.setProperty( "hi", "value4" ); node2 = db.createNode(); Relationship rel = node1.createRelationshipTo( node2, RelationshipType.withName( "hej" ) ); rel.setProperty( "hej", "valuuu" ); rel.setProperty( "ha", "value1" ); rel.setProperty( "he", "value2" ); rel.setProperty( "ho", "value3" ); rel.setProperty( "hi", "value4" ); transaction.success(); } }
private long nodeWithWhatever( GraphDatabaseService graphDb, Object value ) { Node node = graphDb.createNode( label( "What" ) ); node.setProperty( "ever", value ); return node.getId(); }
private static void generateTransaction( GraphDatabaseAPI database ) { try ( Transaction transaction = database.beginTx() ) { Node startNode = database.createNode( Label.label( "startNode" ) ); startNode.setProperty( "key", "value" ); Node endNode = database.createNode( Label.label( "endNode" ) ); endNode.setProperty( "key", "value" ); startNode.createRelationshipTo( endNode, RelationshipType.withName( "connects" ) ); transaction.success(); } }
@Test public void lookupWithinTransactionWithCacheEviction() { try ( Transaction tx = db.beginTx() ) { // when db.createNode( label( "Node" ) ).setProperty( "prop", store ); // then assertEquals( 1, count( db.findNodes( label( "Node" ), "prop", lookup ) ) ); // no need to actually commit this node } }
private long createTheThirdNode() { long secondNodeId; try ( Transaction transaction = db.beginTx() ) { Node hej = db.createNode( label( "hej" ) ); secondNodeId = hej.getId(); hej.setProperty( "hej", "villa" ); hej.setProperty( "ho", "value3" ); transaction.success(); } return secondNodeId; }
private static void shouldHaveUniquenessConstraintForNamePropertyOnPersonLabel( GraphDatabaseService db ) { try ( Transaction tx = db.beginTx() ) { ConstraintDefinition constraint = Iterables.single( db.schema().getConstraints() ); assertEquals( ConstraintType.UNIQUENESS, constraint.getConstraintType() ); assertEquals( "Person", constraint.getLabel().name() ); assertEquals( "name", Iterables.single( constraint.getPropertyKeys() ) ); tx.success(); } }
private static void createIndex( GraphDatabaseAPI db, String labelName, String property ) { try ( Transaction tx = db.beginTx() ) { db.schema().indexFor( label( labelName ) ).on( property ).create(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); tx.success(); } }
private void assertLabels( long nodeId, String label ) { try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertThat( graphDb.getNodeById( nodeId ).getLabels(), containsInAnyOrder( label( label ) ) ); } }
@Test public void testSingleNodeLabels() { Node n = gdb.createNode(); n.addLabel( Label.label( "Foo" ) ); n.addLabel( Label.label( "Bar" ) ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + ":`Foo`:`Bar`)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
public IndexDefinition createSchemaIndex( String labelName, String propertyKey ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AUTH_DISABLED ) ) { IndexDefinition index = database.getGraph().schema().indexFor( label( labelName ) ).on( propertyKey ).create(); tx.success(); return index; } }
@Test @Graph( { "a:Person EATS b:Banana", "a EATS b:Apple" } ) public void ensurePeopleCanEatBananasAndApples() { Map<String,Node> graph = data.get(); Node a = graph.get( "a" ); Node b = graph.get( "b" ); try ( Transaction ignored = graphdb.beginTx() ) { assertTrue( "Person label missing", a.hasLabel( label( "Person" ) ) ); assertTrue( "Banana label missing", b.hasLabel( label( "Banana" ) ) ); assertTrue( "Apple label missing", b.hasLabel( label( "Apple" ) ) ); } }
private int labelId( Label alien ) { ThreadToStatementContextBridge contextBridge = ((GraphDatabaseAPI) db).getDependencyResolver() .resolveDependency( ThreadToStatementContextBridge.class ); try ( Transaction tx = db.beginTx() ) { return contextBridge.getKernelTransactionBoundToThisThread( true ) .tokenRead().nodeLabel( alien.name() ); } }