Skip to content

Commit

Permalink
Log warnings instead of throwing exceptions when multiple elements wi…
Browse files Browse the repository at this point in the history
…th with the same IdGraph id are discovered
  • Loading branch information
joshsh committed Mar 21, 2014
1 parent 9ef2831 commit f4addb3
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Logger;

/**
* A Graph implementation which wraps another Graph implementation,
* enabling custom element IDs even for those graphs which don't otherwise support them.
* <p/>
*
* The base Graph must be an instance of KeyIndexableGraph.
* It *may* be an instance of IndexableGraph, in which case its indices will be wrapped appropriately.
* It *may* be an instance of TransactionalGraph, in which case transaction operations will be passed through.
Expand All @@ -34,6 +35,8 @@
*/
public class IdGraph<T extends KeyIndexableGraph> implements KeyIndexableGraph, WrapperGraph<T>, IndexableGraph, TransactionalGraph {

private static final Logger LOGGER = Logger.getLogger(IdGraph.class.getName());

// Note: using "__id" instead of "_id" avoids collision with Rexster's "_id"
public static final String ID = "__id";

Expand Down Expand Up @@ -152,13 +155,13 @@ public Vertex getVertex(final Object id) {
if (!iter.hasNext()) {
return null;
} else {
Vertex e = iter.next();
Vertex v = iter.next();

if (iter.hasNext()) {
throw new IllegalStateException("multiple vertices exist with id '" + id + "'");
LOGGER.warning("multiple vertices exist with id '" + id + "'. Arbitarily choosing " + v);
}

return new IdVertex(e, this);
return new IdVertex(v, this);
}
} else {
Vertex base = baseGraph.getVertex(id);
Expand Down Expand Up @@ -222,7 +225,7 @@ public Edge getEdge(final Object id) {
Edge e = iter.next();

if (iter.hasNext()) {
throw new IllegalStateException("multiple edges exist with id " + id);
LOGGER.warning("multiple edges exist with id '" + id + "'. Arbitarily choosing " + e);
}

return new IdEdge(e, this);
Expand Down

0 comments on commit f4addb3

Please sign in to comment.