org.neo4j.driver.Record Java Examples

The following examples show how to use org.neo4j.driver.Record. 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: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void findNodeWithMultipleLabels(@Autowired ReactiveMultipleLabelRepository repository) {
	long n1Id;
	long n2Id;
	long n3Id;

	try (Session session = createSession()) {
		Record record = session.run("CREATE (n1:A:B:C), (n2:B:C), (n3:A) return n1, n2, n3").single();
		n1Id = record.get("n1").asNode().id();
		n2Id = record.get("n2").asNode().id();
		n3Id = record.get("n3").asNode().id();
	}

	StepVerifier.create(repository.findById(n1Id))
		.expectNextCount(1)
		.verifyComplete();
	StepVerifier.create(repository.findById(n2Id))
		.verifyComplete();
	StepVerifier.create(repository.findById(n3Id))
		.verifyComplete();
}
 
Example #2
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void findNodeWithMultipleLabels(@Autowired MultipleLabelRepository multipleLabelRepository) {
	long n1Id;
	long n2Id;
	long n3Id;

	try (Session session = createSession()) {
		Record record = session.run("CREATE (n1:A:B:C), (n2:B:C), (n3:A) return n1, n2, n3").single();
		n1Id = record.get("n1").asNode().id();
		n2Id = record.get("n2").asNode().id();
		n3Id = record.get("n3").asNode().id();
	}

	assertThat(multipleLabelRepository.findById(n1Id)).isPresent();
	assertThat(multipleLabelRepository.findById(n2Id)).isNotPresent();
	assertThat(multipleLabelRepository.findById(n3Id)).isNotPresent();
}
 
Example #3
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void createNodeAndRelationshipWithMultipleLabels(
	@Autowired MultipleLabelWithAssignedIdRepository multipleLabelRepository) {
	MultipleLabels.MultipleLabelsEntityWithAssignedId entity = new MultipleLabels.MultipleLabelsEntityWithAssignedId(
		4711L);
	entity.otherMultipleLabelEntity = new MultipleLabels.MultipleLabelsEntityWithAssignedId(42L);

	multipleLabelRepository.save(entity);

	try (Session session = createSession()) {
		Record record = session.run("MATCH (n:X)-[:HAS]->(c:X) return n, c").single();
		Node parentNode = record.get("n").asNode();
		Node childNode = record.get("c").asNode();
		assertThat(parentNode.labels()).containsExactlyInAnyOrder("X", "Y", "Z");
		assertThat(childNode.labels()).containsExactlyInAnyOrder("X", "Y", "Z");
	}
}
 
Example #4
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void deleteNodeWithMultipleLabels(@Autowired MultipleLabelWithAssignedIdRepository multipleLabelRepository) {
	long n1Id;
	long n2Id;
	long n3Id;

	try (Session session = createSession()) {
		Record record = session
			.run("CREATE (n1:X:Y:Z{id:4711}), (n2:Y:Z{id:42}), (n3:X{id:23}) return n1, n2, n3").single();
		n1Id = record.get("n1").asNode().get("id").asLong();
		n2Id = record.get("n2").asNode().get("id").asLong();
		n3Id = record.get("n3").asNode().get("id").asLong();
	}

	multipleLabelRepository.deleteById(n1Id);
	multipleLabelRepository.deleteById(n2Id);
	multipleLabelRepository.deleteById(n3Id);

	try (Session session = createSession()) {
		assertThat(session.run("MATCH (n:X:Y:Z) return n").list()).hasSize(0);
		assertThat(session.run("MATCH (n:Y:Z) return n").list()).hasSize(1);
		assertThat(session.run("MATCH (n:X) return n").list()).hasSize(1);
	}
}
 
Example #5
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void saveEntityGraphWithSelfInverseRelationshipDefined(@Autowired SimilarThingRepository repository) {
	SimilarThing originalThing = new SimilarThing().withName("Original");
	SimilarThing similarThing = new SimilarThing().withName("Similar");

	originalThing.setSimilar(similarThing);
	similarThing.setSimilarOf(originalThing);
	repository.save(originalThing);

	try (Session session = createSession()) {
		Record record = session.run(
			"MATCH (ot:SimilarThing{name:'Original'})-[r:SimilarTo]->(st:SimilarThing {name:'Similar'})"
				+ " RETURN r").single();

		assertThat(record.keys()).isNotEmpty();
		assertThat(record.containsKey("r")).isTrue();
		assertThat(record.get("r").asRelationship().type()).isEqualToIgnoringCase("SimilarTo");
	}
}
 
