Search in sources :

Example 21 with Artist

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);
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) EntityGraphMapper(org.neo4j.ogm.context.EntityGraphMapper) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Album(org.neo4j.ogm.domain.music.Album) CompileContext(org.neo4j.ogm.cypher.compiler.CompileContext) Test(org.junit.Test)

Example 22 with Artist

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);
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Album(org.neo4j.ogm.domain.music.Album) Recording(org.neo4j.ogm.domain.music.Recording) Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Studio(org.neo4j.ogm.domain.music.Studio) Before(org.junit.Before)

Example 23 with Artist

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);
}
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)

Example 24 with Artist

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();
}
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 25 with Artist

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);
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Test(org.junit.Test)

Aggregations

Artist (org.neo4j.ogm.domain.music.Artist)33 Test (org.junit.Test)29 Album (org.neo4j.ogm.domain.music.Album)27 Recording (org.neo4j.ogm.domain.music.Recording)19 Studio (org.neo4j.ogm.domain.music.Studio)19 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)11 Session (org.neo4j.ogm.session.Session)8 Before (org.junit.Before)4 List (java.util.List)3 Filter (org.neo4j.ogm.cypher.Filter)3 SessionFactory (org.neo4j.ogm.session.SessionFactory)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MappingContext (org.neo4j.ogm.context.MappingContext)2 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)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