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; } }
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; } }
@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); } }
throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, iae);
return; throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value);
@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; } }
@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 IllegalArgumentException dataTypeOfPropertyValueNotSupported(final Object val) { return dataTypeOfPropertyValueNotSupported(val, null); }
@Override public <V> VertexProperty<V> setVertexProperty(final Neo4jVertex vertex, final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) { if (cardinality != VertexProperty.Cardinality.single) throw VertexProperty.Exceptions.multiPropertiesNotSupported(); if (keyValues.length > 0) throw VertexProperty.Exceptions.metaPropertiesNotSupported(); try { vertex.getBaseVertex().setProperty(key, value); return new Neo4jVertexProperty<>(vertex, key, value); } catch (final IllegalArgumentException iae) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, iae); } }
@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.EdgeFeatures.class, feature = EdgeFeatures.FEATURE_ADD_PROPERTY) public void shouldEnableFeatureOnEdgeIfNotEnabled() throws Exception { assumeThat(graph.features().supports(EdgePropertyFeatures.class, featureName), is(false)); try { final Edge edge = createEdgeForPropertyFeatureTests(); edge.property("aKey", value); fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgePropertyFeatures.class.getSimpleName(), featureName)); } catch (Exception e) { validateException(Property.Exceptions.dataTypeOfPropertyValueNotSupported(value), e); } }
@Override public <V> Property<V> property(final String key, final V value) { ElementHelper.validateProperty(key, value); 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); } } }
public static PropertyType from(Object o) { PropertyType propertyType = JAVA_CLASS_NAME_TO_ENUM.get(o.getClass().getName()); if (propertyType == null && (o instanceof JsonNode)) { propertyType = JAVA_CLASS_NAME_TO_ENUM.get(JsonNode.class.getName()); } else if (propertyType == null && (o instanceof JsonNode[])) { propertyType = JAVA_CLASS_NAME_TO_ENUM.get(JsonNode[].class.getName()); } if (propertyType == null) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(o); } return propertyType; }
@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 PropertyType from(Object o) { PropertyType propertyType = JAVA_CLASS_NAME_TO_ENUM.get(o.getClass().getName()); if (propertyType == null && (o instanceof JsonNode)) { propertyType = JAVA_CLASS_NAME_TO_ENUM.get(JsonNode.class.getName()); } else if (propertyType == null && (o instanceof JsonNode[])) { propertyType = JAVA_CLASS_NAME_TO_ENUM.get(JsonNode[].class.getName()); } if (propertyType == null) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(o); } return propertyType; }
throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, iae);
public static IllegalArgumentException dataTypeOfPropertyValueNotSupported(final Object val) { return dataTypeOfPropertyValueNotSupported(val, null); }
@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.EdgeFeatures.class, feature = EdgeFeatures.FEATURE_ADD_PROPERTY) public void shouldEnableFeatureOnEdgeIfNotEnabled() throws Exception { assumeThat(graph.features().supports(EdgePropertyFeatures.class, featureName), is(false)); try { final Edge edge = createEdgeForPropertyFeatureTests(); edge.property("aKey", value); fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgePropertyFeatures.class.getSimpleName(), featureName)); } catch (Exception e) { validateException(Property.Exceptions.dataTypeOfPropertyValueNotSupported(value), e); } }
@Override public <V> VertexProperty<V> setVertexProperty(final Neo4jVertex vertex, final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) { if (cardinality != VertexProperty.Cardinality.single) throw VertexProperty.Exceptions.multiPropertiesNotSupported(); if (keyValues.length > 0) throw VertexProperty.Exceptions.metaPropertiesNotSupported(); try { vertex.getBaseVertex().setProperty(key, value); return new Neo4jVertexProperty<>(vertex, key, value); } catch (final IllegalArgumentException iae) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(value, iae); } }
@Override public <V> Property<V> property(final String key, final V value) { ElementHelper.validateProperty(key, value); 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); } } }