Example #6
Source File: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void loadEntityWithBidirectionalRelationship(@Autowired BidirectionalStartRepository repository) {

	long startId;

	try (Session session = createSession()) {
		Record record = session
			.run("CREATE (n:BidirectionalStart{name:'Ernie'})-[:CONNECTED]->(e:BidirectionalEnd{name:'Bert'}) "
				+ "RETURN n").single();

		Node startNode = record.get("n").asNode();
		startId = startNode.id();
	}

	StepVerifier.create(repository.findById(startId))
		.assertNext(entity -> {
			assertThat(entity.getEnds()).hasSize(1);
		})
		.verifyComplete();
}
 
Example #7
Source File: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void deleteNodeWithMultipleLabels(@Autowired ReactiveMultipleLabelRepository repository) {

	long n1Id;
	long n2Id;
	long n3Id;

	try (Session session = createSession()) {
		Record record = session.run("CREATE (n1:A:B:C), (n2:B:C), (n3:A) return n1, n2, n3").single();
		n1Id = record.get("n1").asNode().id();
		n2Id = record.get("n2").asNode().id();
		n3Id = record.get("n3").asNode().id();
	}

	repository.deleteById(n1Id).block();
	repository.deleteById(n2Id).block();
	repository.deleteById(n3Id).block();

	try (Session session = createSession()) {
		assertThat(session.run("MATCH (n:A:B:C) return n").list()).hasSize(0);
		assertThat(session.run("MATCH (n:B:C) return n").list()).hasSize(1);
		assertThat(session.run("MATCH (n:A) return n").list()).hasSize(1);
	}
}
 
Example #8
Source File: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void createNodeAndRelationshipWithMultipleLabels(@Autowired ReactiveMultipleLabelWithAssignedIdRepository repository) {

	MultipleLabels.MultipleLabelsEntityWithAssignedId entity = new MultipleLabels.MultipleLabelsEntityWithAssignedId(4711L);
	entity.otherMultipleLabelEntity = new MultipleLabels.MultipleLabelsEntityWithAssignedId(42L);

	repository.save(entity).block();

	try (Session session = createSession()) {
		Record record = session.run("MATCH (n:X)-[:HAS]->(c:X) return n, c").single();
		Node parentNode = record.get("n").asNode();
		Node childNode = record.get("c").asNode();
		assertThat(parentNode.labels()).containsExactlyInAnyOrder("X", "Y", "Z");
		assertThat(childNode.labels()).containsExactlyInAnyOrder("X", "Y", "Z");
	}
}
 
Example #9
Source File: Neo4JSession.java    From neo4j-gremlin-bolt with Apache License 2.0 6 votes vote down vote up
private Vertex loadVertex(Record record) {
    // node
    Node node = record.get(0).asNode();
    // vertex id
    Object vertexId = vertexIdProvider.get(node);
    // check vertex has been deleted
    if (!deletedVertices.contains(vertexId)) {
        // check this vertex has been already loaded into this session
        Vertex vertex = vertices.get(vertexId);
        if (vertex == null) {
            // check node belongs to partition
            if (partition.containsVertex(StreamSupport.stream(node.labels().spliterator(), false).collect(Collectors.toSet()))) {
                // create and register vertex
                return registerVertex(new Neo4JVertex(graph, this, vertexIdProvider, edgeIdProvider, node));
            }
            // skip vertex (not in partition)
            return null;
        }
        // return vertex
        return vertex;
    }
    // skip vertex (deleted)
    return null;
}
 
