org.neo4j.driver.Transaction Java Examples

The following examples show how to use org.neo4j.driver.Transaction. 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: DynamicRelationshipsITBase.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@BeforeEach
protected void setupData() {
	try (
		Session session = driver.session();
		Transaction transaction = session.beginTransaction()
	) {
		transaction.run("MATCH (n) detach delete n");
		idOfExistingPerson = transaction.run(""
			+ "CREATE (t:" + labelOfTestSubject + " {name: 'A'}) WITH t "
			+ "CREATE (t) - [:HAS_WIFE] -> (w:Person {firstName: 'B'}) "
			+ "CREATE (t) - [:HAS_DAUGHTER] -> (d:Person {firstName: 'C'}) "
			+ "WITH t "
			+ "UNWIND ['Tom', 'Garfield'] AS cat "
			+ "CREATE (t) - [:CATS] -> (w:Pet {name: cat}) "
			+ "WITH DISTINCT t "
			+ "UNWIND ['Benji', 'Lassie'] AS dog "
			+ "CREATE (t) - [:DOGS] -> (w:Pet {name: dog}) "
			+ "RETURN DISTINCT id(t) as id").single().get("id").asLong();
		transaction.commit();
	}
}
 
Example #2
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 #3
Source File: StringlyTypedDynamicRelationshipsIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test // GH-216
void shouldWriteDynamicCollectionRelationships(@Autowired PersonWithRelativesRepository repository) {

	PersonWithStringlyTypedRelatives newPerson = new PersonWithStringlyTypedRelatives("Test");
	Map<String, List<Pet>> pets = newPerson.getPets();

	List<Pet> monsters = pets.computeIfAbsent("MONSTERS", s -> new ArrayList<>());
	monsters.add(new Pet("Godzilla"));
	monsters.add(new Pet("King Kong"));

	List<Pet> fish = pets.computeIfAbsent("FISH", s -> new ArrayList<>());
	fish.add(new Pet("Nemo"));

	newPerson = repository.save(newPerson);
	pets = newPerson.getPets();
	assertThat(pets).containsOnlyKeys("MONSTERS", "FISH");

	try (Transaction transaction = driver.session().beginTransaction()) {
		long numberOfRelations = transaction.run(""
			+ "MATCH (t:" + labelOfTestSubject + ") WHERE id(t) = $id "
			+ "RETURN size((t)-->(:Pet))"
			+ " as numberOfRelations", Values.parameters("id", newPerson.getId()))
			.single().get("numberOfRelations").asLong();
		assertThat(numberOfRelations).isEqualTo(3L);
	}
}
 
Example #4
Source File: DynamicRelationshipsIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test // GH-216
void shouldWriteDynamicCollectionRelationships(@Autowired PersonWithRelativesRepository repository) {

	PersonWithRelatives newPerson = new PersonWithRelatives("Test");
	Map<TypeOfPet, List<Pet>> pets = newPerson.getPets();

	List<Pet> monsters = pets.computeIfAbsent(TypeOfPet.MONSTERS, s -> new ArrayList<>());
	monsters.add(new Pet("Godzilla"));
	monsters.add(new Pet("King Kong"));

	List<Pet> fish = pets.computeIfAbsent(TypeOfPet.FISH, s -> new ArrayList<>());
	fish.add(new Pet("Nemo"));

	newPerson = repository.save(newPerson);
	pets = newPerson.getPets();
	assertThat(pets).containsOnlyKeys(TypeOfPet.MONSTERS, TypeOfPet.FISH);

	try (Transaction transaction = driver.session().beginTransaction()) {
		long numberOfRelations = transaction.run(""
			+ "MATCH (t:" + labelOfTestSubject + ") WHERE id(t) = $id "
			+ "RETURN size((t)-->(:Pet))"
			+ " as numberOfRelations", Values.parameters("id", newPerson.getId()))
			.single().get("numberOfRelations").asLong();
		assertThat(numberOfRelations).isEqualTo(3L);
	}
}
 
