use of com.tinkerpop.blueprints.Element in project blueprints by tinkerpop.
the class ElementHelper method removeProperties.
/**
* Clear all the properties from an iterable of elements.
*
* @param elements the elements to remove properties from
*/
public static void removeProperties(final Iterable<Element> elements) {
for (final Element element : elements) {
final List<String> keys = new ArrayList<String>();
keys.addAll(element.getPropertyKeys());
for (final String key : keys) {
element.removeProperty(key);
}
}
}
use of com.tinkerpop.blueprints.Element in project blueprints by tinkerpop.
the class KeyIndexableGraphHelper method reIndexElements.
/**
* For those graphs that do no support automatic reindexing of elements when a key is provided for indexing, this method can be used to simulate that behavior.
* The elements in the graph are iterated and their properties (for the provided keys) are removed and then added.
* Be sure that the key indices have been created prior to calling this method so that they can pick up the property mutations calls.
* Finally, if the graph is a TransactionalGraph, then a 1000 mutation buffer is used for each commit.
*
* @param graph the graph containing the provided elements
* @param elements the elements to index into the key indices
* @param keys the keys of the key indices
* @return the number of element properties that were indexed
*/
public static long reIndexElements(final Graph graph, final Iterable<? extends Element> elements, final Set<String> keys) {
final boolean isTransactional = graph instanceof TransactionalGraph;
long counter = 0;
for (final Element element : elements) {
for (final String key : keys) {
final Object value = element.removeProperty(key);
if (null != value) {
counter++;
element.setProperty(key, value);
if (isTransactional && (counter % 1000 == 0)) {
((TransactionalGraph) graph).commit();
}
}
}
}
if (isTransactional) {
((TransactionalGraph) graph).commit();
}
return counter;
}
use of com.tinkerpop.blueprints.Element in project blueprints by tinkerpop.
the class GraphSONUtility method createJSONMap.
private static ObjectNode createJSONMap(final Map map, final List<String> propertyKeys, final boolean showTypes) {
final ObjectNode jsonMap = jsonNodeFactory.objectNode();
for (Object key : map.keySet()) {
Object value = map.get(key);
if (value != null) {
if (value instanceof List) {
value = createJSONList((List) value, propertyKeys, showTypes);
} else if (value instanceof Iterable) {
value = createJSONList(getList((Iterable) value), propertyKeys, showTypes);
} else if (value instanceof Iterator) {
value = createJSONList(getList((Iterator) value), propertyKeys, showTypes);
} else if (value instanceof Map) {
value = createJSONMap((Map) value, propertyKeys, showTypes);
} else if (value instanceof Element) {
value = objectNodeFromElement((Element) value, propertyKeys, showTypes ? GraphSONMode.EXTENDED : GraphSONMode.NORMAL);
} else if (value.getClass().isArray()) {
value = createJSONList(convertArrayToList(value), propertyKeys, showTypes);
}
}
putObject(jsonMap, key.toString(), getValue(value, showTypes));
}
return jsonMap;
}
use of com.tinkerpop.blueprints.Element in project blueprints by tinkerpop.
the class RexsterGraph method getIndices.
public Iterable<Index<? extends Element>> getIndices() {
List<Index<? extends Element>> indices = new ArrayList<Index<? extends Element>>();
JSONArray json = RestHelper.getResultArray(this.graphURI + RexsterTokens.SLASH_INDICES);
for (int ix = 0; ix < json.length(); ix++) {
JSONObject index = json.optJSONObject(ix);
Class c;
String clazz = index.optString(RexsterTokens.CLASS);
if (clazz.toLowerCase().contains(RexsterTokens.VERTEX))
c = Vertex.class;
else if (clazz.toLowerCase().contains(RexsterTokens.EDGE))
c = Edge.class;
else
throw new RuntimeException("Can not determine whether " + clazz + " is a vertex or edge class");
indices.add(new RexsterIndex(this, index.optString(RexsterTokens.NAME), c));
}
return indices;
}
use of com.tinkerpop.blueprints.Element in project frames by tinkerpop.
the class JavaHandlerModule method createHandler.
<T> T createHandler(final Object framedElement, final FramedGraph<?> graph, final Element element, Class<?> frameClass, final Method method) {
try {
Class<T> implClass = (Class<T>) classCache.get(frameClass);
T handler = factory.create(implClass);
((Proxy) handler).setHandler(new MethodHandler() {
private JavaHandlerContextImpl<Element> defaultJavahandlerImpl = new JavaHandlerContextImpl<Element>(graph, method, element);
@Override
public Object invoke(Object o, Method m, Method proceed, Object[] args) throws Throwable {
if (!Modifier.isAbstract(m.getModifiers())) {
return proceed.invoke(o, args);
} else {
if (m.getAnnotation(JavaHandler.class) != null) {
throw new JavaHandlerException("Method " + m + " is marked with @JavaHandler but is not implemented");
}
if (m.getDeclaringClass() == JavaHandlerContext.class) {
return m.invoke(defaultJavahandlerImpl, args);
}
return m.invoke(framedElement, args);
}
}
});
return handler;
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof ClassNotFoundException) {
throw new JavaHandlerException("Problem locating handler class for " + frameClass, e);
} else {
throw new JavaHandlerException("Cannot create class for handling framed method", cause);
}
} catch (InstantiationException e) {
throw new JavaHandlerException("Problem instantiating handler class", e);
} catch (IllegalAccessException e) {
throw new JavaHandlerException("Problem instantiating handler class", e);
}
}
Aggregations