Example #10
Source File: CallbacksITBase.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
protected void verifyDatabase(Iterable<ThingWithAssignedId> expectedValues) {

		List<String> ids = StreamSupport.stream(expectedValues.spliterator(), false)
			.map(ThingWithAssignedId::getTheId).collect(toList());
		List<String> names = StreamSupport.stream(expectedValues.spliterator(), false)
			.map(ThingWithAssignedId::getName).collect(toList());
		try (Session session = driver.session()) {
			Record record = session
				.run("MATCH (n:Thing) WHERE n.theId in $ids RETURN COLLECT(n) as things", Values.parameters("ids", ids))
				.single();

			List<Node> nodes = record.get("things").asList(Value::asNode);
			assertThat(nodes).extracting(n -> n.get("theId").asString()).containsAll(ids);
			assertThat(nodes).extracting(n -> n.get("name").asString())
				.containsAll(names);
		}
	}
 
Example #11
Source File: ReactiveNeo4jOperationsIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void saveAll() {
	String thing1Name = "testThing1";
	String thing2Name = "testThing2";
	ThingWithGeneratedId thing1 = new ThingWithGeneratedId(thing1Name);
	ThingWithGeneratedId thing2 = new ThingWithGeneratedId(thing2Name);

	StepVerifier.create(neo4jOperations.saveAll(Arrays.asList(thing1, thing2)))
		.expectNextCount(2)
		.verifyComplete();

	try (Session session = driver.session(getSessionConfig())) {
		Map<String, Object> paramMap = new HashMap<>();
		paramMap.put("name1", thing1Name);
		paramMap.put("name2", thing2Name);

		Result result = session.run(
			"MATCH (t:ThingWithGeneratedId) WHERE t.name = $name1 or t.name = $name2 return t",
			paramMap);
		List<Record> resultValues = result.list();
		assertThat(resultValues).hasSize(2);
		assertThat(resultValues).allMatch(record ->
			record.asMap(Function.identity()).get("t").get("name").asString().startsWith("testThing"));
	}
}
 
Example #12
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void saveWithAssignedId(@Autowired ThingRepository repository) {

	assertThat(repository.count()).isEqualTo(21);

	ThingWithAssignedId thing = new ThingWithAssignedId("aaBB");
	thing.setName("That's the thing.");
	thing = repository.save(thing);

	try (Session session = createSession()) {
		Record record = session
			.run("MATCH (n:Thing) WHERE n.theId = $id RETURN n", Values.parameters("id", thing.getTheId()))
			.single();

		assertThat(record.containsKey("n")).isTrue();
		Node node = record.get("n").asNode();
		assertThat(node.get("theId").asString()).isEqualTo(thing.getTheId());
		assertThat(node.get("name").asString()).isEqualTo(thing.getName());

		assertThat(repository.count()).isEqualTo(22);
	}
}
 
Example #13
Source File: PartTreeNeo4jQuery.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Override
protected <T extends Object> PreparedQuery<T> prepareQuery(
	Class<T> returnedType, List<String> includedProperties, Neo4jParameterAccessor parameterAccessor,
	@Nullable Neo4jQueryType queryType,
	@Nullable BiFunction<TypeSystem, Record, ?> mappingFunction) {

	CypherQueryCreator queryCreator = new CypherQueryCreator(
		mappingContext, domainType, Optional.ofNullable(queryType).orElseGet(() -> Neo4jQueryType.fromPartTree(tree)), tree, parameterAccessor,
		includedProperties,
		this::convertParameter
	);

	QueryAndParameters queryAndParameters = queryCreator.createQuery();

	return PreparedQuery.queryFor(returnedType)
		.withCypherQuery(queryAndParameters.getQuery())
		.withParameters(queryAndParameters.getParameters())
		.usingMappingFunction(mappingFunction)
		.build();
}
 
Example #14
Source File: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void loadEntityWithRelationshipWithAssignedId(@Autowired ReactivePetRepository repository) {

	long petNodeId;

	try (Session session = createSession()) {
		Record record = session
			.run("CREATE (p:Pet{name:'Jerry'})-[:Has]->(t:Thing{theId:'t1', name:'Thing1'}) "
				+ "RETURN p, t").single();

		Node petNode = record.get("p").asNode();
		petNodeId = petNode.id();
	}

	StepVerifier.create(repository.findById(petNodeId))
		.assertNext(pet -> {
			ThingWithAssignedId relatedThing = pet.getThings().get(0);
			assertThat(relatedThing.getTheId()).isEqualTo("t1");
			assertThat(relatedThing.getName()).isEqualTo("Thing1");
		})
		.verifyComplete();
}
 
