use of org.neo4j.ogm.domain.gh817.Bike in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method shouldRefreshUpdatedRelationshipEntities.
// GH-817
@Test
public void shouldRefreshUpdatedRelationshipEntities() {
sessionFactory.openSession().purgeDatabase();
Session sessionForCreation = sessionFactory.openSession();
Rider rider = new Rider("Michael");
Bike bike1 = new Bike("Bike1");
Bike bike2 = new Bike("Bike2");
rider.getTrips().add(new Trip(rider, bike1, "n/a"));
rider.getTrips().add(new Trip(rider, bike2, "n/a"));
try (Transaction tx = sessionForCreation.beginTransaction()) {
sessionForCreation.save(rider);
tx.commit();
}
Session sessionForLoadingAndUpdate = sessionFactory.openSession();
Iterable<Trip> loadedBikes = sessionForLoadingAndUpdate.loadAll(Trip.class);
assertThat(loadedBikes).hasSize(2).extracting(Trip::getName).containsOnly("n/a");
String name = "A nice trip";
Iterable<Trip> updatedBikes = sessionForLoadingAndUpdate.query(Trip.class, "MATCH (r:Rider) - [t:RODE] -> (c:Bike) SET t.name = $newName RETURN *", Collections.singletonMap("newName", name));
Rider loadedRider = sessionForLoadingAndUpdate.load(Rider.class, rider.getId());
assertThat(updatedBikes).hasSize(2).extracting(Trip::getName).containsOnly(name);
assertThat(loadedRider.getTrips()).hasSize(2).extracting(Trip::getName).containsOnly(name);
}
use of org.neo4j.ogm.domain.gh817.Bike in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method shouldFlushSessionWithoutReturningNodes.
// GH-817
@Test
public void shouldFlushSessionWithoutReturningNodes() {
sessionFactory.openSession().purgeDatabase();
Session sessionForCreation = sessionFactory.openSession();
try (Transaction tx = sessionForCreation.beginTransaction()) {
Stream.of(new Bike("Bike1"), new Bike("Bike2")).forEach(sessionForCreation::save);
tx.commit();
}
Session sessionForLoadingAndUpdate = sessionFactory.openSession();
Iterable<Bike> loadedBikes = sessionForLoadingAndUpdate.loadAll(Bike.class);
assertThat(loadedBikes).hasSize(2).extracting(Bike::isDamaged).containsOnly(false);
sessionForLoadingAndUpdate.query("MATCH (c:Bike) SET c.damaged = true", Collections.emptyMap());
loadedBikes = sessionForLoadingAndUpdate.loadAll(Bike.class);
assertThat(loadedBikes).hasSize(2).extracting(Bike::isDamaged).containsOnly(true);
}
use of org.neo4j.ogm.domain.gh817.Bike in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method shouldRefreshUpdatedEntities.
// GH-817
@Test
public void shouldRefreshUpdatedEntities() {
sessionFactory.openSession().purgeDatabase();
Session sessionForCreation = sessionFactory.openSession();
try (Transaction tx = sessionForCreation.beginTransaction()) {
Stream.of(new Bike("Bike1"), new Bike("Bike2")).forEach(sessionForCreation::save);
tx.commit();
}
Session sessionForLoadingAndUpdate = sessionFactory.openSession();
Iterable<Bike> loadedBikes = sessionForLoadingAndUpdate.loadAll(Bike.class);
assertThat(loadedBikes).hasSize(2).extracting(Bike::isDamaged).containsOnly(false);
Iterable<Bike> updatedBikes = sessionForLoadingAndUpdate.query(Bike.class, "MATCH (c:Bike) SET c.damaged = true RETURN c", Collections.emptyMap());
assertThat(updatedBikes).hasSize(2).extracting(Bike::isDamaged).containsOnly(true);
}
Aggregations