Example #5
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 #6
Source File: AuditingITBase.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@BeforeEach
protected void setupData() {
	try (Transaction transaction = driver.session().beginTransaction()) {
		transaction.run("MATCH (n) detach delete n");

		idOfExistingThing = transaction
			.run(
				"CREATE (t:ImmutableAuditableThing {name: $name, createdBy: $createdBy, createdAt: $createdAt}) RETURN id(t) as id",
				Values.parameters("name", EXISTING_THING_NAME, "createdBy", EXISTING_THING_CREATED_BY, "createdAt",
					EXISTING_THING_CREATED_AT))
			.single().get("id").asLong();

		transaction
			.run(
				"CREATE (t:ImmutableAuditableThingWithGeneratedId {name: $name, createdBy: $createdBy, createdAt: $createdAt, id: $id}) RETURN t.id as id",
				Values.parameters("name", EXISTING_THING_NAME, "createdBy", EXISTING_THING_CREATED_BY, "createdAt",
					EXISTING_THING_CREATED_AT, "id", idOfExistingThingWithGeneratedId));

		transaction.commit();
	}
}
 
Example #7
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 #8
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();
	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();

	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 #9
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 #10
Source File: ReactiveDynamicLabelsIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
Long createTestEntity(Transaction transaction) {
	Record r = transaction.run(""
		+ "CREATE (e:SimpleDynamicLabelsCtor:Foo:Bar:Baz:Foobar) "
		+ "RETURN id(e) as existingEntityId").single();
	long newId = r.get("existingEntityId").asLong();
	transaction.commit();
	return newId;
}
 
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: DriverMocks.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
/**
 * @return An instance usable in a test where an open session with an ongoing transaction is required.
 */
public static Driver withOpenSessionAndTransaction() {

	Transaction transaction = mock(Transaction.class);
	when(transaction.isOpen()).thenReturn(true);

	Session session = mock(Session.class);
	when(session.isOpen()).thenReturn(true);
	when(session.beginTransaction(any(TransactionConfig.class))).thenReturn(transaction);

	Driver driver = mock(Driver.class);
	when(driver.session(any(SessionConfig.class))).thenReturn(session);
	return driver;
}
 
Example #13
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 #14
Source File: Neo4jResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void readNodes(Driver driver) {
    try (Session session = driver.session();
            Transaction transaction = session.beginTransaction()) {
        Result result = transaction
                .run("MATCH (f:Framework {name: $name}) - [:CAN_USE] -> (n) RETURN f, n",
                        Values.parameters("name", "Quarkus"));
        result.forEachRemaining(
                record -> System.out.println(String.format("%s works with %s", record.get("n").get("name").asString(),
                        record.get("f").get("name").asString())));
        transaction.commit();
    }
}
 
Example #15
Source File: Neo4jResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void createNodes(Driver driver) {
    try (Session session = driver.session();
            Transaction transaction = session.beginTransaction()) {
        transaction.run("CREATE (f:Framework {name: $name}) - [:CAN_USE] -> (n:Database {name: 'Neo4j'})",
                Values.parameters("name", "Quarkus"));
        transaction.commit();
    }
}
 
Example #16
Source File: Neo4jTransactionManagerTest.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void shouldParticipateInOngoingTransactionWithRollback() throws Exception {

	when(userTransaction.getStatus()).thenReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE,
			Status.STATUS_ACTIVE);

	JtaTransactionManager txManager = new JtaTransactionManager(userTransaction);
	TransactionTemplate txTemplate = new TransactionTemplate(txManager);

	txTemplate.execute(new TransactionCallbackWithoutResult() {

		@Override
		protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {

			assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
			assertThat(transactionStatus.isNewTransaction()).isTrue();
			assertThat(TransactionSynchronizationManager.hasResource(driver)).isFalse();

			Transaction nativeTransaction = retrieveTransaction(driver, databaseName);

			assertThat(nativeTransaction).isNotNull();
			assertThat(TransactionSynchronizationManager.hasResource(driver)).isTrue();

			transactionStatus.setRollbackOnly();
		}
	});

	verify(userTransaction).begin();
	verify(userTransaction).rollback();

	verify(driver).session(any(SessionConfig.class));

	verify(session, times(2)).isOpen();
	verify(session).beginTransaction(any(TransactionConfig.class));
	verify(session).close();

	verify(transaction, times(3)).isOpen();
	verify(transaction).rollback();
	verify(transaction).close();
}
 
