org.apache.tinkerpop.gremlin.structure.util.ElementHelper Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.util.ElementHelper.
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: AbstractRdfDocumentGraphConsumer.java From baleen with Apache License 2.0 | 6 votes |
@SuppressWarnings({"rawtypes", "unchecked"}) private Individual addIndividual(OntModel model, Vertex v, String className) { OntClass ontClass = model.getOntClass(namespace + className); if (ontClass != null) { Individual individual = ontClass.createIndividual(namespace + v.id()); Map<String, List> propertyValueMap = ElementHelper.vertexPropertyValueMap(v); propertyValueMap .entrySet() .forEach( e -> { Property property = model.getProperty(namespace + e.getKey()); if (property != null) { e.getValue().forEach(value -> individual.addProperty(property, value.toString())); } }); return individual; } else { getMonitor().warn("Missing ontology class {}", className); } return null; }
Example #2
Source File: StarGraph.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) { if (null == this.vertexProperties || this.vertexProperties.isEmpty()) return Collections.emptyIterator(); else if (propertyKeys.length == 0) return (Iterator) this.vertexProperties.entrySet().stream() .flatMap(entry -> entry.getValue().stream()) .iterator(); else if (propertyKeys.length == 1) return (Iterator) this.vertexProperties.getOrDefault(propertyKeys[0], Collections.emptyList()).iterator(); else return (Iterator) this.vertexProperties.entrySet().stream() .filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys)) .flatMap(entry -> entry.getValue().stream()) .iterator(); }
Example #3
Source File: BlazeGraph.java From tinkerpop3 with GNU General Public License v2.0 | 6 votes |
/** * Helper to parse URIs from a list of element ids for lookup of * vertices or edges. * * @see #vertices(Object...) * @see #edges(Object...) */ private List<URI> validateIds(final Object... elementIds) { ElementHelper.validateMixedElementIds(Element.class, elementIds); return Stream.of(elementIds) .map(elementId -> { if (elementId instanceof String) { return (String) elementId; } else if (elementId instanceof Element) { final Object id = ((Element) elementId).id(); if (id instanceof String) { return (String) id; } } throw new IllegalArgumentException( "Unknown element id type: " + elementId + " ("+ elementId.getClass()+")"); }) .map(vf::elementURI) .collect(Collectors.toList()); }
Example #4
Source File: SqlgGraph.java From sqlg with MIT License | 6 votes |
@Override public Vertex addVertex(Object... keyValues) { if (this.tx().isInStreamingBatchMode()) { throw SqlgExceptions.invalidMode(String.format("Transaction is in %s, use streamVertex(Object ... keyValues)", this.tx().getBatchModeType().toString())); } if (this.tx().isInStreamingWithLockBatchMode()) { return internalStreamVertex(keyValues); } else { Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues); final Pair<Map<String, Object>, Map<String, Object>> keyValueMapPair = Pair.of(keyValueMapTriple.getMiddle(), keyValueMapTriple.getRight()); final Map<String, PropertyType> columns = keyValueMapTriple.getLeft(); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label); this.tx().readWrite(); this.getTopology().threadWriteLock(); VertexLabel vertexLabel = this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); if (!vertexLabel.hasIDPrimaryKey()) { Preconditions.checkArgument(columns.keySet().containsAll(vertexLabel.getIdentifiers()), "identifiers must be present %s", vertexLabel.getIdentifiers()); } return new SqlgVertex(this, false, false, schemaTablePair.getSchema(), schemaTablePair.getTable(), keyValueMapPair); } }
Example #5
Source File: HBaseBulkLoader.java From hgraphdb with Apache License 2.0 | 6 votes |
public Vertex addVertex(final Object... keyValues) { try { ElementHelper.legalPropertyKeyValueArray(keyValues); Object idValue = ElementHelper.getIdValue(keyValues).orElse(null); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); idValue = HBaseGraphUtils.generateIdIfNeeded(idValue); long now = System.currentTimeMillis(); HBaseVertex vertex = new HBaseVertex(graph, idValue, label, now, now, HBaseGraphUtils.propertiesToMap(keyValues)); vertex.validate(); Iterator<IndexMetadata> indices = vertex.getIndices(OperationType.WRITE); indexVertex(vertex, indices); Creator creator = new VertexWriter(graph, vertex); if (verticesMutator != null) verticesMutator.mutate(getMutationList(creator.constructInsertions())); return vertex; } catch (IOException e) { throw new HBaseGraphException(e); } }
Example #6
Source File: TinkerHelper.java From tinkerpop with Apache License 2.0 | 6 votes |
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; }
Example #7
Source File: TinkerHelper.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
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((long)idValue)) throw Graph.Exceptions.edgeWithIdAlreadyExists(idValue); } else { idValue = graph.edgeIdManager.getNextId(graph); } edge = new TinkerEdge(graph, idValue, outVertex, label, inVertex); ElementHelper.attachProperties(edge, keyValues); graph.edges.put((long)edge.id(), edge); TinkerHelper.addOutEdge(outVertex, label, edge); TinkerHelper.addInEdge(inVertex, label, edge); return edge; }
Example #8
Source File: TinkerGraph.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
private Vertex createVertex(final long idValue, final String label, final Object... keyValues) { final Vertex vertex; if (specializedVertexFactoryByLabel.containsKey(label)) { final SpecializedElementFactory.ForVertex factory = specializedVertexFactoryByLabel.get(label); final SpecializedTinkerVertex underlying = factory.createVertex(idValue, this); vertex = factory.createVertexRef(underlying); } else { // vertex label not registered for a specialized factory, treating as generic vertex if (this.usesSpecializedElements) { throw new IllegalArgumentException( "this instance of TinkerGraph uses specialized elements, but doesn't have a factory for label " + label + ". Mixing specialized and generic elements is not (yet) supported"); } vertex = new TinkerVertex(idValue, label, this); } ElementHelper.attachProperties(vertex, VertexProperty.Cardinality.list, keyValues); return vertex; }
Example #9
Source File: TinkerGraph.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Override public Vertex addVertex(final Object... keyValues) { if (isClosed()) { throw new IllegalStateException("cannot add more elements, graph is closed"); } ElementHelper.legalPropertyKeyValueArray(keyValues); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); Long idValue = (Long) vertexIdManager.convert(ElementHelper.getIdValue(keyValues).orElse(null)); if (null != idValue) { if (vertices.containsKey(idValue)) throw Exceptions.vertexWithIdAlreadyExists(idValue); } else { idValue = (Long) vertexIdManager.getNextId(this); } currentId.set(Long.max(idValue, currentId.get())); final Vertex vertex = createVertex(idValue, label, keyValues); vertices.put((long)vertex.id(), vertex); getElementsByLabel(verticesByLabel, label).add(vertex); return vertex; }
Example #10
Source File: StarGraph.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) { final Edge edge = this.addOutEdge(label, inVertex, keyValues); if (inVertex.equals(this)) { if (ElementHelper.getIdValue(keyValues).isPresent()) { // reuse edge ID from method params this.addInEdge(label, this, keyValues); } else { // copy edge ID that we just allocated with addOutEdge final Object[] keyValuesWithId = Arrays.copyOf(keyValues, keyValues.length + 2); keyValuesWithId[keyValuesWithId.length - 2] = T.id; keyValuesWithId[keyValuesWithId.length - 1] = edge.id(); this.addInEdge(label, this, keyValuesWithId); } } return edge; }
Example #11
Source File: Neo4jVertex.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) { ElementHelper.validateProperty(key, value); if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported(); this.graph.tx().readWrite(); if (cardinality != VertexProperty.Cardinality.single) throw VertexProperty.Exceptions.multiPropertiesNotSupported(); if (null == value) { properties(key).forEachRemaining(VertexProperty::remove); return VertexProperty.empty(); } if (keyValues.length > 0) throw VertexProperty.Exceptions.metaPropertiesNotSupported(); try { this.baseElement.setProperty(key, value); return new Neo4jVertexProperty<>(this, key, value); } catch (final IllegalArgumentException iae) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, iae); } }
Example #12
Source File: Neo4JEdge.java From neo4j-gremlin-bolt with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public <V> Property<V> property(String name, V value) { ElementHelper.validateProperty(name, value); // validate bolt support Neo4JBoltSupport.checkPropertyValue(value); // transaction should be ready for io operations graph.tx().readWrite(); // property value for key Neo4JEdgeProperty<V> propertyValue = new Neo4JEdgeProperty<>(this, name, value); // update map properties.put(name, propertyValue); // set edge as dirty session.dirtyEdge(this); // update flag dirty = true; // return property return propertyValue; }
Example #13
Source File: Neo4jEdge.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public <V> Property<V> property(final String key, final V value) { ElementHelper.validateProperty(key, value); if (null == value) { properties(key).forEachRemaining(Property::remove); return Property.empty(); } this.graph.tx().readWrite(); try { this.baseElement.setProperty(key, value); return new Neo4jProperty<>(this, key, value); } catch (final IllegalArgumentException e) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, e); } }
Example #14
Source File: StarGraph.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public <U> Property<U> property(final String key, final U value) { ElementHelper.validateProperty(key, value); if (null == metaProperties) metaProperties = new HashMap<>(); Map<String, Object> properties = metaProperties.get(this.id); if (null == properties) { properties = new HashMap<>(); metaProperties.put(this.id, properties); } properties.put(key, value); return new StarProperty<>(key, value, this); }
Example #15
Source File: TinkerVertexProperty.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Override public <U> Iterator<Property<U>> properties(final String... propertyKeys) { if (null == this.properties) return Collections.emptyIterator(); if (propertyKeys.length == 1) { final Property<U> property = this.properties.get(propertyKeys[0]); return null == property ? Collections.emptyIterator() : IteratorUtils.of(property); } else return (Iterator) this.properties.entrySet().stream().filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys)).map(entry -> entry.getValue()).collect(Collectors.toList()).iterator(); }
Example #16
Source File: SpecializedTinkerVertex.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Override public <V> VertexProperty<V> property(VertexProperty.Cardinality cardinality, String key, V value, Object... keyValues) { if (this.removed) throw elementAlreadyRemoved(Vertex.class, id); ElementHelper.legalPropertyKeyValueArray(keyValues); ElementHelper.validateProperty(key, value); synchronized (this) { this.modifiedSinceLastSerialization = true; final VertexProperty<V> vp = updateSpecificProperty(cardinality, key, value); TinkerHelper.autoUpdateIndex(this, key, value, null); return vp; } }
Example #17
Source File: TinkerVertexProperty.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public <U> Iterator<Property<U>> properties(final String... propertyKeys) { if (null == this.properties) return Collections.emptyIterator(); if (propertyKeys.length == 1) { final Property<U> property = this.properties.get(propertyKeys[0]); return null == property ? Collections.emptyIterator() : IteratorUtils.of(property); } else return (Iterator) this.properties.entrySet().stream().filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys)).map(entry -> entry.getValue()).collect(Collectors.toList()).iterator(); }
Example #18
Source File: StarGraph.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public <V> Property<V> property(final String key, final V value) { ElementHelper.validateProperty(key, value); if (null == edgeProperties) edgeProperties = new HashMap<>(); Map<String, Object> properties = edgeProperties.get(this.id); if (null == properties) { properties = new HashMap<>(); edgeProperties.put(this.id, properties); } properties.put(key, value); return new StarProperty<>(key, value, this); }
Example #19
Source File: ArangoDBVertexProperty.java From arangodb-tinkerpop-provider with Apache License 2.0 | 5 votes |
@Override public <U> Property<U> property(String key, U value) { logger.info("property {} = {}", key, value); ElementHelper.validateProperty(key, value); Property<U> p = property(key); if (!p.isPresent()) { p = ArangoDBUtil.createArangoDBPropertyProperty(key, value, this); } else { ((ArangoDBElementProperty<U>) p).value(value); } return p; }
Example #20
Source File: Neo4JVertex.java From neo4j-gremlin-bolt with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Edge addEdge(String label, Vertex vertex, Object... keyValues) { // validate label ElementHelper.validateLabel(label); // vertex must exist if (vertex == null) throw Graph.Exceptions.argumentCanNotBeNull("vertex"); // validate properties ElementHelper.legalPropertyKeyValueArray(keyValues); // transaction should be ready for io operations graph.tx().readWrite(); // add edge return session.addEdge(label, this, (Neo4JVertex)vertex, keyValues); }
Example #21
Source File: ConfigurationGroovyCustomizer.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Creates a new instance using configuration values specified */ ConfigurationGroovyCustomizer(final Object... keyValues) { if (null == keyValues || keyValues.length == 0) throw new IllegalArgumentException("ConfigurationCustomizerProvider must have key/values specified"); if (keyValues.length % 2 != 0) throw new IllegalArgumentException("The keyValues must have an even number of values"); properties = ElementHelper.asMap(keyValues); }
Example #22
Source File: SqlgUtil.java From sqlg with MIT License | 5 votes |
public static Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> validateVertexKeysValues(SqlDialect sqlDialect, Object[] keyValues, List<String> previousBatchModeKeys) { Map<String, Object> resultAllValues = new LinkedHashMap<>(); Map<String, Object> resultNotNullValues = new LinkedHashMap<>(); Map<String, PropertyType> keyPropertyTypeMap = new LinkedHashMap<>(); if (keyValues.length % 2 != 0) throw Element.Exceptions.providedKeyValuesMustBeAMultipleOfTwo(); int keyCount = 0; for (int i = 0; i < keyValues.length; i = i + 2) { if (!(keyValues[i] instanceof String) && !(keyValues[i] instanceof T)) { throw Element.Exceptions.providedKeyValuesMustHaveALegalKeyOnEvenIndices(); } if (keyValues[i].equals(T.id)) { throw Vertex.Exceptions.userSuppliedIdsNotSupported(); } if (!keyValues[i].equals(T.label)) { String key = (String) keyValues[i]; sqlDialect.validateColumnName(key); Object value = keyValues[i + 1]; if (value != null) { ElementHelper.validateProperty(key, value); sqlDialect.validateProperty(key, value); } if (value != null) { resultNotNullValues.put(key, value); keyPropertyTypeMap.put(key, PropertyType.from(value)); } else { keyPropertyTypeMap.put(key, PropertyType.STRING); } resultAllValues.put(key, value); if (previousBatchModeKeys != null && !previousBatchModeKeys.isEmpty() && !key.equals(previousBatchModeKeys.get(keyCount++))) { throw new IllegalStateException("Streaming batch mode must occur for the same keys in the same order. Expected " + previousBatchModeKeys.get(keyCount - 1) + " found " + key); } } } return Triple.of(keyPropertyTypeMap, resultAllValues, resultNotNullValues); }
Example #23
Source File: SqlgElement.java From sqlg with MIT License | 5 votes |
@Override public boolean equals(final Object object) { this.sqlgGraph.tx().readWrite(); if (this.sqlgGraph.features().supportsBatchMode() && this.sqlgGraph.tx().isInBatchMode()) { if (this.id() != null && (object instanceof SqlgElement) && ((SqlgElement) object).id() != null) { return ElementHelper.areEqual(this, object); } else { return super.equals(object); } } else { return ElementHelper.areEqual(this, object); } }
Example #24
Source File: StarGraph.java From tinkerpop with Apache License 2.0 | 5 votes |
Edge addOutEdge(final String label, final Vertex inVertex, final Object... keyValues) { ElementHelper.validateLabel(label); ElementHelper.legalPropertyKeyValueArray(keyValues); if (null == this.outEdges) this.outEdges = new HashMap<>(); List<Edge> outE = this.outEdges.get(label); if (null == outE) { outE = new ArrayList<>(); this.outEdges.put(label, outE); } final StarEdge outEdge = new StarOutEdge(ElementHelper.getIdValue(keyValues).orElse(nextId()), label, inVertex.id()); ElementHelper.attachProperties(outEdge, keyValues); outE.add(outEdge); return outEdge; }
Example #25
Source File: StarGraph.java From tinkerpop with Apache License 2.0 | 5 votes |
Edge addInEdge(final String label, final Vertex outVertex, final Object... keyValues) { ElementHelper.validateLabel(label); ElementHelper.legalPropertyKeyValueArray(keyValues); if (null == this.inEdges) this.inEdges = new HashMap<>(); List<Edge> inE = this.inEdges.get(label); if (null == inE) { inE = new ArrayList<>(); this.inEdges.put(label, inE); } final StarEdge inEdge = new StarInEdge(ElementHelper.getIdValue(keyValues).orElse(nextId()), label, outVertex.id()); ElementHelper.attachProperties(inEdge, keyValues); inE.add(inEdge); return inEdge; }
Example #26
Source File: SqlgGraph.java From sqlg with MIT License | 5 votes |
public void addTemporaryVertex(Object... keyValues) { if (this.tx().isInStreamingBatchMode()) { throw SqlgExceptions.invalidMode(String.format("Transaction is in %s, use streamVertex(Object ... keyValues)", this.tx().getBatchModeType().toString())); } Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label, true); final Map<String, PropertyType> columns = keyValueMapTriple.getLeft(); this.getTopology().ensureTemporaryVertexTableExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); final Pair<Map<String, Object>, Map<String, Object>> keyValueMapPair = Pair.of(keyValueMapTriple.getMiddle(), keyValueMapTriple.getRight()); new SqlgVertex(this, true, false, schemaTablePair.getSchema(), schemaTablePair.getTable(), keyValueMapPair); }
Example #27
Source File: HBaseBulkLoader.java From hgraphdb with Apache License 2.0 | 5 votes |
public Edge addEdge(Vertex outVertex, Vertex inVertex, String label, Object... keyValues) { try { if (null == inVertex) throw Graph.Exceptions.argumentCanNotBeNull("inVertex"); ElementHelper.validateLabel(label); ElementHelper.legalPropertyKeyValueArray(keyValues); Object idValue = ElementHelper.getIdValue(keyValues).orElse(null); idValue = HBaseGraphUtils.generateIdIfNeeded(idValue); long now = System.currentTimeMillis(); HBaseEdge edge = new HBaseEdge(graph, idValue, label, now, now, HBaseGraphUtils.propertiesToMap(keyValues), inVertex, outVertex); edge.validate(); Iterator<IndexMetadata> indices = edge.getIndices(OperationType.WRITE); indexEdge(edge, indices); EdgeIndexWriter writer = new EdgeIndexWriter(graph, edge, Constants.CREATED_AT); if (edgeIndicesMutator != null) edgeIndicesMutator.mutate(getMutationList(writer.constructInsertions())); Creator creator = new EdgeWriter(graph, edge); if (edgesMutator != null) edgesMutator.mutate(getMutationList(creator.constructInsertions())); return edge; } catch (IOException e) { throw new HBaseGraphException(e); } }
Example #28
Source File: VertexModel.java From hgraphdb with Apache License 2.0 | 5 votes |
public Iterator<Vertex> verticesWithLimit(String label, String key, Object from, int limit, boolean reversed) { ElementHelper.validateProperty(key, from != null ? from : new Object()); IndexMetadata index = graph.getIndex(OperationType.READ, ElementType.VERTEX, label, key); if (index != null) { LOGGER.debug("Using vertex index for ({}, {})", label, key); return graph.getVertexIndexModel().verticesWithLimit(label, index.isUnique(), key, from, limit, reversed); } throw new HBaseGraphNotValidException("Method verticesWithLimit requires an index be defined"); }
Example #29
Source File: HBaseElement.java From hgraphdb with Apache License 2.0 | 5 votes |
public void incrementProperty(String key, long value) { if (!graph.configuration().getUseSchema()) { throw new HBaseGraphNoSchemaException("Schema not enabled"); } ElementHelper.validateProperty(key, value); graph.validateProperty(getElementType(), label, key, value); updatedAt(System.currentTimeMillis()); Mutator writer = getModel().incrementProperty(this, key, value); long newValue = Mutators.increment(getTable(), writer, key); getProperties().put(key, newValue); }
Example #30
Source File: HBaseVertex.java From hgraphdb with Apache License 2.0 | 5 votes |
@Override public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) { Iterable<String> keys = getPropertyKeys(); Iterator<String> filter = IteratorUtils.filter(keys.iterator(), key -> ElementHelper.keyExists(key, propertyKeys)); return IteratorUtils.map(filter, key -> new HBaseVertexProperty<>(graph, this, key, getProperty(key))); }