public ElementType toElementType() { switch (this) { case VERTEX: case VERTEX_EXTENDED_DATA: return ElementType.VERTEX; case EDGE: case EDGE_EXTENDED_DATA: return ElementType.EDGE; } throw new VertexiumException("Unhandled type: " + this); }
@Override public InputStream getInputStream() { try { return fs.open(this.path); } catch (IOException ex) { throw new VertexiumException("Could not open: " + this.path, ex); } } }
@SuppressWarnings("unchecked") public Class<? extends T> getMinMaxType() { if (min != null) { return (Class<? extends T>) min.getClass(); } if (max != null) { return (Class<? extends T>) max.getClass(); } throw new VertexiumException("Invalid state. min or max must not be null."); } }
@Override public String nextId() { synchronized (ids) { if (ids.size() == 0) { throw new VertexiumException("No ids in the queue to give out"); } return ids.remove(); } }
public HasNotPropertyContainer(Class dataType, Collection<PropertyDefinition> propertyDefinitions) { this.keys = propertyDefinitions.stream() .filter(propertyDefinition -> isPropertyOfType(propertyDefinition, dataType)) .map(PropertyDefinition::getPropertyName) .collect(Collectors.toSet()); if (this.keys.isEmpty()) { throw new VertexiumException("Invalid query parameters, no properties of type " + dataType.getName() + " found"); } }
@Override public SimilarToGraphQuery minTermFrequency(int minTermFrequency) { if (!(parameters instanceof SimilarToQueryParameters)) { throw new VertexiumException("Invalid query parameters, expected " + SimilarToQueryParameters.class.getName() + " found " + parameters.getClass().getName()); } ((SimilarToQueryParameters) this.parameters).setMinTermFrequency(minTermFrequency); return this; }
@Override public SimilarToGraphQuery maxQueryTerms(int maxQueryTerms) { if (!(parameters instanceof SimilarToQueryParameters)) { throw new VertexiumException("Invalid query parameters, expected " + SimilarToQueryParameters.class.getName() + " found " + parameters.getClass().getName()); } ((SimilarToQueryParameters) this.parameters).setMaxQueryTerms(maxQueryTerms); return this; }
private BatchWriter getWriterForTable(String tableName) { try { return batchWriter.getBatchWriter(tableName); } catch (Exception e) { throw new VertexiumException("Unable to get writer for table " + tableName, e); } }
@SuppressWarnings("unchecked") private static Collection<Class<? extends Plugin>> loadTransportClientPlugins(ElasticsearchSearchIndexConfiguration config) { return config.getEsPluginClassNames().stream() .map(pluginClassName -> { try { return (Class<? extends Plugin>) Class.forName(pluginClassName); } catch (ClassNotFoundException ex) { throw new VertexiumException("Could not load transport client plugin: " + pluginClassName, ex); } }) .collect(Collectors.toList()); }
public Row map(int index, ResultSet rs, StatementContext ctx) throws SQLException { try { Row row = new Row(); row.valueType = Class.forName(rs.getString(VALUE_TYPE_COLUMN_NAME)); row.length = rs.getLong(VALUE_LENGTH_COLUMN_NAME); return row; } catch (ClassNotFoundException ex) { throw new VertexiumException(ex); } } }
private AuthorizationsProvider createAuthorizationsProvider(AccumuloGraph graph, GraphConfiguration config) { try { return ConfigurationUtils.createProvider(graph, config, "authorizationsProvider", null); } catch (Exception ex) { throw new VertexiumException("Could not create authorization provider", ex); } } }
public String readToString(long offset, long limit) { try (InputStream in = getInputStream()) { return IOUtils.toString(in, offset, limit); } catch (IOException e) { throw new VertexiumException("Could not read streaming property value into string", e); } }
private void saveElementMutation(ElementType elementType, Mutation m) { switch (elementType) { case VERTEX: saveVertexMutation(m); break; case EDGE: saveEdgeMutation(m); break; default: throw new VertexiumException("Unhandled element type: " + elementType); } }
public static ElasticsearchDocumentType parse(String s) { if (s.equals(VERTEX.getKey())) { return VERTEX; } else if (s.equals(EDGE.getKey())) { return EDGE; } else if (s.equals(VERTEX_EXTENDED_DATA.getKey())) { return VERTEX_EXTENDED_DATA; } else if (s.equals(EDGE_EXTENDED_DATA.getKey())) { return EDGE_EXTENDED_DATA; } throw new VertexiumException("Could not parse element type: " + s); }
private Map<Object, Map<Object, Long>> nestedTermsBucketToMap(Iterable<TermsBucket> buckets, String nestedAggName) { Map<Object, Map<Object, Long>> results = new HashMap<>(); for (TermsBucket entry : buckets) { TermsResult nestedResults = (TermsResult) entry.getNestedResults().get(nestedAggName); if (nestedResults == null) { throw new VertexiumException("Could not find nested: " + nestedAggName); } results.put(entry.getKey(), termsBucketToMap(nestedResults.getBuckets())); } return results; }
@Override public CypherInteger visitOC_IntegerLiteral(CypherParser.OC_IntegerLiteralContext ctx) { try { return new CypherInteger(Long.decode(ctx.getText())); } catch (NumberFormatException ex) { throw new VertexiumException("could not parse \"" + ctx.getText() + "\" into integer"); } }
public BatchWriter getWriterFromElementType(VertexiumObjectType objectType) { switch (objectType) { case VERTEX: return getVerticesWriter(); case EDGE: return getEdgesWriter(); case EXTENDED_DATA: return getExtendedDataWriter(); default: throw new VertexiumException("Unexpected object type: " + objectType); } }
public static SearchResponse checkForFailures(SearchResponse searchResponse) { ShardSearchFailure[] shardFailures = searchResponse.getShardFailures(); if (shardFailures.length > 0) { for (ShardSearchFailure shardFailure : shardFailures) { LOGGER.error("search response shard failure", shardFailure.getCause()); } throw new VertexiumException("search response shard failures", shardFailures[0].getCause()); } return searchResponse; } }
protected void doBulkRequest(BulkRequest bulkRequest) { BulkResponse response = getClient().bulk(bulkRequest).actionGet(); if (response.hasFailures()) { for (BulkItemResponse bulkResponse : response) { if (bulkResponse.isFailed()) { LOGGER.error("Failed to index %s (message: %s)", bulkResponse.getId(), bulkResponse.getFailureMessage()); } } throw new VertexiumException("Could not add element."); } }
protected void doBulkRequest(BulkRequest bulkRequest) { BulkResponse response = getClient().bulk(bulkRequest).actionGet(); if (response.hasFailures()) { for (BulkItemResponse bulkResponse : response) { if (bulkResponse.isFailed()) { LOGGER.error("Failed to index %s (message: %s)", bulkResponse.getId(), bulkResponse.getFailureMessage()); } } throw new VertexiumException("Could not add element."); } }