use of com.baidu.hugegraph.structure.constant.GraphAttachable in project incubator-hugegraph-toolchain by apache.
the class ResultSet method get.
public Result get(int index) {
if (index >= this.data.size()) {
return null;
}
Object object = this.data().get(index);
if (object == null) {
return null;
}
Class<?> clazz = this.parseResultClass(object);
// Primitive type
if (clazz.equals(object.getClass())) {
return new Result(object);
}
try {
String rawValue = MAPPER.writeValueAsString(object);
object = MAPPER.readValue(rawValue, clazz);
if (object instanceof GraphAttachable) {
((GraphAttachable) object).attachManager(graphManager);
}
return new Result(object);
} catch (Exception e) {
throw new SerializeException("Failed to deserialize: %s", e, object);
}
}
use of com.baidu.hugegraph.structure.constant.GraphAttachable in project incubator-hugegraph-toolchain by apache.
the class GremlinApiTest method testAttachedManager.
@Test
public void testAttachedManager() {
GremlinRequest request = new GremlinRequest("g.V()");
ResultSet resultSet = gremlin().execute(request);
Assert.assertEquals(6, resultSet.size());
Iterator<Result> results = resultSet.iterator();
while (results.hasNext()) {
Result result = results.next();
Object object = result.getObject();
Assert.assertEquals(Vertex.class, object.getClass());
Vertex vertex = (Vertex) object;
Assert.assertNotNull(Whitebox.getInternalState(vertex, "manager"));
}
request = new GremlinRequest("g.E()");
resultSet = gremlin().execute(request);
Assert.assertEquals(6, resultSet.size());
results = resultSet.iterator();
while (results.hasNext()) {
Result result = results.next();
Object object = result.getObject();
Assert.assertEquals(Edge.class, object.getClass());
Edge edge = (Edge) object;
Assert.assertNotNull(Whitebox.getInternalState(edge, "manager"));
}
request = new GremlinRequest("g.V().outE().path()");
resultSet = gremlin().execute(request);
Assert.assertEquals(6, resultSet.size());
results = resultSet.iterator();
while (results.hasNext()) {
Result result = results.next();
Object object = result.getObject();
Assert.assertEquals(Path.class, object.getClass());
Path path = (Path) object;
Assert.assertNotNull(path.objects());
for (Object pathObject : path.objects()) {
Assert.assertTrue(pathObject instanceof GraphAttachable);
Assert.assertNotNull(Whitebox.getInternalState(pathObject, "manager"));
}
Assert.assertNull(path.crosspoint());
}
}
Aggregations