Java Code Examples for org.apache.tinkerpop.gremlin.structure.util.ElementHelper#validateProperty()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.util.ElementHelper#validateProperty() . 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: Neo4jEdge.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: Neo4jVertex.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: Neo4JEdge.java    From neo4j-gremlin-bolt with Apache License 2.0 6 votes vote down vote up
/**
 * {@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 4
Source File: VertexModel.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
public Iterator<Vertex> vertices(String label, String key, Object value) {
    ElementHelper.validateProperty(key, value);
    IndexMetadata index = graph.getIndex(OperationType.READ, ElementType.VERTEX, label, key);
    if (index != null) {
        LOGGER.debug("Using vertex index for ({}, {})", label, key);
        return graph.getVertexIndexModel().vertices(label, index.isUnique(), key, value);
    }
    final VertexReader parser = new VertexReader(graph);

    byte[] val = ValueUtils.serializePropertyValue(graph, ElementType.VERTEX, label, key, value);
    final byte[] keyBytes = Bytes.toBytes(key);
    Scan scan = getPropertyScan(label, keyBytes, val);
    ResultScanner scanner = null;
    try {
        scanner = table.getScanner(scan);
        return HBaseGraphUtils.mapWithCloseAtEnd(scanner, parser::parse);
    } catch (IOException e) {
        throw new HBaseGraphException(e);
    }
}
 
Example 5
Source File: VertexModel.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
public Iterator<Vertex> verticesInRange(String label, String key, Object inclusiveFrom, Object exclusiveTo) {
    ElementHelper.validateProperty(key, inclusiveFrom);
    ElementHelper.validateProperty(key, exclusiveTo);
    IndexMetadata index = graph.getIndex(OperationType.READ, ElementType.VERTEX, label, key);
    if (index != null) {
        LOGGER.debug("Using vertex index for ({}, {})", label, key);
        return graph.getVertexIndexModel().verticesInRange(label, index.isUnique(), key, inclusiveFrom, exclusiveTo);
    }
    final VertexReader parser = new VertexReader(graph);

    byte[] fromVal = ValueUtils.serializePropertyValue(graph, ElementType.VERTEX, label, key, inclusiveFrom);
    byte[] toVal = ValueUtils.serializePropertyValue(graph, ElementType.VERTEX, label, key, exclusiveTo);
    final byte[] keyBytes = Bytes.toBytes(key);
    Scan scan = getPropertyScan(label, keyBytes, fromVal, toVal);
    ResultScanner scanner = null;
    try {
        scanner = table.getScanner(scan);
        return HBaseGraphUtils.mapWithCloseAtEnd(scanner, parser::parse);
    } catch (IOException e) {
        throw new HBaseGraphException(e);
    }
}
 
Example 6
Source File: VertexModel.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
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 7
Source File: TinkerGraphComputerView.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public <V> Property<V> addProperty(final TinkerVertex vertex, final String key, final V value) {
    ElementHelper.validateProperty(key, value);
    if (isComputeKey(key)) {
        final TinkerVertexProperty<V> property = new TinkerVertexProperty<V>((TinkerVertex) vertex, key, value) {
            @Override
            public void remove() {
                removeProperty(vertex, key, this);
            }
        };
        this.addValue(vertex, key, property);
        return property;
    } else {
        throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key);
    }
}
 
Example 8
Source File: SqlgUtil.java    From sqlg with MIT License 5 votes vote down vote up
/**
 * Validates the key values and converts it into a Triple with three maps.
 * The left  map is a map of keys together with their PropertyType.
 * The middle map is a map of keys together with their values.
 * The right map is a map of keys with values where the values are guaranteed not to be null.
 *
 * @param sqlDialect The dialect.
 * @param keyValues  The key value pairs.
 * @return A Triple with 3 maps.
 */
public static Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> validateVertexKeysValues(SqlDialect sqlDialect, Object[] keyValues) {
    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();

    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];
            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);
        }
    }
    return Triple.of(keyPropertyTypeMap, resultAllValues, resultNotNullValues);
}
 
Example 9
Source File: ArangoDBEdge.java    From arangodb-tinkerpop-provider with Apache License 2.0 5 votes vote down vote up
@Override
public <V> Property<V> property(
	String key,
	V value) {
	logger.info("set property {} = {}", key, value);
	ElementHelper.validateProperty(key, value);
	Property<V> p = property(key);
	if (!p.isPresent()) {
           p = ArangoDBUtil.createArangoDBEdgeProperty(key, value, this);
       }
	else {
		((ArangoDBEdgeProperty<V>) p).value(value);
	}
	return p;
}
 