Example #17
Source File: Neo4jTransactionManagerTest.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void shouldParticipateInOngoingTransactionWithCommit() throws Exception {

	when(userTransaction.getStatus()).thenReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE,
			Status.STATUS_ACTIVE);

	JtaTransactionManager txManager = new JtaTransactionManager(userTransaction);
	TransactionTemplate txTemplate = new TransactionTemplate(txManager);

	txTemplate.execute(new TransactionCallbackWithoutResult() {

		@Override
		protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {

			assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
			assertThat(transactionStatus.isNewTransaction()).isTrue();
			assertThat(TransactionSynchronizationManager.hasResource(driver)).isFalse();

			Transaction nativeTransaction = retrieveTransaction(driver, databaseName);

			assertThat(nativeTransaction).isNotNull();
			assertThat(TransactionSynchronizationManager.hasResource(driver)).isTrue();
		}
	});

	verify(userTransaction).begin();

	verify(driver).session(any(SessionConfig.class));

	verify(session, times(2)).isOpen();
	verify(session).beginTransaction(any(TransactionConfig.class));
	verify(session).close();

	verify(transaction, times(3)).isOpen();
	verify(transaction).commit();
	verify(transaction).close();
}
 
Example #18
Source File: Neo4jTransactionManagerTest.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void shouldUseTxFromNeo4jTxManager() {

	Neo4jTransactionManager txManager = new Neo4jTransactionManager(driver, DatabaseSelectionProvider.createStaticDatabaseSelectionProvider(databaseName));
	TransactionTemplate txTemplate = new TransactionTemplate(txManager);

	txTemplate.execute(new TransactionCallbackWithoutResult() {

		@Override
		protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {

			assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
			assertThat(transactionStatus.isNewTransaction()).isTrue();
			assertThat(TransactionSynchronizationManager.hasResource(driver)).isTrue();

			Transaction optionalTransaction = retrieveTransaction(driver, databaseName);
			assertThat(optionalTransaction).isNotNull();

			transactionStatus.setRollbackOnly();
		}
	});

	verify(driver).session(any(SessionConfig.class));

	verify(session).isOpen();
	verify(session).beginTransaction(any(TransactionConfig.class));
	verify(session).close();

	verify(transaction, times(2)).isOpen();
	verify(transaction).rollback();
	verify(transaction).close();
}
 
Example #19
Source File: Neo4jTransactionManagerTest.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void shouldWorkWithoutSynchronizations() {
	Transaction optionalTransaction = retrieveTransaction(driver, databaseName);

	assertThat(optionalTransaction).isNull();

	verifyNoInteractions(driver, session, transaction);
}
 
Example #20
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 #21
Source File: ReactiveDynamicLabelsIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
Long createTestEntity(Transaction transaction) {
	Record r = transaction.run(""
		+ "CREATE (e:SimpleDynamicLabelsWithBusinessIdAndVersion:Foo:Bar:Baz:Foobar {id: 'E2', myVersion: 0}) "
		+ "RETURN id(e) as existingEntityId").single();
	long newId = r.get("existingEntityId").asLong();
	transaction.commit();
	return newId;
}
 
Example #22
Source File: ReactiveDynamicLabelsIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
Long createTestEntity(Transaction transaction) {
	Record r = transaction.run(""
		+ "CREATE (e:SimpleDynamicLabelsWithVersion:Foo:Bar:Baz:Foobar {myVersion: 0}) "
		+ "RETURN id(e) as existingEntityId").single();
	long newId = r.get("existingEntityId").asLong();
	transaction.commit();
	return newId;
}
 
