Skip to content

Commit

Permalink
fix #56 for blueprints backend
Browse files Browse the repository at this point in the history
  • Loading branch information
gdaniel committed Jan 20, 2017
1 parent 70eb6e8 commit 6c90bb3
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,8 @@ public PersistentEObject reifyVertex(Vertex vertex, EClass eClass) {
PersistentEObject object = null;

Id id = new StringId(vertex.getId().toString());
if (isNull(eClass)) {
eClass = resolveInstanceOf(vertex);
}
try {
object = persistentObjectsCache.get(id, new PersistentEObjectCacheLoader(eClass));
object = persistentObjectsCache.get(id, new PersistentEObjectCacheLoader(vertex, eClass));
}
catch (Exception e) {
NeoLogger.error(e);
Expand Down Expand Up @@ -449,25 +446,38 @@ private void initMetaClassesIndex(List<EClass> eClassList) {
/**
* A cache loader to retrieve a {@link PersistentEObject} stored in the database.
*/
private static class PersistentEObjectCacheLoader implements Function<Id, PersistentEObject> {
private class PersistentEObjectCacheLoader implements Function<Id, PersistentEObject> {

/**
* The vertex associated with the object to retrieve.
*/
private final Vertex vertex;
/**
* The class associated with the object to retrieve.
*/
private final EClass eClass;
private EClass eClass;

/**
* Constructs a new {@code PersistentEObjectCacheLoader} with the given {@code eClass}.
*
* @param vertex the vertex associated with the object to retrieve
* @param eClass the class associated with the object to retrieve
*/
private PersistentEObjectCacheLoader(EClass eClass) {
private PersistentEObjectCacheLoader(Vertex vertex, EClass eClass) {
this.vertex = vertex;
this.eClass = eClass;
}

@Override
public PersistentEObject apply(Id id) {
PersistentEObject object;
if(isNull(eClass)) {
/*
* Use the embedded vertex to compute the eClass instead of the id to avoid
* a backend query to retrieve the vertex
*/
eClass = BlueprintsPersistenceBackend.this.resolveInstanceOf(vertex);
}
if (nonNull(eClass)) {
EObject eObject;
if (Objects.equals(eClass.getEPackage().getClass(), EPackageImpl.class)) {
Expand Down

0 comments on commit 6c90bb3

Please sign in to comment.