Search in sources :

Example 6 with Knows

use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.

the class SessionAndMappingContextTest method shouldRollbackRelationshipEntityWithDifferentStartAndEndNodes.

@Test
public void shouldRollbackRelationshipEntityWithDifferentStartAndEndNodes() {
    Actor mary = new Actor("Mary");
    Actor john = new Actor("John");
    Knows maryKnowsJohn = new Knows();
    maryKnowsJohn.setFirstActor(mary);
    maryKnowsJohn.setSecondActor(john);
    try (Transaction tx = session.beginTransaction()) {
        session.save(maryKnowsJohn);
        assertThat(mary.getUuid()).isNotNull();
        assertThat(maryKnowsJohn.id).isNotNull();
        assertThat(john.getUuid()).isNotNull();
        tx.rollback();
        assertThat(mary.getUuid()).isNull();
        assertThat(maryKnowsJohn.id).isNull();
        assertThat(john.getUuid()).isNull();
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Test(org.junit.Test)

Example 7 with Knows

use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.

the class CineastsRelationshipEntityTest method shouldSaveRelationshipEntityWithCamelCaseStartEndNodes.

// DATAGRAPH-567
@Test
public void shouldSaveRelationshipEntityWithCamelCaseStartEndNodes() {
    Actor bruce = new Actor("Bruce");
    Actor jim = new Actor("Jim");
    Knows knows = new Knows();
    knows.setFirstActor(bruce);
    knows.setSecondActor(jim);
    knows.setSince(new Date());
    bruce.getKnows().add(knows);
    session.save(bruce);
    Actor actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
    assertThat(actor).isNotNull();
    assertThat(actor.getKnows()).hasSize(1);
    assertThat(actor.getKnows().iterator().next().getSecondActor().getName()).isEqualTo("Jim");
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Date(java.util.Date) Test(org.junit.Test)

Example 8 with Knows

use of org.neo4j.ogm.domain.cineasts.annotated.Knows in project neo4j-ogm by neo4j.

the class CineastsRelationshipEntityTest method shouldSaveRelationshipEntityWithNullProperty.

// DATAGRAPH-610
@Test
public void shouldSaveRelationshipEntityWithNullProperty() {
    Actor bruce = new Actor("Bruce");
    Actor jim = new Actor("Jim");
    // since = null
    Knows knows = new Knows();
    knows.setFirstActor(bruce);
    knows.setSecondActor(jim);
    bruce.getKnows().add(knows);
    session.save(bruce);
    Actor actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
    assertThat(actor).isNotNull();
    assertThat(actor.getKnows()).hasSize(1);
    assertThat(actor.getKnows().iterator().next().getSecondActor().getName()).isEqualTo("Jim");
    bruce.getKnows().iterator().next().setSince(new Date());
    session.save(bruce);
    actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
    assertThat(actor.getKnows()).hasSize(1);
    assertThat(actor.getKnows().iterator().next().getSince()).isNotNull();
    bruce.getKnows().iterator().next().setSince(null);
    session.save(bruce);
    actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
    assertThat(actor.getKnows()).hasSize(1);
    assertThat(actor.getKnows().iterator().next().getSince()).isNull();
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Knows

use of org.neo4j.ogm.domain.cineasts.annotated.Knows 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)

Aggregations

Knows (org.neo4j.ogm.domain.cineasts.annotated.Knows)9 Test (org.junit.Test)7 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)6 Date (java.util.Date)4 Filter (org.neo4j.ogm.cypher.Filter)3 Before (org.junit.Before)2 Document (org.neo4j.ogm.domain.filesystem.Document)1 Folder (org.neo4j.ogm.domain.filesystem.Folder)1 Album (org.neo4j.ogm.domain.music.Album)1 Artist (org.neo4j.ogm.domain.music.Artist)1 Recording (org.neo4j.ogm.domain.music.Recording)1 Studio (org.neo4j.ogm.domain.music.Studio)1 Result (org.neo4j.ogm.model.Result)1 PostSaveEvent (org.neo4j.ogm.session.event.PostSaveEvent)1 PreSaveEvent (org.neo4j.ogm.session.event.PreSaveEvent)1 Transaction (org.neo4j.ogm.transaction.Transaction)1