Example #15
Source File: Neo4jQuerySupport.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
protected final BiFunction<TypeSystem, Record, ?> getMappingFunction(final ResultProcessor resultProcessor) {

		final Class<?> returnedType = resultProcessor.getReturnedType().getReturnedType();

		final BiFunction<TypeSystem, Record, ?> mappingFunction;
		if (Neo4jSimpleTypes.HOLDER.isSimpleType(returnedType)) {
			// Clients automatically selects a single value mapping function.
			// It will thrown an error if the query contains more than one column.
			mappingFunction = null;
		} else if (resultProcessor.getReturnedType().isProjecting()) {

			if (returnedType.isInterface()) {
				mappingFunction = this.mappingContext.getRequiredMappingFunctionFor(domainType);
			} else if (this.mappingContext.hasPersistentEntityFor(returnedType)) {
				mappingFunction = this.mappingContext.getRequiredMappingFunctionFor(returnedType);
			} else {
				this.mappingContext.addPersistentEntity(returnedType);
				mappingFunction = this.mappingContext.getRequiredMappingFunctionFor(returnedType);
			}
		} else {
			mappingFunction = this.mappingContext.getRequiredMappingFunctionFor(domainType);
		}
		return mappingFunction;
	}
 
Example #16
Source File: ReactiveRepositoryIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void saveEntityGraphWithSelfInverseRelationshipDefined(@Autowired ReactiveSimilarThingRepository repository) {
	SimilarThing originalThing = new SimilarThing().withName("Original");
	SimilarThing similarThing = new SimilarThing().withName("Similar");


	originalThing.setSimilar(similarThing);
	similarThing.setSimilarOf(originalThing);
	StepVerifier.create(repository.save(originalThing))
		.expectNextCount(1)
		.verifyComplete();

	try (Session session = createSession()) {
		Record record = session.run(
			"MATCH (ot:SimilarThing{name:'Original'})-[r:SimilarTo]->(st:SimilarThing {name:'Similar'})"
				+ " RETURN r").single();

		assertThat(record.keys()).isNotEmpty();
		assertThat(record.containsKey("r")).isTrue();
		assertThat(record.get("r").asRelationship().type()).isEqualToIgnoringCase("SimilarTo");
	}
}
 
Example #17
Source File: ReactivePartTreeNeo4jQuery.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Override
protected <T extends Object> PreparedQuery<T> prepareQuery(
	Class<T> returnedType, List<String> includedProperties, Neo4jParameterAccessor parameterAccessor,
	@Nullable Neo4jQueryType queryType,
	@Nullable BiFunction<TypeSystem, Record, ?> mappingFunction) {

	CypherQueryCreator queryCreator = new CypherQueryCreator(
		mappingContext, domainType, Optional.ofNullable(queryType).orElseGet(() -> Neo4jQueryType.fromPartTree(tree)), tree, parameterAccessor,
		includedProperties,
		this::convertParameter
	);

	QueryAndParameters queryAndParameters = queryCreator.createQuery();

	return PreparedQuery.queryFor(returnedType)
		.withCypherQuery(queryAndParameters.getQuery())
		.withParameters(queryAndParameters.getParameters())
		.usingMappingFunction(mappingFunction)
		.build();
}
 
Example #18
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void saveAllWithAssignedIdAndRelationship(@Autowired ThingRepository repository) {

	ThingWithAssignedId thing = new ThingWithAssignedId("aaBB");
	thing.setName("That's the thing.");
	AnotherThingWithAssignedId anotherThing = new AnotherThingWithAssignedId(4711L);
	anotherThing.setName("AnotherThing");
	thing.setThings(singletonList(anotherThing));
	repository.saveAll(singletonList(thing));

	try (Session session = createSession()) {
		Record record = session
			.run("MATCH (n:Thing)-[:Has]->(t:Thing2) WHERE n.theId = $id RETURN n, t",
				Values.parameters("id", thing.getTheId()))
			.single();

		assertThat(record.containsKey("n")).isTrue();
		assertThat(record.containsKey("t")).isTrue();
		Node node = record.get("n").asNode();
		assertThat(node.get("theId").asString()).isEqualTo(thing.getTheId());
		assertThat(node.get("name").asString()).isEqualTo(thing.getName());

		Node relatedNode = record.get("t").asNode();
		assertThat(relatedNode.get("theId").asLong()).isEqualTo(anotherThing.getTheId());
		assertThat(relatedNode.get("name").asString()).isEqualTo(anotherThing.getName());
		assertThat(repository.count()).isEqualTo(1);
	}
}
 
