/** * The object id must be a Map<String,Object> or null. The id is the properties written when * the vertex is created. While it is possible to Edge.setProperty(), this method is faster. * * @param id a id of properties which can be null * @return the newly created vertex */ public Edge addEdge( final Object id, final Vertex outVertex, final Vertex inVertex, final String label) { final Map<String, Object> finalProperties; if (id == null || !(id instanceof Map)) finalProperties = new HashMap<String, Object>(); else finalProperties = makePropertyMap((Map<String, Object>) id); final Long finalId = this.rawGraph.createRelationship( (Long) outVertex.getId(), (Long) inVertex.getId(), DynamicRelationshipType.withName(label), finalProperties); final Neo4jBatchEdge edge = new Neo4jBatchEdge(this, finalId, label); if (finalProperties.size() > 0) { for (final Neo4jBatchAutomaticIndex<Neo4jBatchEdge> index : this.automaticEdgeIndices.values()) { index.autoUpdate(edge, finalProperties); } } return edge; }
/** * The object id can either be null, a long id, or a Map<String,Object>. If null, then an * internal long is provided on the construction of the vertex. If a long id is provided, then the * vertex is constructed with that long id. If a map is provided, then the map serves as the * properties of the vertex. Moreover, if the map contains an _id key, then the value is a user * provided long vertex id. * * @param id a id of properties which can be null * @return the newly created vertex */ public Vertex addVertex(final Object id) { final Long finalId; Map<String, Object> finalProperties = new HashMap<String, Object>(); if (null == id) { rawGraph.createNode(++this.idCounter, finalProperties); finalId = this.idCounter; } else if (id instanceof Long) { rawGraph.createNode((Long) id, finalProperties); finalId = (Long) id; } else if (id instanceof Map) { finalProperties = makePropertyMap((Map<String, Object>) id); final Long providedId = (Long) ((Map<String, Object>) id).get(Neo4jBatchTokens.ID); finalProperties.remove(Neo4jBatchTokens.ID); if (providedId == null) finalId = rawGraph.createNode(finalProperties); else { rawGraph.createNode(providedId, finalProperties); finalId = providedId; } } else { try { finalId = Double.valueOf(id.toString()).longValue(); rawGraph.createNode(finalId, finalProperties); } catch (NumberFormatException e) { throw new IllegalArgumentException( "The provided object must be null, a long id, an object convertible to long, or a Map<String,Object>"); } } final Neo4jBatchVertex vertex = new Neo4jBatchVertex(this, finalId); if (finalProperties.size() > 0) { for (final Neo4jBatchAutomaticIndex<Neo4jBatchVertex> index : this.automaticVertexIndices.values()) { index.autoUpdate(vertex, finalProperties); } } return vertex; }