use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class SaveCapabilityTest method shouldSaveOnlyModifiedNodes.
@Test
public void shouldSaveOnlyModifiedNodes() {
int depth = 1;
Neo4jSession neo4jSession = (Neo4jSession) session;
CompileContext context = null;
Artist leann = new Artist("Leann Rimes");
Album lost = new Album("Lost Highway");
lost.setArtist(bonJovi);
lost.setGuestArtist(leann);
context = new EntityGraphMapper(neo4jSession.metaData(), neo4jSession.context()).map(lost, depth);
assertThat(context.registry()).as("Should save 3 nodes and 2 relations (5 items)").hasSize(5);
session.save(lost);
context = new EntityGraphMapper(neo4jSession.metaData(), neo4jSession.context()).map(lost, depth);
assertThat(context.registry()).as("Should have nothing to save").isEmpty();
session.clear();
Artist loadedLeann = session.load(Artist.class, leann.getId(), depth);
context = new EntityGraphMapper(neo4jSession.metaData(), neo4jSession.context()).map(loadedLeann, depth);
assertThat(context.registry()).as("Should have nothing to save").isEmpty();
loadedLeann.setName("New name");
context = new EntityGraphMapper(neo4jSession.metaData(), neo4jSession.context()).map(loadedLeann, depth);
assertThat(context.registry()).as("Should have one node to save").hasSize(1);
loadedLeann.getGuestAlbums().iterator().next().setName("New Album Name");
context = new EntityGraphMapper(neo4jSession.metaData(), neo4jSession.context()).map(loadedLeann, depth);
assertThat(context.registry()).as("Should have two node to save").hasSize(2);
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method init.
@Before
public void init() throws IOException {
session = (Neo4jSession) sessionFactory.openSession();
artist1 = new Artist();
artist1.setName("MainArtist");
Artist artist2 = new Artist();
artist2.setName("GuestArtist");
album1 = new Album();
album1.setName("First");
album1.setGuestArtist(artist2);
album2 = new Album();
album2.setName("Second");
album3 = new Album();
album3.setName("Third");
artist1.addAlbum(album1);
artist1.addAlbum(album2);
artist1.addAlbum(album3);
Studio studio = new Studio();
studio.setName("Studio");
Recording recording = new Recording();
recording.setAlbum(album1);
recording.setAlbum(album2);
recording.setAlbum(album3);
recording.setStudio(studio);
recording.setYear(2001);
session.save(artist1);
actor1 = new Actor("Actor1");
actor2 = new Actor("Actor2");
knows = new Knows();
knows.setFirstActor(actor1);
knows.setSecondActor(actor2);
actor1.knows.add(knows);
session.save(actor1);
Actor actor3 = new Actor("Actor3");
Actor actor4 = new Actor("Actor4");
knows2 = new Knows();
knows2.setFirstActor(actor3);
knows2.setSecondActor(actor4);
actor3.knows.add(knows2);
session.save(actor3);
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class TransactionTest method shouldNotCommitWhenTransactionIsManaged.
@Test
public void shouldNotCommitWhenTransactionIsManaged() {
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);
// the previous saves shouldn't have been committed
tx.rollback();
assertThat(session.countEntitiesOfType(Artist.class)).isEqualTo(0);
}
use of org.neo4j.ogm.domain.music.Artist 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();
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method loadAllByInstancesShouldSortByIdsIfSortOrderIsNotProvided.
@Test
public void loadAllByInstancesShouldSortByIdsIfSortOrderIsNotProvided() throws Exception {
Artist beatles = session.load(Artist.class, beatlesId);
Artist led = new Artist("Led Zeppelin");
session.save(led);
Artist bonJovi = new Artist("Bon Jovi");
session.save(bonJovi);
Long ledId = led.getId();
Long bonJoviId = bonJovi.getId();
Collection<Artist> artists;
artists = session.loadAll(Arrays.asList(beatles, led, bonJovi));
assertThat(artists).containsExactly(beatles, led, bonJovi);
artists = session.loadAll(Arrays.asList(led, beatles, bonJovi));
assertThat(artists).containsExactly(led, beatles, bonJovi);
artists = session.loadAll(Arrays.asList(led, bonJovi, beatles));
assertThat(artists).containsExactly(led, bonJovi, beatles);
}
Aggregations