@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) public void shouldEnableFeatureOnVertexIfNotEnabled() throws Exception { assumeThat(graph.features().supports(VertexPropertyFeatures.class, featureName), is(false)); try { graph.addVertex("aKey", value); fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), featureName)); } catch (Exception e) { validateException(Property.Exceptions.dataTypeOfPropertyValueNotSupported(value), e); } }
public static void checkTypeName(JanusGraphSchemaCategory category, String name) { switch (category) { case EDGELABEL: case VERTEXLABEL: if (name == null) throw Element.Exceptions.labelCanNotBeNull(); if (StringUtils.isBlank(name)) throw Element.Exceptions.labelCanNotBeEmpty(); break; case PROPERTYKEY: if (name == null) throw Property.Exceptions.propertyKeyCanNotBeNull(); if (StringUtils.isBlank(name)) throw Property.Exceptions.propertyKeyCanNotBeEmpty(); break; case GRAPHINDEX: Preconditions.checkArgument(StringUtils.isNotBlank(name),"Index name cannot be empty: %s",name); break; default: throw new AssertionError(category); } }
throw Property.Exceptions.propertyValueCanNotBeNull();
return; throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value);
return; throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value);
throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, iae);
return; throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value);
throw Property.Exceptions.propertyValueCanNotBeNull();
throw Property.Exceptions.propertyValueCanNotBeNull();
throw Property.Exceptions.propertyValueCanNotBeNull();
@Override public <V> DuctileVertexProperty<V> property(Cardinality cardinality, String key, V value, Object... keyValues) { if (cardinality != VertexProperty.Cardinality.single) { throw VertexProperty.Exceptions.multiPropertiesNotSupported(); } if (keyValues.length > 0) { throw VertexProperty.Exceptions.metaPropertiesNotSupported(); } ElementHelper.validateProperty(key, value); if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported(); graph().tx().readWrite(); try { if (value == null) { getBaseVertex().removeProperty(key); } else { getBaseVertex().setProperty(key, value); } return new DuctileVertexProperty<V>(this, key, value); } catch (final IllegalArgumentException iae) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value); } }
public final Object verifyAttribute(PropertyKey key, Object attribute) { if (attribute==null) throw new SchemaViolationException("Property value cannot be null"); Class<?> datatype = key.dataType(); if (datatype.equals(Object.class)) { if (!attributeHandler.validDataType(attribute.getClass())) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(attribute); } return attribute; } else { if (!attribute.getClass().equals(datatype)) { Object converted = null; try { converted = attributeHandler.convert(datatype, attribute); } catch (IllegalArgumentException e) { //Just means that data could not be converted } if (converted == null) throw new SchemaViolationException( "Value [%s] is not an instance of the expected data type for property key [%s] and cannot be converted. Expected: %s, found: %s", attribute, key.name(), datatype, attribute.getClass()); attribute = converted; } assert (attribute.getClass().equals(datatype)); attributeHandler.verifyAttribute(datatype, attribute); return attribute; } }
/** * Determines whether a list of key/values are legal, ensuring that there are an even number of values submitted * and that the key values in the list of arguments are {@link String} or {@link org.apache.tinkerpop.gremlin.structure.Element} objects. * * @param propertyKeyValues a list of key/value pairs * @throws IllegalArgumentException if something in the pairs is illegal */ public static void legalPropertyKeyValueArray(final Object... propertyKeyValues) throws IllegalArgumentException { if (propertyKeyValues.length % 2 != 0) throw Element.Exceptions.providedKeyValuesMustBeAMultipleOfTwo(); for (int i = 0; i < propertyKeyValues.length; i = i + 2) { if (!(propertyKeyValues[i] instanceof String) && !(propertyKeyValues[i] instanceof T)) throw Element.Exceptions.providedKeyValuesMustHaveALegalKeyOnEvenIndices(); if (null == propertyKeyValues[i + 1]) { throw Property.Exceptions.propertyValueCanNotBeNull(); } } }
/** * Determines whether the property key/value for the specified thing can be legally set. This is typically used as * a pre-condition check prior to setting a property. * * @param key the key of the property * @param value the value of the property * @throws IllegalArgumentException whether the key/value pair is legal and if not, a clear reason exception * message is provided */ public static void validateProperty(final String key, final Object value) throws IllegalArgumentException { if (null == value) throw Property.Exceptions.propertyValueCanNotBeNull(); if (null == key) throw Property.Exceptions.propertyKeyCanNotBeNull(); if (key.isEmpty()) throw Property.Exceptions.propertyKeyCanNotBeEmpty(); if (Graph.Hidden.isHidden(key)) throw Property.Exceptions.propertyKeyCanNotBeAHiddenKey(key); }
private <V> Property<V> property(final String key, final V value, boolean saveDocument) { if (key == null) throw Property.Exceptions.propertyKeyCanNotBeNull(); if (value == null) throw Property.Exceptions.propertyValueCanNotBeNull(); if (Graph.Hidden.isHidden(key)) throw Property.Exceptions.propertyKeyCanNotBeAHiddenKey(key); this.graph.tx().readWrite(); OElement doc = getRawElement(); doc.setProperty(key, value); // when setting multiple properties at once, it makes sense to only save // them in the end // for performance reasons and so that the schema checker only kicks in // at the end if (saveDocument) doc.save(); return new OrientProperty<>(key, value, this); }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = FEATURE_PROPERTIES) public void shouldGetValueThatIsNotPresentOnEdge() { final Vertex v = graph.addVertex(); final Edge e = v.addEdge("self", v); try { e.value("doesnotexist"); fail("Call to Element.value() with a key that is not present should throw an exception"); } catch (Exception ex) { validateException(Property.Exceptions.propertyDoesNotExist(e, "doesnotexist"), ex); } } }
@Override public <V> Property<V> property(String key, V value) { ElementHelper.validateProperty(key, value); graph().tx().readWrite(); try { if (value == null) { getBaseEdge().removeProperty(key); } else { getBaseEdge().setProperty(key, value); } return new DuctileProperty<>(this, key, value); } catch (final IllegalArgumentException e) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value); } }
public static void checkTypeName(TitanSchemaCategory category, String name) { switch (category) { case EDGELABEL: case VERTEXLABEL: if (name == null) throw Element.Exceptions.labelCanNotBeNull(); if (StringUtils.isBlank(name)) throw Element.Exceptions.labelCanNotBeEmpty(); break; case PROPERTYKEY: if (name == null) throw Property.Exceptions.propertyKeyCanNotBeNull(); if (StringUtils.isBlank(name)) throw Property.Exceptions.propertyKeyCanNotBeEmpty(); break; case GRAPHINDEX: Preconditions.checkArgument(StringUtils.isNotBlank(name),"Index name cannot be empty: %s",name); break; default: throw new AssertionError(category); } }
@Test @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = EdgeFeatures.FEATURE_REMOVE_PROPERTY, supported = false) @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldSupportRemovePropertyIfAPropertyCanBeRemoved() throws Exception { try { final Vertex v = graph.addVertex(); final Edge e = v.addEdge("self", v, "name", "foo"); e.property("name").remove(); fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), EdgeFeatures.FEATURE_REMOVE_PROPERTY)); } catch (Exception ex) { validateException(Property.Exceptions.propertyRemovalNotSupported(), ex); } } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = VertexPropertyFeatures.FEATURE_REMOVE_PROPERTY, supported = false) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = VertexFeatures.FEATURE_META_PROPERTIES) @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldSupportRemovePropertyIfAPropertyCanBeRemoved() throws Exception { try { final Vertex v = graph.addVertex(); final VertexProperty p = v.property(VertexProperty.Cardinality.single, "name", "me", "test", "this"); p.property("test").remove(); fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), VertexPropertyFeatures.FEATURE_REMOVE_PROPERTY)); } catch (Exception ex) { validateException(Property.Exceptions.propertyRemovalNotSupported(), ex); } }