Search in sources :

Example 16 with Recording

use of org.neo4j.ogm.domain.music.Recording in project neo4j-ogm by neo4j.

the class GraphIdCapabilityTest method init.

@Before
public void init() throws IOException {
    SessionFactory sessionFactory = new SessionFactory(getDriver(), "org.neo4j.ogm.domain.music");
    session = sessionFactory.openSession();
    session.purgeDatabase();
    // Create some data
    theBeatles = new Artist("The Beatles");
    please = new Album("Please Please Me");
    theBeatles.getAlbums().add(please);
    please.setArtist(theBeatles);
    session.save(theBeatles);
    Studio studio = new Studio("EMI Studios, London");
    recording = new Recording(please, studio, 1963);
    please.setRecording(recording);
    session.save(recording);
    pleaseId = please.getId();
    beatlesId = theBeatles.getId();
    recordingId = recording.getId();
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Before(org.junit.Before)

Example 17 with Recording

use of org.neo4j.ogm.domain.music.Recording in project neo4j-ogm by neo4j.

the class GraphIdCapabilityTest method idShouldReturnNullForEntitiesNotPersisted.

/**
 * @see DATAGRAPH-694
 */
@Test
public void idShouldReturnNullForEntitiesNotPersisted() {
    Album revolver = new Album("Revolver");
    assertThat(session.resolveGraphIdFor(revolver)).isNull();
    Recording revolverRecording = new Recording(revolver, new Studio(), 1966);
    assertThat(session.resolveGraphIdFor(revolverRecording)).isNull();
}
Also used : 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)

Example 18 with Recording

use of org.neo4j.ogm.domain.music.Recording in project neo4j-ogm by neo4j.

the class LoadCapabilityTest method shouldAddRelationshipsWhenDepthIsIncreased.

// DATAGRAPH-642, GH-174
@Test
public void shouldAddRelationshipsWhenDepthIsIncreased() {
    Artist led = new Artist("Led Zeppelin");
    Album album = new Album("Led Zeppelin IV");
    Studio studio = new Studio("Island Studios");
    Recording recording = new Recording(album, studio, 1970);
    led.addAlbum(album);
    album.setArtist(led);
    album.setRecording(recording);
    session.save(led);
    session.clear();
    // Load to depth 0
    Artist ledZeppelin = session.load(Artist.class, led.getId(), 0);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).isEmpty();
    // Load to depth 1
    ledZeppelin = session.load(Artist.class, led.getId(), 1);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(1);
    Album ledZeppelinIV = ledZeppelin.getAlbums().iterator().next();
    assertThat(ledZeppelinIV.getName()).isEqualTo(album.getName());
    assertThat(ledZeppelinIV.getArtist()).isEqualTo(ledZeppelin);
    assertThat(ledZeppelinIV.getRecording()).isNull();
    // Load to depth 2
    ledZeppelin = session.load(Artist.class, led.getId(), 2);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(1);
    ledZeppelinIV = ledZeppelin.getAlbums().iterator().next();
    assertThat(ledZeppelinIV.getName()).isEqualTo(album.getName());
    assertThat(ledZeppelinIV.getArtist()).isEqualTo(ledZeppelin);
    assertThat(ledZeppelinIV.getRecording()).isNotNull();
    assertThat(ledZeppelinIV.getRecording().getStudio().getName()).isEqualTo(studio.getName());
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) 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)

Example 19 with Recording

use of org.neo4j.ogm.domain.music.Recording in project neo4j-ogm by neo4j.

the class LoadCapabilityTest method shouldRetainPreviouslyLoadedRelationshipsWhenDepthIsReduced.

// DATAGRAPH-642, GH-174
@Test
public void shouldRetainPreviouslyLoadedRelationshipsWhenDepthIsReduced() {
    Artist led = new Artist("Led Zeppelin");
    Album album = new Album("Led Zeppelin IV");
    Studio studio = new Studio("Island Studios");
    Recording recording = new Recording(album, studio, 1970);
    led.addAlbum(album);
    album.setArtist(led);
    album.setRecording(recording);
    session.save(led);
    session.clear();
    // Load Artist to depth 2
    Artist ledZeppelin = session.load(Artist.class, led.getId(), 2);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(1);
    Album ledZeppelinIV = ledZeppelin.getAlbums().iterator().next();
    assertThat(ledZeppelinIV.getName()).isEqualTo(album.getName());
    assertThat(ledZeppelinIV.getArtist()).isEqualTo(ledZeppelin);
    assertThat(ledZeppelinIV.getRecording()).isNotNull();
    assertThat(ledZeppelinIV.getRecording().getStudio().getName()).isEqualTo(studio.getName());
    // Now load to depth 1
    ledZeppelin = session.load(Artist.class, led.getId(), 0);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(1);
    ledZeppelinIV = ledZeppelin.getAlbums().iterator().next();
    assertThat(ledZeppelinIV.getName()).isEqualTo(album.getName());
    assertThat(ledZeppelinIV.getArtist()).isEqualTo(ledZeppelin);
    assertThat(ledZeppelinIV.getRecording()).isNotNull();
    assertThat(ledZeppelinIV.getRecording().getStudio().getName()).isEqualTo(studio.getName());
    // Now load to depth 0
    ledZeppelin = session.load(Artist.class, led.getId(), 0);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(1);
    ledZeppelinIV = ledZeppelin.getAlbums().iterator().next();
    assertThat(ledZeppelinIV.getName()).isEqualTo(album.getName());
    assertThat(ledZeppelinIV.getArtist()).isEqualTo(ledZeppelin);
    assertThat(ledZeppelinIV.getRecording()).isNotNull();
    assertThat(ledZeppelinIV.getRecording().getStudio().getName()).isEqualTo(studio.getName());
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) 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)

Example 20 with Recording

use of org.neo4j.ogm.domain.music.Recording 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

Album (org.neo4j.ogm.domain.music.Album)21 Recording (org.neo4j.ogm.domain.music.Recording)21 Studio (org.neo4j.ogm.domain.music.Studio)21 Test (org.junit.Test)19 Artist (org.neo4j.ogm.domain.music.Artist)19 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)8 Session (org.neo4j.ogm.session.Session)7 Filter (org.neo4j.ogm.cypher.Filter)3 List (java.util.List)2 Map (java.util.Map)2 Before (org.junit.Before)2 Transaction (org.neo4j.ogm.transaction.Transaction)2 MappingContext (org.neo4j.ogm.context.MappingContext)1 Filters (org.neo4j.ogm.cypher.Filters)1 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)1 Knows (org.neo4j.ogm.domain.cineasts.annotated.Knows)1 SessionFactory (org.neo4j.ogm.session.SessionFactory)1