use of org.neo4j.ogm.context.MappingContext in project neo4j-ogm by neo4j.
the class EntityGraphMapperTest method setUpTestDatabase.
@BeforeClass
public static void setUpTestDatabase() {
mappingMetadata = new MetaData("org.neo4j.ogm.domain.education", "org.neo4j.ogm.domain.forum", "org.neo4j.ogm.domain.social", "org.neo4j.ogm.domain.policy");
mappingContext = new MappingContext(mappingMetadata);
}
use of org.neo4j.ogm.context.MappingContext in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldNotBeDirtyOnLoadEntityThenSaveThenReload.
// GH-177
@Test
public void shouldNotBeDirtyOnLoadEntityThenSaveThenReload() {
MappingContext context = ((Neo4jSession) session).context();
Artist pinkFloyd = new Artist("Pink Floyd");
// new object not saved is always dirty
assertThat(context.isDirty(pinkFloyd)).isTrue();
session.save(pinkFloyd);
// object hash updated by save.
assertThat(context.isDirty(pinkFloyd)).isFalse();
// forget everything we've done
session.clear();
pinkFloyd = session.load(Artist.class, pinkFloyd.getId());
// a freshly loaded object is never dirty
assertThat(context.isDirty(pinkFloyd)).isFalse();
pinkFloyd.setName("Purple Floyd");
// we changed the name so it is now dirty
assertThat(context.isDirty(pinkFloyd)).isTrue();
session.save(pinkFloyd);
// object saved, no longer dirty
assertThat(context.isDirty(pinkFloyd)).isFalse();
// load the same identity, but to a copy ref
Artist purpleFloyd = session.load(Artist.class, pinkFloyd.getId());
// nothing has changed, so it should not be dirty
assertThat(context.isDirty(purpleFloyd)).isFalse();
// two refs pointing to the same object
assertThat(pinkFloyd == purpleFloyd).isTrue();
}
use of org.neo4j.ogm.context.MappingContext in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldNotBeDirtyOnLoadRelationshipEntityThenSaveThenReload.
// GH-177
@Test
public void shouldNotBeDirtyOnLoadRelationshipEntityThenSaveThenReload() {
MappingContext context = ((Neo4jSession) session).context();
Artist pinkFloyd = new Artist("Pink Floyd");
Album divisionBell = new Album("The Division Bell");
divisionBell.setArtist(pinkFloyd);
Studio studio = new Studio("Britannia Row Studios");
Recording recording = new Recording(divisionBell, studio, 1994);
divisionBell.setRecording(recording);
pinkFloyd.addAlbum(divisionBell);
// new object not saved is always dirty
assertThat(context.isDirty(recording)).isTrue();
session.save(recording);
// object hash updated by save.
assertThat(context.isDirty(recording)).isFalse();
// forget everything we've done
session.clear();
recording = session.load(Recording.class, recording.getId(), 2);
// a freshly loaded object is never dirty
assertThat(context.isDirty(recording)).isFalse();
recording.setYear(1995);
// we changed the year so it is now dirty
assertThat(context.isDirty(recording)).isTrue();
session.save(recording);
// object saved, no longer dirty
assertThat(context.isDirty(recording)).isFalse();
Recording recording1995 = session.load(Recording.class, recording.getId(), // load the same identity, but to a copy ref
2);
// nothing has changed, so it should not be dirty
assertThat(context.isDirty(recording1995)).isFalse();
// two refs pointing to the same object
assertThat(recording == recording1995).isTrue();
}
Aggregations