1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
| public final class TinkerFactory {
public static TinkerGraph createClassic() { final Configuration conf = new BaseConfiguration(); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, TinkerGraph.DefaultIdManager.INTEGER.name()); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, TinkerGraph.DefaultIdManager.INTEGER.name()); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER, TinkerGraph.DefaultIdManager.INTEGER.name());
final TinkerGraph g = TinkerGraph.open(conf); generateClassic(g); return g; }
public static void generateClassic(final TinkerGraph g) { final Vertex marko = g.addVertex(T.id, 1, "name", "marko", "age", 29); final Vertex vadas = g.addVertex(T.id, 2, "name", "vadas", "age", 27); final Vertex lop = g.addVertex(T.id, 3, "name", "lop", "lang", "java"); final Vertex josh = g.addVertex(T.id, 4, "name", "josh", "age", 32); final Vertex ripple = g.addVertex(T.id, 5, "name", "ripple", "lang", "java"); final Vertex peter = g.addVertex(T.id, 6, "name", "peter", "age", 35); marko.addEdge("knows", vadas, T.id, 7, "weight", 0.5f); marko.addEdge("knows", josh, T.id, 8, "weight", 1.0f); marko.addEdge("created", lop, T.id, 9, "weight", 0.4f); josh.addEdge("created", ripple, T.id, 10, "weight", 1.0f); josh.addEdge("created", lop, T.id, 11, "weight", 0.4f); peter.addEdge("created", lop, T.id, 12, "weight", 0.2f); }
public static TinkerGraph createModern() { final TinkerGraph g = TinkerGraph.open(); generateModern(g); return g; }
public static void generateModern(final TinkerGraph g) { final Vertex marko = g.addVertex(T.id, 1, T.label, "person", "name", "marko", "age", 29); final Vertex vadas = g.addVertex(T.id, 2, T.label, "person", "name", "vadas", "age", 27); final Vertex lop = g.addVertex(T.id, 3, T.label, "software", "name", "lop", "lang", "java"); final Vertex josh = g.addVertex(T.id, 4, T.label, "person", "name", "josh", "age", 32); final Vertex ripple = g.addVertex(T.id, 5, T.label, "software", "name", "ripple", "lang", "java"); final Vertex peter = g.addVertex(T.id, 6, T.label, "person", "name", "peter", "age", 35); marko.addEdge("knows", vadas, T.id, 7, "weight", 0.5d); marko.addEdge("knows", josh, T.id, 8, "weight", 1.0d); marko.addEdge("created", lop, T.id, 9, "weight", 0.4d); josh.addEdge("created", ripple, T.id, 10, "weight", 1.0d); josh.addEdge("created", lop, T.id, 11, "weight", 0.4d); peter.addEdge("created", lop, T.id, 12, "weight", 0.2d); }
public static TinkerGraph createTheCrew() { final Configuration conf = new BaseConfiguration(); conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name()); final TinkerGraph g = TinkerGraph.open(conf); generateTheCrew(g); return g; }
public static void generateTheCrew(final TinkerGraph g) { final Vertex marko = g.addVertex(T.id, 1, T.label, "person", "name", "marko"); final Vertex stephen = g.addVertex(T.id, 7, T.label, "person", "name", "stephen"); final Vertex matthias = g.addVertex(T.id, 8, T.label, "person", "name", "matthias"); final Vertex daniel = g.addVertex(T.id, 9, T.label, "person", "name", "daniel"); final Vertex gremlin = g.addVertex(T.id, 10, T.label, "software", "name", "gremlin"); final Vertex tinkergraph = g.addVertex(T.id, 11, T.label, "software", "name", "tinkergraph");
marko.property(VertexProperty.Cardinality.list, "location", "san diego", "startTime", 1997, "endTime", 2001); marko.property(VertexProperty.Cardinality.list, "location", "santa cruz", "startTime", 2001, "endTime", 2004); marko.property(VertexProperty.Cardinality.list, "location", "brussels", "startTime", 2004, "endTime", 2005); marko.property(VertexProperty.Cardinality.list, "location", "santa fe", "startTime", 2005);
stephen.property(VertexProperty.Cardinality.list, "location", "centreville", "startTime", 1990, "endTime", 2000); stephen.property(VertexProperty.Cardinality.list, "location", "dulles", "startTime", 2000, "endTime", 2006); stephen.property(VertexProperty.Cardinality.list, "location", "purcellville", "startTime", 2006);
matthias.property(VertexProperty.Cardinality.list, "location", "bremen", "startTime", 2004, "endTime", 2007); matthias.property(VertexProperty.Cardinality.list, "location", "baltimore", "startTime", 2007, "endTime", 2011); matthias.property(VertexProperty.Cardinality.list, "location", "oakland", "startTime", 2011, "endTime", 2014); matthias.property(VertexProperty.Cardinality.list, "location", "seattle", "startTime", 2014);
daniel.property(VertexProperty.Cardinality.list, "location", "spremberg", "startTime", 1982, "endTime", 2005); daniel.property(VertexProperty.Cardinality.list, "location", "kaiserslautern", "startTime", 2005, "endTime", 2009); daniel.property(VertexProperty.Cardinality.list, "location", "aachen", "startTime", 2009);
marko.addEdge("develops", gremlin, T.id, 13, "since", 2009); marko.addEdge("develops", tinkergraph, T.id, 14, "since", 2010); marko.addEdge("uses", gremlin, T.id, 15, "skill", 4); marko.addEdge("uses", tinkergraph, T.id, 16, "skill", 5);
stephen.addEdge("develops", gremlin, T.id, 17, "since", 2010); stephen.addEdge("develops", tinkergraph, T.id, 18, "since", 2011); stephen.addEdge("uses", gremlin, T.id, 19, "skill", 5); stephen.addEdge("uses", tinkergraph, T.id, 20, "skill", 4);
matthias.addEdge("develops", gremlin, T.id, 21, "since", 2012); matthias.addEdge("uses", gremlin, T.id, 22, "skill", 3); matthias.addEdge("uses", tinkergraph, T.id, 23, "skill", 3);
daniel.addEdge("uses", gremlin, T.id, 24, "skill", 5); daniel.addEdge("uses", tinkergraph, T.id, 25, "skill", 3);
gremlin.addEdge("traverses", tinkergraph, T.id, 26);
g.variables().set("creator", "marko"); g.variables().set("lastModified", 2014); g.variables().set("comment", "this graph was created to provide examples and test coverage for tinkerpop3 api advances"); } }
public final class TinkerGraphVariables implements Graph.Variables {
private final Map<String, Object> variables = new ConcurrentHashMap<>();
public TinkerGraphVariables() {
}
@Override public Set<String> keys() { return this.variables.keySet(); }
@Override public <R> Optional<R> get(final String key) { return Optional.ofNullable((R) this.variables.get(key)); }
@Override public void remove(final String key) { this.variables.remove(key); }
@Override public void set(final String key, final Object value) { GraphVariableHelper.validateVariable(key, value); this.variables.put(key, value); }
public String toString() { return StringFactory.graphVariablesString(this); } }
public final class TinkerHelper { protected static Edge addEdge(final TinkerGraph graph, final TinkerVertex outVertex, final TinkerVertex inVertex, final String label, final Object... keyValues) { ElementHelper.validateLabel(label); ElementHelper.legalPropertyKeyValueArray(keyValues);
Object idValue = graph.edgeIdManager.convert(ElementHelper.getIdValue(keyValues).orElse(null));
final Edge edge; if (null != idValue) { if (graph.edges.containsKey(idValue)) throw Graph.Exceptions.edgeWithIdAlreadyExists(idValue); } else { idValue = graph.edgeIdManager.getNextId(graph); }
edge = new TinkerEdge(idValue, outVertex, label, inVertex); ElementHelper.attachProperties(edge, keyValues); graph.edges.put(edge.id(), edge); TinkerHelper.addOutEdge(outVertex, label, edge); TinkerHelper.addInEdge(inVertex, label, edge); return edge;
}
protected static void addOutEdge(final TinkerVertex vertex, final String label, final Edge edge) { if (null == vertex.outEdges) vertex.outEdges = new HashMap<>(); Set<Edge> edges = vertex.outEdges.get(label); if (null == edges) { edges = new HashSet<>(); vertex.outEdges.put(label, edges); } edges.add(edge); }
protected static void addInEdge(final TinkerVertex vertex, final String label, final Edge edge) { if (null == vertex.inEdges) vertex.inEdges = new HashMap<>(); Set<Edge> edges = vertex.inEdges.get(label); if (null == edges) { edges = new HashSet<>(); vertex.inEdges.put(label, edges); } edges.add(edge); }
public static List<TinkerVertex> queryVertexIndex(final TinkerGraph graph, final String key, final Object value) { return null == graph.vertexIndex ? Collections.emptyList() : graph.vertexIndex.get(key, value); }
public static List<TinkerEdge> queryEdgeIndex(final TinkerGraph graph, final String key, final Object value) { return null == graph.edgeIndex ? Collections.emptyList() : graph.edgeIndex.get(key, value); }
public static Iterator<TinkerEdge> getEdges(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) { final List<Edge> edges = new ArrayList<>(); if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) { if (vertex.outEdges != null) { if (edgeLabels.length == 0) vertex.outEdges.values().forEach(edges::addAll); else if (edgeLabels.length == 1) edges.addAll(vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet())); else Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).forEach(edges::addAll); } } if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) { if (vertex.inEdges != null) { if (edgeLabels.length == 0) vertex.inEdges.values().forEach(edges::addAll); else if (edgeLabels.length == 1) edges.addAll(vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet())); else Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).forEach(edges::addAll); } } return (Iterator) edges.iterator(); }
public static Iterator<TinkerVertex> getVertices(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) { final List<Vertex> vertices = new ArrayList<>(); if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) { if (vertex.outEdges != null) { if (edgeLabels.length == 0) vertex.outEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex))); else if (edgeLabels.length == 1) vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex)); else Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex)); } } if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) { if (vertex.inEdges != null) { if (edgeLabels.length == 0) vertex.inEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex))); else if (edgeLabels.length == 1) vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex)); else Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex)); } } return (Iterator) vertices.iterator(); } }
public final class TinkerIoRegistry extends AbstractIoRegistry {
private static final TinkerIoRegistry INSTANCE = new TinkerIoRegistry();
private TinkerIoRegistry() { register(GryoIo.class, TinkerGraph.class, new TinkerGraphGryoSerializer()); register(GraphSONIo.class, null, new TinkerModule()); }
public static TinkerIoRegistry getInstance() { return INSTANCE; }
final static class TinkerGraphGryoSerializer extends Serializer<TinkerGraph> { @Override public void write(final Kryo kryo, final Output output, final TinkerGraph graph) { try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) { GryoWriter.build().mapper(() -> kryo).create().writeGraph(stream, graph); final byte[] bytes = stream.toByteArray(); output.writeInt(bytes.length); output.write(bytes); } catch (Exception io) { throw new RuntimeException(io); } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final TinkerGraph graph = TinkerGraph.open(); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); }
return graph; } }
final static class TinkerModule extends SimpleModule { public TinkerModule() { super("tinkergraph-1.0"); addSerializer(TinkerGraph.class, new TinkerGraphJacksonSerializer()); addDeserializer(TinkerGraph.class, new TinkerGraphJacksonDeserializer()); } }
final static class TinkerGraphJacksonSerializer extends StdSerializer<TinkerGraph> {
public TinkerGraphJacksonSerializer() { super(TinkerGraph.class); }
@Override public void serialize(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject();
jsonGenerator.writeFieldName(GraphSONTokens.VERTICES); jsonGenerator.writeStartArray();
final Iterator<Vertex> vertices = graph.vertices(); while (vertices.hasNext()) { serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator); }
jsonGenerator.writeEndArray();
jsonGenerator.writeFieldName(GraphSONTokens.EDGES); jsonGenerator.writeStartArray();
final Iterator<Edge> edges = graph.edges(); while (edges.hasNext()) { serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator); }
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject(); }
@Override public void serializeWithType(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(GraphSONTokens.CLASS, TinkerGraph.class.getName());
jsonGenerator.writeFieldName(GraphSONTokens.VERTICES); jsonGenerator.writeStartArray(); jsonGenerator.writeString(ArrayList.class.getName()); jsonGenerator.writeStartArray();
final Iterator<Vertex> vertices = graph.vertices(); while (vertices.hasNext()) { GraphSONUtil.writeWithType(vertices.next(), jsonGenerator, serializerProvider, typeSerializer); }
jsonGenerator.writeEndArray(); jsonGenerator.writeEndArray();
jsonGenerator.writeFieldName(GraphSONTokens.EDGES); jsonGenerator.writeStartArray(); jsonGenerator.writeString(ArrayList.class.getName()); jsonGenerator.writeStartArray();
final Iterator<Edge> edges = graph.edges(); while (edges.hasNext()) { GraphSONUtil.writeWithType(edges.next(), jsonGenerator, serializerProvider, typeSerializer); }
jsonGenerator.writeEndArray(); jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject(); } }
static class TinkerGraphJacksonDeserializer extends StdDeserializer<TinkerGraph> { public TinkerGraphJacksonDeserializer() { super(TinkerGraph.class); }
@Override public TinkerGraph deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { final TinkerGraph graph = TinkerGraph.open();
final List<Map<String, Object>> edges; final List<Map<String, Object>> vertices; if (!jsonParser.getCurrentToken().isStructStart()) { if (!jsonParser.getCurrentName().equals(GraphSONTokens.VERTICES)) throw new IOException(String.format("Expected a '%s' key", GraphSONTokens.VERTICES));
jsonParser.nextToken(); vertices = (List<Map<String, Object>>) deserializationContext.readValue(jsonParser, ArrayList.class); jsonParser.nextToken();
if (!jsonParser.getCurrentName().equals(GraphSONTokens.EDGES)) throw new IOException(String.format("Expected a '%s' key", GraphSONTokens.EDGES));
jsonParser.nextToken(); edges = (List<Map<String, Object>>) deserializationContext.readValue(jsonParser, ArrayList.class); } else { final Map<String, Object> graphData = deserializationContext.readValue(jsonParser, HashMap.class); vertices = (List<Map<String,Object>>) graphData.get(GraphSONTokens.VERTICES); edges = (List<Map<String,Object>>) graphData.get(GraphSONTokens.EDGES); }
for (Map<String, Object> vertexData : vertices) { final DetachedVertex detached = new DetachedVertex(vertexData.get(GraphSONTokens.ID), vertexData.get(GraphSONTokens.LABEL).toString(), (Map<String,Object>) vertexData.get(GraphSONTokens.PROPERTIES)); detached.attach(Attachable.Method.getOrCreate(graph)); }
for (Map<String, Object> edgeData : edges) { final DetachedEdge detached = new DetachedEdge(edgeData.get(GraphSONTokens.ID), edgeData.get(GraphSONTokens.LABEL).toString(), (Map<String,Object>) edgeData.get(GraphSONTokens.PROPERTIES), Pair.with(edgeData.get(GraphSONTokens.OUT), edgeData.get(GraphSONTokens.OUT_LABEL).toString()), Pair.with(edgeData.get(GraphSONTokens.IN), edgeData.get(GraphSONTokens.IN_LABEL).toString())); detached.attach(Attachable.Method.getOrCreate(graph)); }
return graph; } } }
public final class TinkerIoRegistryV2d0 extends AbstractIoRegistry {
private static final TinkerIoRegistryV2d0 INSTANCE = new TinkerIoRegistryV2d0();
private TinkerIoRegistryV2d0() { register(GryoIo.class, TinkerGraph.class, new TinkerGraphGryoSerializer()); register(GraphSONIo.class, null, new TinkerModuleV2d0()); }
public static TinkerIoRegistryV2d0 getInstance() { return INSTANCE; }
final static class TinkerGraphGryoSerializer extends Serializer<TinkerGraph> { @Override public void write(final Kryo kryo, final Output output, final TinkerGraph graph) { try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) { GryoWriter.build().mapper(() -> kryo).create().writeGraph(stream, graph); final byte[] bytes = stream.toByteArray(); output.writeInt(bytes.length); output.write(bytes); } catch (Exception io) { throw new RuntimeException(io); } }
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final TinkerGraph graph = TinkerGraph.open(); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); }
return graph; } }
final static class TinkerModuleV2d0 extends TinkerPopJacksonModule { public TinkerModuleV2d0() { super("tinkergraph-2.0"); addSerializer(TinkerGraph.class, new TinkerGraphJacksonSerializer()); addDeserializer(TinkerGraph.class, new TinkerGraphJacksonDeserializer()); }
@Override public Map<Class, String> getTypeDefinitions() { return new HashMap<Class, String>(){{ put(TinkerGraph.class, "graph"); }}; }
@Override public String getTypeNamespace() { return "tinker"; } }
final static class TinkerGraphJacksonSerializer extends StdScalarSerializer<TinkerGraph> {
public TinkerGraphJacksonSerializer() { super(TinkerGraph.class); }
@Override public void serialize(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName(GraphSONTokens.VERTICES); jsonGenerator.writeStartArray();
final Iterator<Vertex> vertices = graph.vertices(); while (vertices.hasNext()) { serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator); }
jsonGenerator.writeEndArray(); jsonGenerator.writeFieldName(GraphSONTokens.EDGES); jsonGenerator.writeStartArray();
final Iterator<Edge> edges = graph.edges(); while (edges.hasNext()) { serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator); }
jsonGenerator.writeEndArray(); jsonGenerator.writeEndObject(); } }
static class TinkerGraphJacksonDeserializer extends StdDeserializer<TinkerGraph> { public TinkerGraphJacksonDeserializer() { super(TinkerGraph.class); }
@Override public TinkerGraph deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException { final TinkerGraph graph = TinkerGraph.open();
final List<? extends Edge> edges; final List<? extends Vertex> vertices;
jsonParser.nextToken(); final Map<String, Object> graphData = deserializationContext.readValue(jsonParser, Map.class); vertices = (List<DetachedVertex>) graphData.get(GraphSONTokens.VERTICES); edges = (List<DetachedEdge>) graphData.get(GraphSONTokens.EDGES);
vertices.forEach(e -> { if (e instanceof DetachedVertex) { ((DetachedVertex)e).attach(Attachable.Method.getOrCreate(graph)); } });
edges.forEach(e -> { if (e instanceof DetachedEdge) { ((DetachedEdge) e).attach(Attachable.Method.getOrCreate(graph)); } });
return graph; } } }
|