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());
}
}
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;
}
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);
}
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;
}
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();
}
Aggregations