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();
}
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();
}
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();
}
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();
}
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");
}
Aggregations