Java Code Examples for org.neo4j.driver.Transaction#run()

The following examples show how to use org.neo4j.driver.Transaction#run() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Neo4jOperationsIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@BeforeEach
void setupData() {

	Transaction transaction = driver.session(getSessionConfig()).beginTransaction();
	transaction.run("MATCH (n) detach delete n");

	person1Id = transaction.run("CREATE (n:PersonWithAllConstructor) SET n.name = $name RETURN id(n)",
		Values.parameters("name", TEST_PERSON1_NAME)
	).next().get(0).asLong();
	person2Id = transaction.run("CREATE (n:PersonWithAllConstructor) SET n.name = $name RETURN id(n)",
		Values.parameters("name", TEST_PERSON2_NAME)
	).next().get(0).asLong();

	transaction.commit();
	transaction.close();
}
 
Example 2
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Override
void setupData(Transaction transaction) {
	ZonedDateTime createdAt = LocalDateTime.of(2019, 1, 1, 23, 23, 42, 0).atZone(ZoneOffset.UTC.normalized());
	id1 = transaction.run("" +
			"CREATE (n:PersonWithAllConstructor) " +
			"  SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.nullable = 'something', n.things = ['a', 'b'], n.place = $place, n.createdAt = $createdAt "
			+
			"RETURN id(n)",
		Values.parameters("name", TEST_PERSON1_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON1_FIRST_NAME, "cool", true, "personNumber", 1, "bornOn", TEST_PERSON1_BORN_ON, "place",
			NEO4J_HQ, "createdAt", createdAt)
	).next().get(0).asLong();
	transaction
		.run("CREATE (a:Thing {theId: 'anId', name: 'Homer'})-[:Has]->(b:Thing2{theId: 4711, name: 'Bart'})");
	IntStream.rangeClosed(1, 20).forEach(i ->
		transaction.run("CREATE (a:Thing {theId: 'id' + $i, name: 'name' + $i})",
			Values.parameters("i", String.format("%02d", i))));

	person1 = new PersonWithAllConstructor(id1, TEST_PERSON1_NAME, TEST_PERSON1_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		true, 1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ, createdAt.toInstant());
}
 
Example 3
Source File: ReactiveNeo4jOperationsIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@BeforeEach
void setupData() {

	Transaction transaction = driver.session(getSessionConfig()).beginTransaction();
	transaction.run("MATCH (n) detach delete n");

	person1Id = transaction.run("CREATE (n:PersonWithAllConstructor) SET n.name = $name RETURN id(n)",
		Values.parameters("name", TEST_PERSON1_NAME)
	).next().get(0).asLong();
	person2Id = transaction.run("CREATE (n:PersonWithAllConstructor) SET n.name = $name RETURN id(n)",
		Values.parameters("name", TEST_PERSON2_NAME)
	).next().get(0).asLong();

	transaction.commit();
	transaction.close();
}
 
Example 4
Source File: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Override
void setupData(Transaction transaction) {

	transaction.run("MATCH (n) detach delete n");

	transaction.run("" + "CREATE (n:PersonWithAllConstructor) "
			+ "  SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.nullable = 'something', n.things = ['a', 'b'], n.place = $place "
			+ "RETURN id(n)",
		parameters("name", TEST_PERSON1_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON1_FIRST_NAME, "cool", true, "personNumber", 1, "bornOn", TEST_PERSON1_BORN_ON, "place",
			NEO4J_HQ))
		.next().get(0).asLong();

	transaction.run(
		"CREATE (n:PersonWithAllConstructor) SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.things = [], n.place = $place return id(n)",
		parameters("name", TEST_PERSON2_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON2_FIRST_NAME, "cool", false, "personNumber", 2, "bornOn", TEST_PERSON2_BORN_ON, "place",
			SFO))
		.next().get(0).asLong();
}
 
Example 5
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
void setupData(Transaction transaction) {
	ZonedDateTime createdAt = LocalDateTime.of(2019, 1, 1, 23, 23, 42, 0).atZone(ZoneOffset.UTC.normalized());
	id1 = transaction.run("" +
			"CREATE (n:PersonWithAllConstructor) " +
			"  SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.nullable = 'something', n.things = ['a', 'b'], n.place = $place, n.createdAt = $createdAt "
			+
			"RETURN id(n)",
		Values.parameters("name", TEST_PERSON1_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON1_FIRST_NAME, "cool", true, "personNumber", 1, "bornOn", TEST_PERSON1_BORN_ON, "place",
			NEO4J_HQ, "createdAt", createdAt)
	).next().get(0).asLong();
	id2 = transaction.run(
		"CREATE (n:PersonWithAllConstructor) SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.things = [], n.place = $place return id(n)",
		Values.parameters("name", TEST_PERSON2_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON2_FIRST_NAME, "cool", false, "personNumber", 2, "bornOn", TEST_PERSON2_BORN_ON, "place",
			SFO)
	).next().get(0).asLong();
	transaction.run("CREATE (n:PersonWithNoConstructor) SET n.name = $name, n.first_name = $firstName",
		Values.parameters("name", TEST_PERSON1_NAME, "firstName", TEST_PERSON1_FIRST_NAME));
	transaction.run("CREATE (n:PersonWithWither) SET n.name = '" + TEST_PERSON1_NAME + "'");
	transaction.run("CREATE (n:KotlinPerson) SET n.name = '" + TEST_PERSON1_NAME + "'");
	transaction
		.run("CREATE (a:Thing {theId: 'anId', name: 'Homer'})-[:Has]->(b:Thing2{theId: 4711, name: 'Bart'})");

	IntStream.rangeClosed(1, 20).forEach(i ->
		transaction.run("CREATE (a:Thing {theId: 'id' + $i, name: 'name' + $i})",
			Values.parameters("i", String.format("%02d", i))));

	person1 = new PersonWithAllConstructor(id1, TEST_PERSON1_NAME, TEST_PERSON1_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		true, 1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ, createdAt.toInstant());
	person2 = new PersonWithAllConstructor(id2, TEST_PERSON2_NAME, TEST_PERSON2_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		false, 2L, TEST_PERSON2_BORN_ON, null, emptyList(), SFO, null);
}
 
