Search in sources :

Example 1 with MappingContext

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();
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) Field(java.lang.reflect.Field) Test(org.junit.Test)

Example 2 with MappingContext

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

Example 3 with MappingContext

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);
    }
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) AbstractTransaction(org.neo4j.ogm.transaction.AbstractTransaction) Transaction(org.neo4j.ogm.transaction.Transaction) AbstractTransaction(org.neo4j.ogm.transaction.AbstractTransaction) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 4 with MappingContext

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);
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) MetaData(org.neo4j.ogm.metadata.MetaData) BeforeClass(org.junit.BeforeClass)

Example 5 with MappingContext

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);
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) MetaData(org.neo4j.ogm.metadata.MetaData) BeforeClass(org.junit.BeforeClass)

Aggregations

MappingContext (org.neo4j.ogm.context.MappingContext)13 Test (org.junit.Test)5 MetaData (org.neo4j.ogm.metadata.MetaData)5 BeforeClass (org.junit.BeforeClass)4 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)4 EntityGraphMapper (org.neo4j.ogm.context.EntityGraphMapper)2 Album (org.neo4j.ogm.domain.music.Album)2 Artist (org.neo4j.ogm.domain.music.Artist)2 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)2 Transaction (org.neo4j.ogm.transaction.Transaction)2 Serializable (java.io.Serializable)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Before (org.junit.Before)1