use of org.neo4j.ogm.context.MappingContext in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldBeAbleToIndicateSafeCall.
@Test
public void shouldBeAbleToIndicateSafeCall() throws NoSuchFieldException, IllegalAccessException {
// Don' think too long about that bloody mess…
MappingContext spyOnMappingContext = Mockito.spy(((Neo4jSession) session).context());
Field mappingContextField = Neo4jSession.class.getDeclaredField("mappingContext");
mappingContextField.setAccessible(true);
mappingContextField.set(session, spyOnMappingContext);
Iterable<String> results = session.query(String.class, "CALL dbms.procedures() yield name", Collections.emptyMap());
assertThat(results).isNotEmpty();
results = session.query(String.class, "CALL dbms.procedures() yield name /*+ OGM READ_ONLY */", Collections.emptyMap());
assertThat(results).isNotEmpty();
results = session.query(String.class, "CALL dbms.procedures() yield name \n/*+ OGM READ_ONLY */", Collections.emptyMap());
assertThat(results).isNotEmpty();
results = session.query(String.class, "CALL /*+ OGM READ_ONLY */ dbms.procedures() yield name", Collections.emptyMap());
assertThat(results).isNotEmpty();
Mockito.verify(spyOnMappingContext, Mockito.atMost(1)).clear();
}
use of org.neo4j.ogm.context.MappingContext in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method disposeFromMappingContextOnDeleteWithTransientRelationshipTest.
@Test
public void disposeFromMappingContextOnDeleteWithTransientRelationshipTest() {
MappingContext mappingContext = session.context();
assertThat(mappingContext.getNodeEntity(artist1.getId()).getClass() == Artist.class).isTrue();
session.delete(artist1);
// check that the mapping context does not hold a reference to the deleted entity anymore
Object object = mappingContext.getNodeEntity(artist1.getId());
assertThat(object == null).isTrue();
// check that objects with references to the deleted object have been cleared
// check for TransientRelationship, where the object connected to the deleted object holds ref in a Set
Album retrievedAlbum1 = (Album) mappingContext.getNodeEntity(album1.getId());
assertThat(retrievedAlbum1.getArtist() == null).isTrue();
Album retrievedAlbum2 = (Album) mappingContext.getNodeEntity(album2.getId());
assertThat(retrievedAlbum2.getArtist() == null).isTrue();
Album retrievedAlbum3 = (Album) mappingContext.getNodeEntity(album3.getId());
assertThat(retrievedAlbum3.getArtist() == null).isTrue();
}
use of org.neo4j.ogm.context.MappingContext in project neo4j-ogm by neo4j.
the class RequestExecutor method initialiseNewEntity.
/**
* Register entities in the {@link MappingContext}
*
* @param persisted entity created as part of the request
*/
private void initialiseNewEntity(Long identity, Object persisted) {
MappingContext mappingContext = session.context();
Transaction tx = session.getTransaction();
if (persisted != null) {
// it will be null if the variable represents a simple relationship.
// set the id field of the newly created domain object
EntityUtils.setIdentity(persisted, identity, session.metaData());
ClassInfo classInfo = session.metaData().classInfo(persisted);
if (tx != null) {
((AbstractTransaction) tx).registerNew(persisted);
}
registerEntity(mappingContext, classInfo, identity, persisted);
}
}
use of org.neo4j.ogm.context.MappingContext in project neo4j-ogm by neo4j.
the class DirectRelationshipsTest method setUpTestDatabase.
@BeforeClass
public static void setUpTestDatabase() {
mappingMetadata = new MetaData("org.neo4j.ogm.domain.filesystem");
mappingContext = new MappingContext(mappingMetadata);
}
use of org.neo4j.ogm.context.MappingContext in project neo4j-ogm by neo4j.
the class CompilerTest method setUpTestDatabase.
@BeforeClass
public static void setUpTestDatabase() {
mappingMetadata = new MetaData("org.neo4j.ogm.domain.education", "org.neo4j.ogm.domain.forum", "org.neo4j.ogm.domain.social", "org.neo4j.domain.policy", "org.neo4j.ogm.domain.music", "org.neo4j.ogm.domain.restaurant", "org.neo4j.ogm.domain.travel");
mappingContext = new MappingContext(mappingMetadata);
}
Aggregations