Example 10
Source File: SqlgVertex.java    From sqlg with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <V> VertexProperty<V> property(final String key, final V value) {
    if (this.removed) {
        throw new IllegalStateException(String.format("Vertex with id %s was removed.", id().toString()));
    }
    ElementHelper.validateProperty(key, value);
    this.sqlgGraph.tx().readWrite();
    return (VertexProperty<V>) super.property(key, value);
}
 
Example 11
Source File: SqlgUtil.java    From sqlg with MIT License 5 votes vote down vote up
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 12
Source File: TinkerEdge.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Override
public <V> Property<V> property(final String key, final V value) {
    if (this.removed) throw elementAlreadyRemoved(Edge.class, id);
    ElementHelper.validateProperty(key, value);
    final Property oldProperty = super.property(key);
    final Property<V> newProperty = new TinkerProperty<>(this, key, value);
    if (null == this.properties) this.properties = new HashMap<>();
    this.properties.put(key, newProperty);
    TinkerHelper.autoUpdateIndex(this, key, value, oldProperty.isPresent() ? oldProperty.value() : null);
    return newProperty;

}
 
Example 13
Source File: ArangoDBVertexProperty.java    From arangodb-tinkerpop-provider with Apache License 2.0 5 votes vote down vote up
@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 14
Source File: HBaseGraphUtils.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> propertiesToMap(Object... keyValues) {
    Map<String, Object> props = new HashMap<>();
    for (int i = 0; i < keyValues.length; i = i + 2) {
        Object key = keyValues[i];
        if (key.equals(T.id) || key.equals(T.label)) continue;
        String keyStr = key.toString();
        Object value = keyValues[i + 1];
        ElementHelper.validateProperty(keyStr, value);
        props.put(keyStr, value);
    }
    return props;
}
 
Example 15
Source File: BlazeVertex.java    From tinkerpop3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Strengthen return type to {@link BlazeVertexProperty}.
 * 
 * @see BlazeGraph#vertexProperty(BlazeVertex, Cardinality, String, Object, Object...)
 */
@Override
public <V> BlazeVertexProperty<V> property(final Cardinality cardinality, 
        final String key, final V val, final Object... kvs) {
    ElementHelper.validateProperty(key, val);
    if (ElementHelper.getIdValue(kvs).isPresent())
        throw Vertex.Exceptions.userSuppliedIdsNotSupported();
    
    return graph.vertexProperty(this, cardinality, key, val, kvs);
}
 
Example 16
Source File: TinkerGraphComputerView.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
public <V> Property<V> addProperty(final TinkerVertex vertex, final String key, final V value) {
    ElementHelper.validateProperty(key, value);
    if (isComputeKey(key)) {
        final TinkerVertexProperty<V> property = new TinkerVertexProperty<V>((TinkerVertex) vertex, key, value) {
            @Override
            public void remove() {
                removeProperty(vertex, key, this);
            }
        };
        this.addValue(vertex, key, property);
        return property;
    } else {
        throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key);
    }
}
 
Example 17
Source File: SpecializedTinkerEdge.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Override
public <V> Property<V> property(String key, V value) {
    if (this.removed) throw elementAlreadyRemoved(Edge.class, id);
    ElementHelper.validateProperty(key, value);
    synchronized (this) {
        modifiedSinceLastSerialization = true;
        final Property<V> p = updateSpecificProperty(key, value);
        TinkerHelper.autoUpdateIndex(this, key, value, null);
        return p;
    }
}
 
Example 18
Source File: SpecializedTinkerVertex.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@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 19
Source File: BlazeReifiedElement.java    From tinkerpop3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Pass through to {@link BlazeGraph#property(BlazeReifiedElement, String, Object)}
 */
default <V> BlazeProperty<V> property(final String key, final V val) {
    ElementHelper.validateProperty(key, val);
    return graph().property(this, key, val);
}
 
Example 20
Source File: VertexComputeKey.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
private VertexComputeKey(final String key, final boolean isTransient) {
    this.key = key;
    this.isTransient = isTransient;
    ElementHelper.validateProperty(key, key);
}