Example 6
Source File: ProjectionIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	Session session = driver.session();
	Transaction transaction = session.beginTransaction();

	transaction.run("MATCH (n) detach delete n");

	transaction.run("CREATE (:Person{firstName:'" + FIRST_NAME + "', lastName:'" + LAST_NAME + "'})"
		+ "-[:LIVES_AT]->"
		+ "(:Address{city:'" + CITY + "'})");

	transaction.commit();
	transaction.close();
	session.close();
}
 
Example 7
Source File: OptimisticLockingIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	Session session = driver.session(SessionConfig.defaultConfig());
	Transaction transaction = session.beginTransaction();
	transaction.run("MATCH (n) detach delete n");
	transaction.commit();
	session.close();
}
 
Example 8
Source File: ReactiveProjectionIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	Session session = driver.session();
	Transaction transaction = session.beginTransaction();

	transaction.run("MATCH (n) detach delete n");

	transaction.run("CREATE (:Person{firstName:'" + FIRST_NAME + "', lastName:'" + LAST_NAME + "'})"
		+ "-[:LIVES_AT]->"
		+ "(:Address{city:'" + CITY + "'})");

	transaction.commit();
	transaction.close();
	session.close();
}
 
Example 9
Source File: ReactiveOptimisticLockingIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {

	Session session = driver.session(SessionConfig.defaultConfig());
	Transaction transaction = session.beginTransaction();
	transaction.run("MATCH (n) detach delete n");
	transaction.commit();
	session.close();
}
 
Example 10
Source File: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
void setupData(Transaction transaction) {

	transaction.run("MATCH (n) detach delete n");

	id1 = transaction.run("" + "CREATE (n:PersonWithAllConstructor) "
			+ "  SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.nullable = 'something', n.things = ['a', 'b'], n.place = $place "
			+ "RETURN id(n)",
		parameters("name", TEST_PERSON1_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON1_FIRST_NAME, "cool", true, "personNumber", 1, "bornOn", TEST_PERSON1_BORN_ON, "place",
			NEO4J_HQ))
		.next().get(0).asLong();

	id2 = transaction.run(
		"CREATE (n:PersonWithAllConstructor) SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.things = [], n.place = $place return id(n)",
		parameters("name", TEST_PERSON2_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON2_FIRST_NAME, "cool", false, "personNumber", 2, "bornOn", TEST_PERSON2_BORN_ON, "place",
			SFO))
		.next().get(0).asLong();

	transaction
		.run("CREATE (a:Thing {theId: 'anId', name: 'Homer'})-[:Has]->(b:Thing2{theId: 4711, name: 'Bart'})");
	IntStream.rangeClosed(1, 20).forEach(i ->
		transaction.run("CREATE (a:Thing {theId: 'id' + $i, name: 'name' + $i})",
			parameters("i", String.format("%02d", i))));

	person1 = new PersonWithAllConstructor(id1, TEST_PERSON1_NAME, TEST_PERSON1_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		true,
		1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ, null);

	person2 = new PersonWithAllConstructor(id2, TEST_PERSON2_NAME, TEST_PERSON2_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		false, 2L, TEST_PERSON2_BORN_ON, null, Collections.emptyList(), SFO, null);
}
 