Example #23
Source File: ReactiveDynamicLabelsIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
Long createTestEntity(Transaction transaction) {
	Record r = transaction.run(""
		+ "CREATE (e:SimpleDynamicLabelsWithBusinessId:Foo:Bar:Baz:Foobar {id: 'E1'}) "
		+ "RETURN id(e) as existingEntityId").single();
	long newId = r.get("existingEntityId").asLong();
	transaction.commit();
	return newId;
}
 
Example #24
Source File: ReactiveDynamicLabelsIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
Long createTestEntity(Transaction transaction) {
	Record r = transaction.run(""
		+ "CREATE (e:InheritedSimpleDynamicLabels:Foo:Bar:Baz:Foobar) "
		+ "RETURN id(e) as existingEntityId").single();
	long newId = r.get("existingEntityId").asLong();
	transaction.commit();
	return newId;
}
 
Example #25
Source File: ReactiveDynamicLabelsIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
Long createTestEntity(Transaction transaction) {
	Record r = transaction.run(""
		+ "CREATE (e:SimpleDynamicLabels:Foo:Bar:Baz:Foobar) "
		+ "RETURN id(e) as existingEntityId").single();
	long newId = r.get("existingEntityId").asLong();
	transaction.commit();
	return newId;
}
 
Example #26
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 #27
Source File: ReactiveStringlyTypeDynamicRelationshipsIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test // GH-216
void shouldWriteDynamicCollectionRelationships(@Autowired PersonWithRelativesRepository repository) {

	PersonWithStringlyTypedRelatives newPerson = new PersonWithStringlyTypedRelatives("Test");
	Map<String, List<Pet>> pets = newPerson.getPets();

	List<Pet> monsters = pets.computeIfAbsent("MONSTERS", s -> new ArrayList<>());
	monsters.add(new Pet("Godzilla"));
	monsters.add(new Pet("King Kong"));

	List<Pet> fish = pets.computeIfAbsent("FISH", s -> new ArrayList<>());
	fish.add(new Pet("Nemo"));

	List<PersonWithStringlyTypedRelatives> recorded = new ArrayList<>();
	repository.save(newPerson)
		.as(StepVerifier::create)
		.recordWith(() -> recorded)
		.consumeNextWith(person -> {
			Map<String, List<Pet>> writtenPets = person.getPets();
			assertThat(writtenPets).containsOnlyKeys("MONSTERS", "FISH");
		})
		.verifyComplete();

	try (Transaction transaction = driver.session().beginTransaction()) {
		long numberOfRelations = transaction.run(""
			+ "MATCH (t:" + labelOfTestSubject + ") WHERE id(t) = $id "
			+ "RETURN size((t)-->(:Pet))"
			+ " as numberOfRelations", Values.parameters("id", recorded.get(0).getId()))
			.single().get("numberOfRelations").asLong();
		assertThat(numberOfRelations).isEqualTo(3L);
	}
}
 
Example #28
Source File: ReactiveStringlyTypeDynamicRelationshipsIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void shouldWriteDynamicRelationships(@Autowired PersonWithRelativesRepository repository) {

	PersonWithStringlyTypedRelatives newPerson = new PersonWithStringlyTypedRelatives("Test");
	Person d = new Person();
	ReflectionTestUtils.setField(d, "firstName", "R1");
	newPerson.getRelatives().put("RELATIVE_1", d);
	d = new Person();
	ReflectionTestUtils.setField(d, "firstName", "R2");
	newPerson.getRelatives().put("RELATIVE_2", d);

	List<PersonWithStringlyTypedRelatives> recorded = new ArrayList<>();
	repository.save(newPerson)
		.as(StepVerifier::create)
		.recordWith(() -> recorded)
		.consumeNextWith(personWithRelatives -> {
			Map<String, Person> relatives = personWithRelatives.getRelatives();
			assertThat(relatives).containsOnlyKeys("RELATIVE_1", "RELATIVE_2");
		})
		.verifyComplete();

	try (Transaction transaction = driver.session().beginTransaction()) {
		long numberOfRelations = transaction.run(""
				+ "MATCH (t:" + labelOfTestSubject + ") WHERE id(t) = $id "
				+ "RETURN size((t)-->(:Person))"
				+ " as numberOfRelations",
			Values.parameters("id", recorded.get(0).getId()))
			.single().get("numberOfRelations").asLong();
		assertThat(numberOfRelations).isEqualTo(2L);
	}
}
 
