* @param path
* @return
*/
private <Type> VertexSet load(Type expected, Iterable<Property> path) {
LinkedList<Property> updatablePath = new LinkedList<Property>(CollectionUtils.asList(path));
Property lastProperty = updatablePath.removeLast();
// if value is a literal, well, it's time for an index lookup
Class<Type> expectedClass = (Class<Type>) expected.getClass();
if (expected != null && Literals.containsKey(expectedClass)) {
// Yup : gladly using implementation as it provides a last() method !
Index<Vertex> vertices = (Index<Vertex>) service.getDatabase().getIndex(IndexNames.VERTICES.getIndexName(), IndexNames.VERTICES.getIndexed());
// stinky code fragment for collections : as each value is stored under
// a key in the form propertyName:index, we have to iterate upon them
String propertyKeyInIndex = null;
String propertyValueInIndex = null;
if (Collection.class.isAssignableFrom(lastProperty.getType())) {
propertyKeyInIndex = GraphUtils.getEdgeNameFor(new CollectionAccessByValueProperty(lastProperty, expected, Updater.ELEMENT_IN_COLLECTION_MARKER));
propertyValueInIndex = Updater.ELEMENT_IN_COLLECTION_MARKER_GRAPH_VALUE;
} else {
propertyKeyInIndex = GraphUtils.getEdgeNameFor(lastProperty);
LiteralTransformer<Type> transformer = Literals.get(expectedClass);
if(Literals.containsKey(lastProperty.getType())) {
transformer = Literals.get(lastProperty.getType());
}
propertyValueInIndex = transformer.toString(expected);
}
VertexSet returned = new VertexSet().withPropertyPath(updatablePath);
returned.setVertices(new IndexLazyLoader(vertices, propertyKeyInIndex, propertyValueInIndex));