Example 11
Source File: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
void setupData(Transaction transaction) {

	transaction.run("MATCH (n) detach delete n");

	id1 = transaction.run("" + "CREATE (n:PersonWithAllConstructor) "
			+ "  SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.nullable = 'something', n.things = ['a', 'b'], n.place = $place "
			+ "RETURN id(n)",
		parameters("name", TEST_PERSON1_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON1_FIRST_NAME, "cool", true, "personNumber", 1, "bornOn", TEST_PERSON1_BORN_ON, "place",
			NEO4J_HQ))
		.next().get(0).asLong();

	id2 = transaction.run(
		"CREATE (n:PersonWithAllConstructor) SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.things = [], n.place = $place return id(n)",
		parameters("name", TEST_PERSON2_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON2_FIRST_NAME, "cool", false, "personNumber", 2, "bornOn", TEST_PERSON2_BORN_ON, "place",
			SFO))
		.next().get(0).asLong();

	transaction
		.run("CREATE (a:Thing {theId: 'anId', name: 'Homer'})-[:Has]->(b:Thing2{theId: 4711, name: 'Bart'})");
	IntStream.rangeClosed(1, 20).forEach(i ->
		transaction.run("CREATE (a:Thing {theId: 'id' + $i, name: 'name' + $i})",
			parameters("i", String.format("%02d", i))));

	person1 = new PersonWithAllConstructor(id1, TEST_PERSON1_NAME, TEST_PERSON1_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		true,
		1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ, null);

	person2 = new PersonWithAllConstructor(id2, TEST_PERSON2_NAME, TEST_PERSON2_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		false, 2L, TEST_PERSON2_BORN_ON, null, Collections.emptyList(), SFO, null);
}
 
Example 12
Source File: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
void setupData(Transaction transaction) {

	transaction.run("MATCH (n) detach delete n");

	id1 = transaction.run("" + "CREATE (n:PersonWithAllConstructor) "
			+ "  SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.nullable = 'something', n.things = ['a', 'b'], n.place = $place "
			+ "RETURN id(n)",
		parameters("name", TEST_PERSON1_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON1_FIRST_NAME, "cool", true, "personNumber", 1, "bornOn", TEST_PERSON1_BORN_ON, "place",
			NEO4J_HQ))
		.next().get(0).asLong();

	id2 = transaction.run(
		"CREATE (n:PersonWithAllConstructor) SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.things = [], n.place = $place return id(n)",
		parameters("name", TEST_PERSON2_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON2_FIRST_NAME, "cool", false, "personNumber", 2, "bornOn", TEST_PERSON2_BORN_ON, "place",
			SFO))
		.next().get(0).asLong();

	transaction
		.run("CREATE (a:Thing {theId: 'anId', name: 'Homer'})-[:Has]->(b:Thing2{theId: 4711, name: 'Bart'})");
	IntStream.rangeClosed(1, 20).forEach(i ->
		transaction.run("CREATE (a:Thing {theId: 'id' + $i, name: 'name' + $i})",
			parameters("i", String.format("%02d", i))));

	person1 = new PersonWithAllConstructor(id1, TEST_PERSON1_NAME, TEST_PERSON1_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		true,
		1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ, null);

	person2 = new PersonWithAllConstructor(id2, TEST_PERSON2_NAME, TEST_PERSON2_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		false, 2L, TEST_PERSON2_BORN_ON, null, Collections.emptyList(), SFO, null);
}
 
Example 13
Source File: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
void setupData(Transaction transaction) {

	transaction.run("MATCH (n) detach delete n");

	id1 = transaction.run("" + "CREATE (n:PersonWithAllConstructor) "
			+ "  SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.nullable = 'something', n.things = ['a', 'b'], n.place = $place "
			+ "RETURN id(n)",
		parameters("name", TEST_PERSON1_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON1_FIRST_NAME, "cool", true, "personNumber", 1, "bornOn", TEST_PERSON1_BORN_ON, "place",
			NEO4J_HQ))
		.next().get(0).asLong();

	id2 = transaction.run(
		"CREATE (n:PersonWithAllConstructor) SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.things = [], n.place = $place return id(n)",
		parameters("name", TEST_PERSON2_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName",
			TEST_PERSON2_FIRST_NAME, "cool", false, "personNumber", 2, "bornOn", TEST_PERSON2_BORN_ON, "place",
			SFO))
		.next().get(0).asLong();

	person1 = new PersonWithAllConstructor(id1, TEST_PERSON1_NAME, TEST_PERSON1_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		true,
		1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ, null);

	person2 = new PersonWithAllConstructor(id2, TEST_PERSON2_NAME, TEST_PERSON2_FIRST_NAME,
		TEST_PERSON_SAMEVALUE,
		false, 2L, TEST_PERSON2_BORN_ON, null, Collections.emptyList(), SFO, null);
}
 
Example 14
Source File: CypherTransactionWork.java    From knowbi-pentaho-pdi-neo4j-output with Apache License 2.0 5 votes vote down vote up
@Override public Void execute( Transaction tx ) {
  Result result = tx.run( cypher, unwindMap );
  try {
    step.getResultRows( result, currentRow, unwind );
    return null;
  } catch ( KettleException e ) {
    throw new RuntimeException( "Unable to execute cypher statement '"+cypher+"'", e );
  }
}
 
Example 15
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 4 votes vote down vote up
@Override
void setupData(Transaction transaction) {
	transaction.run("CREATE (:PersonWithAllConstructor{name: '" + TEST_PERSON1_NAME + "', first_name: '" + TEST_PERSON1_FIRST_NAME + "'}),"
		+ " (:PersonWithAllConstructor{name: '" + TEST_PERSON2_NAME + "'})");
}
 
Example 16
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 4 votes vote down vote up
@Override void setupData(Transaction transaction) {
	transaction.run("CREATE (:CustomTypes{customType:'XYZ'})");
}