Example #19
Source File: DynamicLabelsIT.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 #20
Source File: RemoteDatastoreRelationManager.java    From extended-objects with Apache License 2.0 5 votes vote down vote up
@Override
public RemoteRelationship findRelationById(RelationTypeMetadata<RelationshipMetadata<RemoteRelationshipType>> metadata, Long id) {
    String statement = String.format("MATCH (start)-[r:%s]->(end) WHERE id(r)=$id RETURN start,r,end",
            metadata.getDatastoreMetadata().getDiscriminator().getName());
    Record record = statementExecutor.getSingleResult(statement, parameters("id", id));
    Node start = record.get("start").asNode();
    Relationship relationship = record.get("r").asRelationship();
    Node end = record.get("end").asNode();
    return datastoreSessionCache.getRelationship(start, relationship, end);
}
 
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:SimpleDynamicLabels:Foo:Bar:Baz:Foobar) "
		+ "RETURN id(e) as existingEntityId").single();
	long newId = r.get("existingEntityId").asLong();
	transaction.commit();
	return newId;
}
 
Example #22
Source File: DynamicLabelsIT.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:DynamicLabelsBaseClass:ExtendedBaseClass1:D1:D2:D3) "
		+ "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: RepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void updateSingleEntity(@Autowired PersonRepository repository) {

	PersonWithAllConstructor originalPerson = repository.findById(id1).get();
	originalPerson.setFirstName("Updated first name");
	originalPerson.setNullable("Updated nullable field");
	assertThat(originalPerson.getThings()).isNotEmpty();
	originalPerson.setThings(emptyList());

	PersonWithAllConstructor savedPerson = repository.save(originalPerson);
	try (Session session = createSession()) {
		session.readTransaction(tx -> {
			Record record = tx.run("MATCH (n:PersonWithAllConstructor) WHERE id(n) = $id RETURN n",
				Values.parameters("id", id1)).single();

			assertThat(record.containsKey("n")).isTrue();
			Node node = record.get("n").asNode();

			assertThat(node.id()).isEqualTo(savedPerson.getId());
			assertThat(node.get("first_name").asString()).isEqualTo(savedPerson.getFirstName());
			assertThat(node.get("nullable").asString()).isEqualTo(savedPerson.getNullable());
			assertThat(node.get("things").asList()).isEmpty();

			return null;
		});
	}
}
 
Example #25
Source File: StatementExecutor.java    From extended-objects with Apache License 2.0 5 votes vote down vote up
private Record getSingleResult(Result result) {
    try {
        return result.single();
    } catch (NoSuchRecordException e) {
        throw new XOException("Query returned no result.");
    } finally {
        result.consume();
    }
}
 
Example #26
Source File: Neo4JVertex.java    From neo4j-gremlin-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public Neo4JDatabaseCommand insertCommand() {
    // concat labels with additional labels on insertion
    SortedSet<String> labels = Stream.concat(this.labels.stream(), additionalLabels.stream()).collect(Collectors.toCollection(TreeSet::new));
    try {
        // parameters
        Map<String, Object> parameters = Collections.singletonMap("vp", statementParameters());
        // check database side id generation is required
        if (id == null) {
            // create statement
            String statement = "CREATE (n" + processLabels(labels, false) + "$vp) RETURN " + vertexIdProvider.matchPredicateOperand("n");
            // command statement
            return new Neo4JDatabaseCommand(statement, parameters, result -> {
                // check we received data
                if (result.hasNext()) {
                    // record
                    Record record = result.next();
                    // process node identifier
                    generatedId = vertexIdProvider.processIdentifier(record.get(0).asObject());
                }
            });
        }
        // command statement
        return new Neo4JDatabaseCommand("CREATE (" + processLabels(labels, false) + "$vp)", parameters);
    }
    finally {
        // to find vertex in database (labels + additional labels)
        matchLabels = labels;
    }
}
 
