Search in sources :

Example 11 with MappingContext

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);
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) MetaData(org.neo4j.ogm.metadata.MetaData) BeforeClass(org.junit.BeforeClass)

Example 12 with MappingContext

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();
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) Artist(org.neo4j.ogm.domain.music.Artist) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Test(org.junit.Test)

Example 13 with MappingContext

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();
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) Artist(org.neo4j.ogm.domain.music.Artist) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Album(org.neo4j.ogm.domain.music.Album) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Test(org.junit.Test)

Aggregations

MappingContext (org.neo4j.ogm.context.MappingContext)13 Test (org.junit.Test)5 MetaData (org.neo4j.ogm.metadata.MetaData)5 BeforeClass (org.junit.BeforeClass)4 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)4 EntityGraphMapper (org.neo4j.ogm.context.EntityGraphMapper)2 Album (org.neo4j.ogm.domain.music.Album)2 Artist (org.neo4j.ogm.domain.music.Artist)2 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)2 Transaction (org.neo4j.ogm.transaction.Transaction)2 Serializable (java.io.Serializable)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Before (org.junit.Before)1