Example #29
Source File: ReactiveDynamicRelationshipsIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test // GH-216
void shouldWriteDynamicCollectionRelationships(@Autowired PersonWithRelativesRepository repository) {

	PersonWithRelatives newPerson = new PersonWithRelatives("Test");
	Map<TypeOfPet, List<Pet>> pets = newPerson.getPets();

	List<Pet> monsters = pets.computeIfAbsent(TypeOfPet.MONSTERS, s -> new ArrayList<>());
	monsters.add(new Pet("Godzilla"));
	monsters.add(new Pet("King Kong"));

	List<Pet> fish = pets.computeIfAbsent(TypeOfPet.FISH, s -> new ArrayList<>());
	fish.add(new Pet("Nemo"));

	List<PersonWithRelatives> recorded = new ArrayList<>();
	repository.save(newPerson)
		.as(StepVerifier::create)
		.recordWith(() -> recorded)
		.consumeNextWith(person -> {
			Map<TypeOfPet, List<Pet>> writtenPets = person.getPets();
			assertThat(writtenPets).containsOnlyKeys(TypeOfPet.MONSTERS, TypeOfPet.FISH);
		})
		.verifyComplete();

	try (Transaction transaction = driver.session().beginTransaction()) {
		long numberOfRelations = transaction.run(""
			+ "MATCH (t:" + labelOfTestSubject + ") WHERE id(t) = $id "
			+ "RETURN size((t)-->(:Pet))"
			+ " as numberOfRelations", Values.parameters("id", recorded.get(0).getId()))
			.single().get("numberOfRelations").asLong();
		assertThat(numberOfRelations).isEqualTo(3L);
	}
}
 
Example #30
Source File: ReactiveDynamicRelationshipsIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void shouldWriteDynamicRelationships(@Autowired PersonWithRelativesRepository repository) {

	PersonWithRelatives newPerson = new PersonWithRelatives("Test");
	Person d = new Person();
	ReflectionTestUtils.setField(d, "firstName", "R1");
	newPerson.getRelatives().put(TypeOfRelative.RELATIVE_1, d);
	d = new Person();
	ReflectionTestUtils.setField(d, "firstName", "R2");
	newPerson.getRelatives().put(TypeOfRelative.RELATIVE_2, d);

	List<PersonWithRelatives> recorded = new ArrayList<>();
	repository.save(newPerson)
		.as(StepVerifier::create)
		.recordWith(() -> recorded)
		.consumeNextWith(personWithRelatives -> {
			Map<TypeOfRelative, Person> relatives = personWithRelatives.getRelatives();
			assertThat(relatives).containsOnlyKeys(TypeOfRelative.RELATIVE_1, TypeOfRelative.RELATIVE_2);
		})
		.verifyComplete();

	try (Transaction transaction = driver.session().beginTransaction()) {
		long numberOfRelations = transaction.run(""
				+ "MATCH (t:" + labelOfTestSubject + ") WHERE id(t) = $id "
				+ "RETURN size((t)-->(:Person))"
				+ " as numberOfRelations",
			Values.parameters("id", recorded.get(0).getId()))
			.single().get("numberOfRelations").asLong();
		assertThat(numberOfRelations).isEqualTo(2L);
	}
}