com.dooapp.gaedo.blueprints.CollectionLazyLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gaedo-blueprints Show documentation
Show all versions of gaedo-blueprints Show documentation
Implementation of gaedo mechanisms backed by blueprints graph layer
package com.dooapp.gaedo.blueprints;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.dooapp.gaedo.blueprints.operations.CollectionAccessByIndexProperty;
import com.dooapp.gaedo.blueprints.operations.CollectionSizeProperty;
import com.dooapp.gaedo.blueprints.operations.LiteralInCollectionUpdaterProperty;
import com.dooapp.gaedo.blueprints.operations.Loader;
import com.dooapp.gaedo.blueprints.strategies.GraphMappingStrategy;
import com.dooapp.gaedo.finders.FinderCrudService;
import com.dooapp.gaedo.finders.repository.ServiceRepository;
import com.dooapp.gaedo.patterns.WriteReplaceable;
import com.dooapp.gaedo.properties.AbstractPropertyAdapter;
import com.dooapp.gaedo.properties.Property;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
@SuppressWarnings("rawtypes")
public class CollectionLazyLoader extends AbstractLazyLoader implements InvocationHandler, WriteReplaceable, Serializable {
/**
* As values can be laoded from both edges and node properties, these different methods have to be implemented in different fashions.
* That's why I've created this lcoal interface, that will allow us to load both opf them in the order
* defined by collection_index while respecting the way they're stored.
* @author ndx
*
*/
private interface ValueLoader {
Object load(ObjectCache objectsBeingAccessed);
}
public class LoadValueInProperty implements ValueLoader {
private Property toLoad;
public LoadValueInProperty(AbstractPropertyAdapter elementByIndexProperty) {
this.toLoad = elementByIndexProperty;
}
@Override
public Object load(ObjectCache objectsBeingAccessed) {
return Loader.loadSingleLiteral(classLoader, toLoad, rootVertex, objectsBeingAccessed);
}
/**
* @return
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("LoadValueInProperty [");
if (toLoad != null) {
builder.append("toLoad=");
builder.append(toLoad);
}
if (rootVertex != null) {
builder.append("rootVertex=");
builder.append(GraphUtils.toString(rootVertex));
}
builder.append("]");
return builder.toString();
}
}
public class LoadValueBehindEdge implements ValueLoader {
private Edge toLoad;
public LoadValueBehindEdge(Edge e) {
this.toLoad = e;
}
@Override
public Object load(ObjectCache objectsBeingAccessed) {
Vertex value = toLoad.getVertex(Direction.IN);
return loadValue(objectsBeingAccessed, value);
}
/**
* @return
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("LoadValueBehindEdge [");
if (toLoad != null) {
builder.append("toLoad=");
builder.append(GraphUtils.toString(toLoad));
}
builder.append("]");
return builder.toString();
}
}
private static final Logger logger = Logger.getLogger(CollectionLazyLoader.class.getName());
// Internal storage collection (not to be confused with external visible collection)
private Collection collection;
/**
* Serialization constructor
*/
public CollectionLazyLoader() {
}
public CollectionLazyLoader(GraphDatabaseDriver driver, GraphMappingStrategy strategy, ClassLoader classLoader, ServiceRepository repository, Property p, Vertex objectVertex, Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy