com.tinkerpop.blueprints.util.ExceptionFactory Java Examples
The following examples show how to use
com.tinkerpop.blueprints.util.ExceptionFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CachedChronoGraph.java From epcis with Apache License 2.0 | 6 votes |
public CachedChronoEdge addEdge(final Long outVertexIdx, final Long inVertexIdx, final Long labelIdx) { if (labelIdx == null) throw ExceptionFactory.edgeLabelCanNotBeNull(); CachedEdgeID edgeID = new CachedEdgeID(outVertexIdx, labelIdx, inVertexIdx); CachedChronoEdge edge = this.edges.get(edgeID); if (edge == null) { CachedChronoVertex out = getChronoVertex(outVertexIdx); CachedChronoVertex in = getChronoVertex(inVertexIdx); edge = new CachedChronoEdge(out, in, labelIdx, this); this.edges.put(edgeID, edge); out.addOutEdge(labelIdx, in); in.addInEdge(labelIdx, out); } return edge; }
Example #2
Source File: IdGraph.java From org.openntf.domino with Apache License 2.0 | 6 votes |
public <T extends Element> Set<String> getIndexedKeys(final Class<T> elementClass) { if (elementClass == null) throw ExceptionFactory.classForElementCannotBeNull(); boolean v = isVertexClass(elementClass); boolean supported = ((v && supportVertexIds) || (!v && supportEdgeIds)); if (supported) { Set<String> keys = new HashSet<String>(); keys.addAll(baseGraph.getIndexedKeys(elementClass)); keys.remove(ID); return keys; } else { return baseGraph.getIndexedKeys(elementClass); } }
Example #3
Source File: IndexMetadataTableWrapper.java From AccumuloGraph with Apache License 2.0 | 6 votes |
public <T extends Element> Set<String> getIndexedKeys(Class<T> elementClass) { if (elementClass == null) { throw ExceptionFactory.classForElementCannotBeNull(); } IndexedItemsListParser parser = new IndexedItemsListParser(elementClass); Scanner scan = null; try { scan = getScanner(); scan.fetchColumnFamily(new Text(IndexMetadataEntryType.__INDEX_KEY__.name())); Set<String> keys = new HashSet<String>(); for (IndexedItem item : parser.parse(scan)) { keys.add(item.getKey()); } return keys; } finally { if (scan != null) { scan.close(); } } }
Example #4
Source File: AccumuloVertex.java From AccumuloGraph with Apache License 2.0 | 6 votes |
/** * Add an edge as with {@link #addEdge(String, Vertex)}, * but with a specified edge id. * @param id * @param label * @param inVertex * @return */ public Edge addEdge(Object id, String label, Vertex inVertex) { if (label == null) { throw ExceptionFactory.edgeLabelCanNotBeNull(); } if (id == null) { id = AccumuloGraphUtils.generateId(); } String myID = id.toString(); AccumuloEdge edge = new AccumuloEdge(globals, myID, inVertex, this, label); // TODO we arent suppose to make sure the given edge ID doesn't already // exist? globals.getEdgeWrapper().writeEdge(edge); globals.getVertexWrapper().writeEdgeEndpoints(edge); globals.checkedFlush(); globals.getCaches().cache(edge, Edge.class); return edge; }
Example #5
Source File: AccumuloGraph.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") @Override public <T extends Element> void createKeyIndex(String key, Class<T> elementClass, Parameter... indexParameters) { // TODO Move below to somewhere appropriate. if (elementClass == null) { throw ExceptionFactory.classForElementCannotBeNull(); } // Add key to indexed keys list. globals.getIndexMetadataWrapper().writeKeyMetadataEntry(key, elementClass); globals.checkedFlush(); // Reindex graph. globals.getKeyIndexTableWrapper(elementClass).rebuildIndex(key, elementClass); globals.getVertexKeyIndexWrapper().dump(); globals.checkedFlush(); }
Example #6
Source File: AccumuloGraph.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") @Override public <T extends Element> Index<T> createIndex(String indexName, Class<T> indexClass, Parameter... indexParameters) { if (indexClass == null) { throw ExceptionFactory.classForElementCannotBeNull(); } else if (globals.getConfig().getIndexableGraphDisabled()) { throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration"); } for (Index<?> index : globals.getIndexMetadataWrapper().getIndices()) { if (index.getIndexName().equals(indexName)) { throw ExceptionFactory.indexAlreadyExists(indexName); } } return globals.getIndexMetadataWrapper().createIndex(indexName, indexClass); }
Example #7
Source File: AccumuloGraph.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@Override public Vertex addVertex(Object id) { if (id == null) { id = AccumuloGraphUtils.generateId(); } String idStr = id.toString(); Vertex vert = null; if (!globals.getConfig().getSkipExistenceChecks()) { vert = getVertex(idStr); if (vert != null) { throw ExceptionFactory.vertexWithIdAlreadyExists(idStr); } } vert = new AccumuloVertex(globals, idStr); globals.getVertexWrapper().writeVertex(vert); globals.checkedFlush(); globals.getCaches().cache(vert, Vertex.class); return vert; }
Example #8
Source File: AccumuloGraph.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Override public Edge getEdge(Object id) { if (id == null) { throw ExceptionFactory.edgeIdCanNotBeNull(); } String idStr = id.toString(); Edge edge = globals.getCaches().retrieve(idStr, Edge.class); if (edge != null) { return edge; } edge = new AccumuloEdge(globals, idStr); if (!globals.getConfig().getSkipExistenceChecks()) { // In addition to just an "existence" check, we will also load // any "preloaded" properties now, which saves us a round-trip // to Accumulo later. String[] preload = globals.getConfig().getPreloadedProperties(); if (preload == null) { preload = new String[]{}; } Map<String, Object> props = globals.getEdgeWrapper() .readProperties(edge, preload); // This will be null if the element does not exist, // in which case return null. if (props == null) { return null; } for (Entry<String, Object> ents : props.entrySet()) { ((AccumuloElement) edge).setPropertyInMemory(ents.getKey(), ents.getValue()); } } globals.getCaches().cache(edge, Edge.class); return edge; }
Example #9
Source File: AccumuloGraph.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Override public <T extends Element> Index<T> getIndex(String indexName, Class<T> indexClass) { if (indexClass == null) { throw ExceptionFactory.classForElementCannotBeNull(); } else if (globals.getConfig().getIndexableGraphDisabled()) { throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration"); } return globals.getIndexMetadataWrapper().getIndex(indexName, indexClass); }
Example #10
Source File: AccumuloGraph.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Override public <T extends Element> void dropKeyIndex(String key, Class<T> elementClass) { // TODO Move below to somewhere appropriate. if (elementClass == null) { throw ExceptionFactory.classForElementCannotBeNull(); } globals.getIndexMetadataWrapper().clearKeyMetadataEntry(key, elementClass); String table = null; if (elementClass.equals(Vertex.class)) { table = globals.getConfig().getVertexKeyIndexTableName(); } else { table = globals.getConfig().getEdgeKeyIndexTableName(); } BatchDeleter bd = null; try { bd = globals.getConfig().getConnector().createBatchDeleter(table, globals.getConfig().getAuthorizations(), globals.getConfig().getMaxWriteThreads(), globals.getConfig().getBatchWriterConfig()); bd.setRanges(Collections.singleton(new Range())); bd.fetchColumnFamily(new Text(key)); bd.delete(); } catch (Exception e) { throw new AccumuloGraphException(e); } finally { if (bd != null) bd.close(); } globals.checkedFlush(); }
Example #11
Source File: AccumuloGraph.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Override public Vertex getVertex(Object id) { if (id == null) { throw ExceptionFactory.vertexIdCanNotBeNull(); } String myID = id.toString(); Vertex vertex = globals.getCaches().retrieve(myID, Vertex.class); if (vertex != null) { return vertex; } vertex = new AccumuloVertex(globals, myID); if (!globals.getConfig().getSkipExistenceChecks()) { // In addition to just an "existence" check, we will also load // any "preloaded" properties now, which saves us a round-trip // to Accumulo later. String[] preload = globals.getConfig().getPreloadedProperties(); if (preload == null && !globals.getConfig().getPreloadAllProperties()) { preload = new String[]{}; } Map<String, Object> props = globals.getVertexWrapper() .readProperties(vertex, preload); if (props == null) { return null; } for (Entry<String, Object> ents : props.entrySet()) { ((AccumuloElement) vertex).setPropertyInMemory(ents.getKey(), ents.getValue()); } } globals.getCaches().cache(vertex, Vertex.class); return vertex; }
Example #12
Source File: AccumuloGraphUtils.java From AccumuloGraph with Apache License 2.0 | 5 votes |
/** * Ensure that the given key/value don't conflict with * Blueprints reserved words. * @param key * @param value */ public static void validateProperty(String key, Object value) { nullCheckProperty(key, value); if (key.equals(StringFactory.ID)) { throw ExceptionFactory.propertyKeyIdIsReserved(); } else if (key.equals(StringFactory.LABEL)) { throw ExceptionFactory.propertyKeyLabelIsReservedForEdges(); } else if (value == null) { throw ExceptionFactory.propertyValueCanNotBeNull(); } }
Example #13
Source File: AccumuloGraphUtils.java From AccumuloGraph with Apache License 2.0 | 5 votes |
/** * Disallow null keys/values and throw appropriate * Blueprints exceptions. * @param key * @param value */ public static void nullCheckProperty(String key, Object value) { if (key == null) { throw ExceptionFactory.propertyKeyCanNotBeNull(); } else if (value == null) { throw ExceptionFactory.propertyValueCanNotBeNull(); } else if (key.trim().equals(StringFactory.EMPTY_STRING)) { throw ExceptionFactory.propertyKeyCanNotBeEmpty(); } }
Example #14
Source File: AccumuloVertex.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Override public void remove() { globals.getCaches().remove(getId(), Vertex.class); super.removeElementFromNamedIndexes(); // Throw exception if the element does not exist. if (!globals.getVertexWrapper().elementExists(id)) { throw ExceptionFactory.vertexWithIdDoesNotExist(getId()); } // Remove properties from key/value indexes. Map<String, Object> props = globals.getVertexWrapper() .readAllProperties(this); for (Entry<String,Object> ent : props.entrySet()) { globals.getVertexKeyIndexWrapper().removePropertyFromIndex(this, ent.getKey(), ent.getValue()); } // Remove edges incident to this vertex. CloseableIterable<Edge> iter = (CloseableIterable<Edge>)getEdges(Direction.BOTH); for (Edge edge : iter) { edge.remove(); } iter.close(); globals.checkedFlush(); // Get rid of the vertex. globals.getVertexWrapper().deleteVertex(this); globals.checkedFlush(); }
Example #15
Source File: MapReduceEdge.java From AccumuloGraph with Apache License 2.0 | 5 votes |
public String getVertexId(Direction direction) throws IllegalArgumentException { switch (direction) { case IN: return destinationId; case OUT: return sourceId; case BOTH: default: throw ExceptionFactory.bothIsNotSupported(); } }
Example #16
Source File: IndexMetadataTableWrapper.java From AccumuloGraph with Apache License 2.0 | 5 votes |
public <T extends Element> Index<T> getIndex(String indexName, Class<T> indexClass) { IndexedItemsListParser parser = new IndexedItemsListParser(); Scanner scan = null; try { scan = getScanner(); scan.fetchColumnFamily(new Text(IndexMetadataEntryType.__INDEX_NAME__.name())); for (IndexedItem item : parser.parse(scan)) { if (item.getKey().equals(indexName)) { if (item.getElementClass().equals(indexClass)) { return new AccumuloIndex<T>(globals, indexName, indexClass); } else { throw ExceptionFactory.indexDoesNotSupportClass(indexName, indexClass); } } } return null; } finally { if (scan != null) { scan.close(); } } }
Example #17
Source File: IndexMetadataTableWrapper.java From AccumuloGraph with Apache License 2.0 | 5 votes |
public <T extends Element> Index<T> createIndex(String indexName, Class<T> indexClass) { for (Index<?> index : getIndices()) { if (index.getIndexName().equals(indexName)) { throw ExceptionFactory.indexAlreadyExists(indexName); } } writeIndexNameEntry(indexName, indexClass); return new AccumuloIndex<T>(globals, indexName, indexClass); }
Example #18
Source File: IdGraph.java From org.openntf.domino with Apache License 2.0 | 5 votes |
public <T extends Element> void dropKeyIndex(final String key, final Class<T> elementClass) { if (elementClass == null) throw ExceptionFactory.classForElementCannotBeNull(); boolean v = isVertexClass(elementClass); boolean supported = ((v && supportVertexIds) || (!v && supportEdgeIds)); if (supported && key.equals(ID)) { throw new IllegalArgumentException("index key " + ID + " is reserved by IdGraph"); } else { baseGraph.dropKeyIndex(key, elementClass); } }
Example #19
Source File: IdGraph.java From org.openntf.domino with Apache License 2.0 | 5 votes |
public <T extends Element> void createKeyIndex(final String key, final Class<T> elementClass, final Parameter... indexParameters) { if (elementClass == null) throw ExceptionFactory.classForElementCannotBeNull(); boolean v = isVertexClass(elementClass); boolean supported = ((v && supportVertexIds) || (!v && supportEdgeIds)); if (supported && key.equals(ID)) { throw new IllegalArgumentException("index key " + ID + " is reserved by IdGraph"); } else { baseGraph.createKeyIndex(key, elementClass, indexParameters); } }
Example #20
Source File: CachedChronoGraph.java From epcis with Apache License 2.0 | 5 votes |
/** * Add an edge to the graph. The added edges requires a recommended identifier, * a tail vertex, an head vertex, and a label. Like adding a vertex, the * provided object identifier may be ignored by the implementation. * * @param outVertexID: * the vertex on the tail of the edge * @param inVertexID: * the vertex on the head of the edge * @param label: * the label associated with the edge * @return the newly created edge */ public CachedChronoEdge addEdge(final String outVertexID, final String inVertexID, final String label) { if (label == null) throw ExceptionFactory.edgeLabelCanNotBeNull(); CachedEdgeID edgeID = new CachedEdgeID(this, outVertexID, label, inVertexID); CachedChronoEdge edge = this.edges.get(edgeID); if (edge == null) { edge = new CachedChronoEdge(outVertexID, inVertexID, label, this); this.edges.put(edgeID, edge); edge.getOutVertex().addOutEdge(edge); edge.getInVertex().addInEdge(edge); } return edge; }
Example #21
Source File: CachedChronoGraph.java From epcis with Apache License 2.0 | 3 votes |
/** * Add an edge to the graph. The added edges requires a recommended identifier, * a tail vertex, an head vertex, and a label. Like adding a vertex, the * provided object identifier may be ignored by the implementation. * * @param id: * outVertexID|label|inVertexID */ public CachedChronoEdge getEdge(String id) { if (null == id) throw ExceptionFactory.edgeIdCanNotBeNull(); CachedEdgeID edgeID = new CachedEdgeID(this, id); return this.edges.get(edgeID); }