use of org.neo4j.ogm.domain.music.Artist 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.Artist in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldNotRefreshPropertiesOnEntityReload.
@Test
public void shouldNotRefreshPropertiesOnEntityReload() {
Artist pinkFloyd = new Artist("Pink Floyd");
session.save(pinkFloyd);
session.clear();
// Load Pink Floyd in a new session, session1
Session session1 = sessionFactory.openSession();
Artist pinkfloyd1 = session1.load(Artist.class, pinkFloyd.getId(), 1);
assertThat(pinkfloyd1).isNotNull();
assertThat(pinkfloyd1.getName()).isEqualTo("Pink Floyd");
// Load Pink Floyd to in another new session, session2
Session session2 = sessionFactory.openSession();
Artist pinkfloyd2 = session2.load(Artist.class, pinkFloyd.getId(), -1);
assertThat(pinkfloyd2).isNotNull();
assertThat(pinkfloyd2.getName()).isEqualTo("Pink Floyd");
// update the name property
pinkfloyd2.setName("Purple Floyd");
// and save it in session2. Now the name in the graph is Purple Floyd
session2.save(pinkfloyd2);
// Reload Pink Floyd in session1
Artist pinkfloyd_1_1 = session1.load(Artist.class, pinkFloyd.getId(), -1);
assertThat(pinkfloyd_1_1).isNotNull();
// the name should be refreshed from the graph
assertThat(pinkfloyd_1_1.getName()).isEqualTo("Pink Floyd");
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class LoadCapabilityTest method shouldMaintainSortOrderWhenLoadingByIds.
// GH-302
@Test
public void shouldMaintainSortOrderWhenLoadingByIds() {
Artist led = new Artist("Led Zeppelin");
session.save(led);
Artist bonJovi = new Artist("Bon Jovi");
session.save(bonJovi);
List<Long> ids = Arrays.asList(beatlesId, led.getId(), bonJovi.getId());
SortOrder sortOrder = new SortOrder();
sortOrder.add(SortOrder.Direction.ASC, "name");
Iterable<Artist> artists = session.loadAll(Artist.class, ids, sortOrder);
assertThat(artists).isNotNull();
List<String> artistNames = new ArrayList<>();
for (Artist artist : artists) {
artistNames.add(artist.getName());
}
assertThat(artistNames.get(0)).isEqualTo("Bon Jovi");
assertThat(artistNames.get(1)).isEqualTo("Led Zeppelin");
assertThat(artistNames.get(2)).isEqualTo("The Beatles");
sortOrder = new SortOrder();
sortOrder.add(SortOrder.Direction.DESC, "name");
artists = session.loadAll(Artist.class, ids, sortOrder);
assertThat(artists).isNotNull();
artistNames = new ArrayList<>();
for (Artist artist : artists) {
artistNames.add(artist.getName());
}
assertThat(artistNames.get(0)).isEqualTo("The Beatles");
assertThat(artistNames.get(1)).isEqualTo("Led Zeppelin");
assertThat(artistNames.get(2)).isEqualTo("Bon Jovi");
}
use of org.neo4j.ogm.domain.music.Artist 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");
}
use of org.neo4j.ogm.domain.music.Artist in project neo4j-ogm by neo4j.
the class CompilerTest method createSimpleRelationshipWithIllegalCharactersBetweenObjects.
// DATAGRAPH-589
@Test
public void createSimpleRelationshipWithIllegalCharactersBetweenObjects() {
Artist theBeatles = new Artist("The Beatles");
Album please = new Album("Please Please Me");
theBeatles.getAlbums().add(please);
please.setArtist(theBeatles);
Compiler compiler = mapAndCompile(theBeatles, -1);
List<Statement> statements = compiler.createNodesStatements();
assertThat(statements).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row CREATE (n:`l'artiste`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, $type as type", "UNWIND $rows as row CREATE (n:`l'album`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, $type as type");
for (Statement statement : statements) {
List rows = (List) statement.getParameters().get("rows");
assertThat(rows).hasSize(1);
}
statements = compiler.createRelationshipsStatements();
assertThat(statements).extracting(Statement::getStatement).containsOnly("UNWIND $rows as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId WITH row,startNode MATCH (endNode) WHERE ID(endNode) = row.endNodeId MERGE (startNode)-[rel:`HAS-ALBUM`]->(endNode) RETURN row.relRef as ref, ID(rel) as id, $type as type");
for (Statement statement : statements) {
List rows = (List) statement.getParameters().get("rows");
assertThat(rows).hasSize(1);
}
}
Aggregations