Search in sources :

Example 6 with Album

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

the class LoadCapabilityTest method shouldMapNewNodesAndRelationshipsWhenEntityIsReloaded.

// GH-173
@Test
public void shouldMapNewNodesAndRelationshipsWhenEntityIsReloaded() {
    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 the Artist to depth 2 in the first session
    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());
    // In session 2, add an album and recording
    Session session2 = sessionFactory.openSession();
    Artist ledZepp = session2.load(Artist.class, led.getId());
    Album houses = new Album("Houses of the Holy");
    Studio studio2 = new Studio("Island Studios");
    Recording housesRec = new Recording(houses, studio2, 1972);
    ledZepp.addAlbum(houses);
    houses.setArtist(ledZepp);
    houses.setRecording(housesRec);
    session2.save(ledZepp);
    // Reload the artist in the first session
    ledZeppelin = session.load(Artist.class, led.getId(), 2);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).hasSize(2);
    for (Album loadedAlbum : ledZeppelin.getAlbums()) {
        assertThat(loadedAlbum.getArtist()).isEqualTo(ledZeppelin);
        assertThat(loadedAlbum.getRecording()).isNotNull();
        assertThat(loadedAlbum.getRecording().getStudio()).isNotNull();
    }
}
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) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 7 with Album

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

the class LoadCapabilityTest method shouldNotModifyPreviouslyLoadedNodesWhenDepthIsReduced.

// GH-173
@Test
public void shouldNotModifyPreviouslyLoadedNodesWhenDepthIsReduced() {
    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 the Artist to depth 1 in the first session
    Artist 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();
    // In session 2, update the name of the artist
    Session session2 = sessionFactory.openSession();
    Artist ledZepp = session2.load(Artist.class, led.getId(), 0);
    ledZepp.setName("Led Zepp");
    session2.save(ledZepp);
    // Back in the first session, load the artist 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);
}
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) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 8 with Album

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

the class LoadCapabilityTest method shouldNotModifyPreviouslyLoadedNodesWhenEntityIsReloaded.

// GH-173
@Test
public void shouldNotModifyPreviouslyLoadedNodesWhenEntityIsReloaded() {
    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 the Artist to depth 1 in the first session
    Artist 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();
    // In session 2, update the name of the artist
    Session session2 = sessionFactory.openSession();
    Artist ledZepp = session2.load(Artist.class, led.getId(), 0);
    ledZepp.setName("Led Zepp");
    session2.save(ledZepp);
    // Reload the artist in the first session
    ledZeppelin = session.load(Artist.class, led.getId(), 1);
    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()).isNull();
}
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) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 9 with Album

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

the class LoadCapabilityTest method shouldBeAbleToLoadEntitiesToDifferentDepthsInDifferentSessions.

// GH-170
@Test
public void shouldBeAbleToLoadEntitiesToDifferentDepthsInDifferentSessions() {
    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);
    session.save(pinkFloyd);
    session.clear();
    // Load Pink Floyd to depth 1 in a new session
    Session session1 = sessionFactory.openSession();
    Artist pinkfloyd1 = session1.load(Artist.class, pinkFloyd.getId(), 1);
    assertThat(pinkfloyd1).isNotNull();
    assertThat(pinkfloyd1.getAlbums()).hasSize(1);
    assertThat(pinkfloyd1.getAlbums().iterator().next().getRecording()).isNull();
    // Load Pink Floyd to depth -1 in a new session
    Session session2 = sessionFactory.openSession();
    Artist pinkfloyd2 = session2.load(Artist.class, pinkFloyd.getId(), -1);
    assertThat(pinkfloyd2).isNotNull();
    assertThat(pinkfloyd2.getAlbums()).hasSize(1);
    assertThat(pinkfloyd2.getAlbums().iterator().next().getRecording()).isNotNull();
    // Load Pink Floyd to depth -1 in an existing session which has loaded it to depth 1 previously
    Artist pinkfloyd_1_1 = session1.load(Artist.class, pinkFloyd.getId(), -1);
    assertThat(pinkfloyd_1_1).isNotNull();
    assertThat(pinkfloyd_1_1.getAlbums()).hasSize(1);
    assertThat(pinkfloyd2.getAlbums().iterator().next().getRecording()).isNotNull();
}
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) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 10 with Album

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

the class LoadCapabilityTest method shouldRefreshEntityStateWhenReloadedOnCleanSession.

// GH-173
@Test
public void shouldRefreshEntityStateWhenReloadedOnCleanSession() {
    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 the Artist to depth 1 in the first session
    Artist 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();
    // In session 2, update the name of the artist, delete the album
    Session session2 = sessionFactory.openSession();
    Artist ledZepp = session2.load(Artist.class, led.getId(), 1);
    ledZepp.setName("Led Zepp");
    ledZepp.getAlbums().iterator().next().setArtist(null);
    ledZepp.getAlbums().clear();
    session2.save(ledZepp);
    // Reload the artist in a clean session
    session.clear();
    ledZeppelin = session.load(Artist.class, led.getId(), 1);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(ledZepp.getName());
    assertThat(ledZeppelin.getAlbums()).isEmpty();
}
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) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Aggregations

Album (org.neo4j.ogm.domain.music.Album)33 Test (org.junit.Test)30 Artist (org.neo4j.ogm.domain.music.Artist)27 Recording (org.neo4j.ogm.domain.music.Recording)21 Studio (org.neo4j.ogm.domain.music.Studio)21 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)9 Session (org.neo4j.ogm.session.Session)7 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Before (org.junit.Before)3 Filter (org.neo4j.ogm.cypher.Filter)3 Map (java.util.Map)2 MappingContext (org.neo4j.ogm.context.MappingContext)2 SessionFactory (org.neo4j.ogm.session.SessionFactory)2 Transaction (org.neo4j.ogm.transaction.Transaction)2 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1 Date (java.util.Date)1 EntityGraphMapper (org.neo4j.ogm.context.EntityGraphMapper)1 Filters (org.neo4j.ogm.cypher.Filters)1