Search in sources :

Example 6 with Recording

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

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

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

Example 9 with Recording

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

the class LoadCapabilityTest method shouldNotModifyPreviouslyLoadedNodesWhenDepthIsIncreased.

// GH-173
@Test
public void shouldNotModifyPreviouslyLoadedNodesWhenDepthIsIncreased() {
    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 0 in the first session
    Artist ledZeppelin = session.load(Artist.class, led.getId(), 0);
    assertThat(ledZeppelin).isNotNull();
    assertThat(ledZeppelin.getName()).isEqualTo(led.getName());
    assertThat(ledZeppelin.getAlbums()).isEmpty();
    // 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 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();
}
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 Recording

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

the class TransactionTest method shouldBeAbleToRetrySaveOnTransactionRollback.

// GH-126
@Test
public void shouldBeAbleToRetrySaveOnTransactionRollback() {
    Transaction tx = session.beginTransaction();
    Studio emi = new Studio("EMI Studios, London");
    Artist theBeatles = new Artist("The Beatles");
    Album please = new Album("Please Please Me");
    Recording pleaseRecording = new Recording(please, emi, 1963);
    please.setRecording(pleaseRecording);
    theBeatles.getAlbums().add(please);
    please.setArtist(theBeatles);
    session.save(theBeatles);
    tx.rollback();
    session.save(theBeatles);
    session.clear();
    theBeatles = session.loadAll(Artist.class, -1).iterator().next();
    assertThat(theBeatles.getName()).isEqualTo("The Beatles");
    assertThat(theBeatles.getAlbums()).hasSize(1);
    assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("Please Please Me");
    assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Transaction(org.neo4j.ogm.transaction.Transaction) 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