Search in sources :

Example 11 with Recording

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

the class MusicIntegrationTest method shouldSaveAndRetrieveArtistWithTwoRelationshipTypesToAlbums.

/**
 * @see DATAGRAPH-637
 */
@Test
public void shouldSaveAndRetrieveArtistWithTwoRelationshipTypesToAlbums() {
    Studio emi = new Studio("EMI Studios, London");
    Studio olympic = new Studio("Olympic Studios, London");
    Artist theBeatles = new Artist("The Beatles");
    Artist eric = new Artist("Eric Clapton");
    Album slowhand = new Album("Slowhand");
    Recording slowRecording = new Recording(slowhand, olympic, 1977);
    slowhand.setRecording(slowRecording);
    slowhand.setArtist(eric);
    session.save(slowhand);
    session.clear();
    Album theBeatlesAlbum = new Album("The Beatles");
    Recording pleaseRecording = new Recording(theBeatlesAlbum, emi, 1968);
    theBeatlesAlbum.setRecording(pleaseRecording);
    theBeatles.getAlbums().add(theBeatlesAlbum);
    theBeatlesAlbum.setArtist(theBeatles);
    theBeatlesAlbum.setGuestArtist(eric);
    session.save(theBeatlesAlbum);
    theBeatles = session.loadAll(Artist.class, new Filters().add(new Filter("name", ComparisonOperator.EQUALS, "The Beatles"))).iterator().next();
    assertThat(theBeatles.getName()).isEqualTo("The Beatles");
    assertThat(theBeatles.getAlbums()).hasSize(1);
    assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("The Beatles");
    assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
    assertThat(theBeatles.getAlbums().iterator().next().getGuestArtist()).isEqualTo(eric);
    // Eric has 2 albums now
    session.clear();
    Artist loadedEric = session.loadAll(Artist.class, new Filters().add(new Filter("name", ComparisonOperator.EQUALS, "Eric Clapton"))).iterator().next();
    assertThat(loadedEric).isNotNull();
    assertThat(loadedEric.getGuestAlbums().iterator().next().getName()).isEqualTo("The Beatles");
    assertThat(loadedEric.getAlbums().iterator().next().getName()).isEqualTo("Slowhand");
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) 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 12 with Recording

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

the class MusicIntegrationTest method shouldBeAbleToQueryForLiteralMapWithAlias.

/**
 * Issue #83
 */
@Test
public void shouldBeAbleToQueryForLiteralMapWithAlias() {
    Studio emi = new Studio("EMI Studios, London");
    Artist theBeatles = new Artist("The Beatles");
    Album theBeatlesAlbum = new Album("The Beatles");
    Recording theBeatlesRec = new Recording(theBeatlesAlbum, emi, 1968);
    theBeatlesAlbum.setRecording(theBeatlesRec);
    theBeatles.getAlbums().add(theBeatlesAlbum);
    theBeatlesAlbum.setArtist(theBeatles);
    session.save(theBeatlesAlbum);
    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);
    Iterator<Map<String, Object>> resultIterator = session.query("MATCH (n:`l'artiste`)-[:`HAS-ALBUM`]-(a) return {artist: collect(distinct n.name), albums: collect(a.name)} as result", Collections.EMPTY_MAP).queryResults().iterator();
    assertThat(resultIterator.hasNext()).isTrue();
    Map<String, Object> row = resultIterator.next();
    Map data = (Map) row.get("result");
    List<String> albums = (List<String>) data.get("albums");
    List<String> artist = (List<String>) data.get("artist");
    assertThat(artist).hasSize(1);
    assertThat(artist.get(0)).isEqualTo("The Beatles");
    assertThat(albums).hasSize(2);
    assertThat(albums.contains("The Beatles")).isTrue();
    assertThat(albums.contains("Please Please Me")).isTrue();
    assertThat(resultIterator.hasNext()).isFalse();
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) List(java.util.List) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Map(java.util.Map) Test(org.junit.Test)

Example 13 with Recording

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

the class MusicIntegrationTest method shouldBeAbleToQueryForLiteralMapWithoutAlias.

/**
 * Issue #83
 */
@Test
public void shouldBeAbleToQueryForLiteralMapWithoutAlias() {
    Studio emi = new Studio("EMI Studios, London");
    Artist theBeatles = new Artist("The Beatles");
    Album theBeatlesAlbum = new Album("The Beatles");
    Recording theBeatlesRec = new Recording(theBeatlesAlbum, emi, 1968);
    theBeatlesAlbum.setRecording(theBeatlesRec);
    theBeatles.getAlbums().add(theBeatlesAlbum);
    theBeatlesAlbum.setArtist(theBeatles);
    session.save(theBeatlesAlbum);
    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);
    Iterator<Map<String, Object>> resultIterator = session.query("MATCH (n:`l'artiste`)-[:`HAS-ALBUM`]-(a) return {artist: collect(distinct n.name), albums: collect(a.name)}", Collections.EMPTY_MAP).queryResults().iterator();
    assertThat(resultIterator.hasNext()).isTrue();
    Map<String, Object> row = resultIterator.next();
    Map data = (Map) row.get("{artist: collect(distinct n.name), albums: collect(a.name)}");
    List<String> albums = (List<String>) data.get("albums");
    List<String> artist = (List<String>) data.get("artist");
    assertThat(artist).hasSize(1);
    assertThat(artist.get(0)).isEqualTo("The Beatles");
    assertThat(albums).hasSize(2);
    assertThat(albums.contains("The Beatles")).isTrue();
    assertThat(albums.contains("Please Please Me")).isTrue();
    assertThat(resultIterator.hasNext()).isFalse();
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Album(org.neo4j.ogm.domain.music.Album) List(java.util.List) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Map(java.util.Map) Test(org.junit.Test)

Example 14 with Recording

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

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

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