Search in sources :

Example 1 with InvalidPropertyFieldException

use of org.neo4j.ogm.exception.core.InvalidPropertyFieldException in project neo4j-ogm by neo4j.

the class ClassInfo method getOrComputePropertyFields.

private Map<String, FieldInfo> getOrComputePropertyFields() {
    Map<String, FieldInfo> result = this.propertyFields;
    if (result == null) {
        synchronized (this) {
            result = this.propertyFields;
            if (result == null) {
                Collection<FieldInfo> fields = fieldsInfo().fields();
                FieldInfo optionalIdentityField = identityFieldOrNull();
                Map<String, FieldInfo> intermediateFieldMap = new HashMap<>(fields.size());
                for (FieldInfo fieldInfo : fields) {
                    if (fieldInfo == optionalIdentityField || fieldInfo.isLabelField() || fieldInfo.hasAnnotation(StartNode.class) || fieldInfo.hasAnnotation(EndNode.class)) {
                        continue;
                    }
                    if (!fieldInfo.getAnnotations().has(Property.class)) {
                        // If a field is not marked explicitly as a property but is persistable as such, add it.
                        if (fieldInfo.persistableAsProperty()) {
                            intermediateFieldMap.put(fieldInfo.property(), fieldInfo);
                        }
                    } else if (fieldInfo.persistableAsProperty()) {
                        // If it is marked as a property, then it should be persistable as such
                        intermediateFieldMap.put(fieldInfo.property(), fieldInfo);
                    } else {
                        // Otherwise, throw a fitting exception
                        throw new InvalidPropertyFieldException(fieldInfo);
                    }
                }
                this.propertyFields = Collections.unmodifiableMap(intermediateFieldMap);
                result = this.propertyFields;
            }
        }
    }
    return result;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InvalidPropertyFieldException(org.neo4j.ogm.exception.core.InvalidPropertyFieldException)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 InvalidPropertyFieldException (org.neo4j.ogm.exception.core.InvalidPropertyFieldException)1