Example #27
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void saveWithAssignedIdAndRelationship(@Autowired ThingRepository repository) {

	ThingWithAssignedId thing = new ThingWithAssignedId("aaBB");
	thing.setName("That's the thing.");
	AnotherThingWithAssignedId anotherThing = new AnotherThingWithAssignedId(4711L);
	anotherThing.setName("AnotherThing");
	thing.setThings(singletonList(anotherThing));
	thing = repository.save(thing);

	try (Session session = createSession()) {
		Record record = session
			.run("MATCH (n:Thing)-[:Has]->(t:Thing2) WHERE n.theId = $id RETURN n, t",
				Values.parameters("id", thing.getTheId()))
			.single();

		assertThat(record.containsKey("n")).isTrue();
		assertThat(record.containsKey("t")).isTrue();
		Node node = record.get("n").asNode();
		assertThat(node.get("theId").asString()).isEqualTo(thing.getTheId());
		assertThat(node.get("name").asString()).isEqualTo(thing.getName());

		Node relatedNode = record.get("t").asNode();
		assertThat(relatedNode.get("theId").asLong()).isEqualTo(anotherThing.getTheId());
		assertThat(relatedNode.get("name").asString()).isEqualTo(anotherThing.getName());
		assertThat(repository.count()).isEqualTo(1);
	}
}
 
Example #28
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void saveAllWithAssignedId(@Autowired ThingRepository repository) {

	assertThat(repository.count()).isEqualTo(21);

	ThingWithAssignedId newThing = new ThingWithAssignedId("aaBB");
	newThing.setName("That's the thing.");

	ThingWithAssignedId existingThing = repository.findById("anId").get();
	existingThing.setName("Updated name.");

	repository.saveAll(Arrays.asList(newThing, existingThing));

	try (Session session = createSession()) {
		Record record = session
			.run(
				"MATCH (n:Thing) WHERE n.theId IN ($ids) WITH n ORDER BY n.name ASC RETURN COLLECT(n.name) as names",
				Values.parameters("ids", Arrays.asList(newThing.getTheId(), existingThing.getTheId())))
			.single();

		assertThat(record.containsKey("names")).isTrue();
		List<String> names = record.get("names").asList(Value::asString);
		assertThat(names).containsExactly(newThing.getName(), existingThing.getName());

		assertThat(repository.count()).isEqualTo(22);
	}
}
 
Example #29
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void saveAllWithConvertedId(@Autowired EntityWithConvertedIdRepository repository) {
	EntityWithConvertedId entity = new EntityWithConvertedId();
	entity.setIdentifyingEnum(EntityWithConvertedId.IdentifyingEnum.A);
	repository.saveAll(Collections.singleton(entity));

	try (Session session = createSession()) {
		Record node = session.run("MATCH (e:EntityWithConvertedId) return e").next();
		assertThat(node.get("e").get("identifyingEnum").asString()).isEqualTo("A");
	}
}
 
Example #30
Source File: RepositoryIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void updateWithAssignedId(@Autowired ThingRepository repository) {

	assertThat(repository.count()).isEqualTo(21);

	ThingWithAssignedId thing = new ThingWithAssignedId("id07");
	thing.setName("An updated thing");
	repository.save(thing);

	thing = repository.findById("id15").get();
	thing.setName("Another updated thing");
	repository.save(thing);

	try (Session session = createSession()) {
		Record record = session
			.run(
				"MATCH (n:Thing) WHERE n.theId IN ($ids) WITH n ORDER BY n.name ASC RETURN COLLECT(n.name) as names",
				Values.parameters("ids", Arrays.asList("id07", "id15")))
			.single();

		assertThat(record.containsKey("names")).isTrue();
		List<String> names = record.get("names").asList(Value::asString);
		assertThat(names).containsExactly("An updated thing", "Another updated thing");

		assertThat(repository.count()).isEqualTo(21);
	}
}