Search in sources :

Example 1 with EntityGraphMapper

use of org.neo4j.ogm.context.EntityGraphMapper in project neo4j-ogm by neo4j.

the class SaveDelegate method save.

public <T> void save(T object, int depth) {
    SaveEventDelegate eventsDelegate = new SaveEventDelegate(session);
    EntityGraphMapper entityGraphMapper = new EntityGraphMapper(session.metaData(), session.context());
    if (this.writeProtectionStrategy != null) {
        entityGraphMapper.addWriteProtection(this.writeProtectionStrategy.get());
    }
    Iterable<T> objects;
    if (object.getClass().isArray()) {
        int length = Array.getLength(object);
        List<T> copy = new ArrayList<>(length);
        for (int i = 0; i < length; i++) {
            T arrayElement = (T) Array.get(object, i);
            copy.add(arrayElement);
        }
        objects = copy;
    } else if (Iterable.class.isAssignableFrom(object.getClass())) {
        objects = (Iterable<T>) object;
    } else if (session.metaData().classInfo(object) != null) {
        objects = Collections.singletonList(object);
    } else {
        throw new IllegalArgumentException("Class " + object.getClass() + " is not a valid entity class. " + "Please check the entity mapping.");
    }
    if (session.eventsEnabled()) {
        objects.forEach(item -> {
            eventsDelegate.preSave(item);
            entityGraphMapper.map(item, depth);
        });
        requestExecutor.executeSave(entityGraphMapper.compileContext());
        eventsDelegate.postSave();
    } else {
        objects.forEach(item -> entityGraphMapper.map(item, depth));
        requestExecutor.executeSave(entityGraphMapper.compileContext());
    }
}
Also used : EntityGraphMapper(org.neo4j.ogm.context.EntityGraphMapper) ArrayList(java.util.ArrayList)

Example 2 with EntityGraphMapper

use of org.neo4j.ogm.context.EntityGraphMapper in project neo4j-ogm by neo4j.

the class CompilerTest method mapAndCompile.

private static Compiler mapAndCompile(Object object, int depth) {
    EntityMapper mapper = new EntityGraphMapper(mappingMetadata, mappingContext);
    CompileContext context = mapper.map(object, depth);
    Compiler compiler = context.getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    return compiler;
}
Also used : EntityGraphMapper(org.neo4j.ogm.context.EntityGraphMapper) RowStatementFactory(org.neo4j.ogm.session.request.RowStatementFactory) EntityMapper(org.neo4j.ogm.context.EntityMapper)

Example 3 with EntityGraphMapper

use of org.neo4j.ogm.context.EntityGraphMapper in project neo4j-ogm by neo4j.

the class MergeWithPrimaryIndexTests method setUpMapper.

@Before
public void setUpMapper() {
    mappingContext = new MappingContext(mappingMetadata);
    this.mapper = new EntityGraphMapper(mappingMetadata, mappingContext);
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) EntityGraphMapper(org.neo4j.ogm.context.EntityGraphMapper) Before(org.junit.Before)

Example 4 with EntityGraphMapper

use of org.neo4j.ogm.context.EntityGraphMapper in project neo4j-ogm by neo4j.

the class CyclicStructureTest method mapAndCompile.

private static Compiler mapAndCompile(Neo4jSession session, Object object, int depth) {
    final MetaData metaData = session.metaData();
    final MappingContext mappingContext = new MappingContext(metaData);
    EntityMapper mapper = new EntityGraphMapper(metaData, mappingContext);
    CompileContext context = mapper.map(object, depth);
    Compiler compiler = context.getCompiler();
    compiler.useStatementFactory(new RowStatementFactory());
    return compiler;
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) EntityGraphMapper(org.neo4j.ogm.context.EntityGraphMapper) MetaData(org.neo4j.ogm.metadata.MetaData) RowStatementFactory(org.neo4j.ogm.session.request.RowStatementFactory) EntityMapper(org.neo4j.ogm.context.EntityMapper)

Example 5 with EntityGraphMapper

use of org.neo4j.ogm.context.EntityGraphMapper in project neo4j-ogm by neo4j.

the class EntityGraphMapperTest method setUpMapper.

@Before
public void setUpMapper() {
    sessionFactory = new SessionFactory(getDriver(), "org.neo4j.ogm.domain.policy", "org.neo4j.ogm.domain.election", "org.neo4j.ogm.domain.forum", "org.neo4j.ogm.domain.education", "org.neo4j.ogm.domain.types", "org.neo4j.ogm.persistence.examples.versioned_rel_entity");
    mappingContext.clear();
    this.mapper = new EntityGraphMapper(mappingMetadata, mappingContext);
    session = sessionFactory.openSession();
    session.purgeDatabase();
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) EntityGraphMapper(org.neo4j.ogm.context.EntityGraphMapper) Before(org.junit.Before)

Aggregations

EntityGraphMapper (org.neo4j.ogm.context.EntityGraphMapper)7 RowStatementFactory (org.neo4j.ogm.session.request.RowStatementFactory)3 Before (org.junit.Before)2 Test (org.junit.Test)2 EntityMapper (org.neo4j.ogm.context.EntityMapper)2 MappingContext (org.neo4j.ogm.context.MappingContext)2 ArrayList (java.util.ArrayList)1 MappedRelationship (org.neo4j.ogm.context.MappedRelationship)1 CompileContext (org.neo4j.ogm.cypher.compiler.CompileContext)1 Compiler (org.neo4j.ogm.cypher.compiler.Compiler)1 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 MetaData (org.neo4j.ogm.metadata.MetaData)1 Statement (org.neo4j.ogm.request.Statement)1 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)1 SessionFactory (org.neo4j.ogm.session.SessionFactory)1