use of org.neo4j.ogm.exception.core.MetadataException in project neo4j-ogm by neo4j.
the class ClassInfo method getCompositeIndexes.
public Collection<CompositeIndex> getCompositeIndexes() {
Collection<CompositeIndex> result = this.compositeIndexes;
if (result == null) {
synchronized (this) {
result = this.compositeIndexes;
if (result == null) {
CompositeIndex[] annotations = cls.getDeclaredAnnotationsByType(CompositeIndex.class);
List<CompositeIndex> intermediateResult = new ArrayList<>(annotations.length);
for (CompositeIndex annotation : annotations) {
String[] properties = annotation.value().length > 0 ? annotation.value() : annotation.properties();
if (properties.length < 1) {
throw new MetadataException("Incorrect CompositeIndex definition on " + className + ". Provide at least 1 property");
}
for (String property : properties) {
// Determine the original field in case the user uses a MapCompositeConverter.
Matcher m = AutoIndexManager.COMPOSITE_KEY_MAP_COMPOSITE_PATTERN.matcher(property);
if (m.matches()) {
property = m.group(1);
}
FieldInfo fieldInfo = propertyField(property);
if (fieldInfo == null) {
throw new MetadataException("Incorrect CompositeIndex definition on " + className + ". Property " + property + " does not exists.");
}
}
intermediateResult.add(annotation);
}
this.compositeIndexes = Collections.unmodifiableList(intermediateResult);
result = this.compositeIndexes;
}
}
}
return result;
}
use of org.neo4j.ogm.exception.core.MetadataException in project neo4j-ogm by neo4j.
the class ClassInfo method getOrComputeIdentityField.
private Optional<FieldInfo> getOrComputeIdentityField() {
Optional<FieldInfo> result = this.identityField;
if (result == null) {
synchronized (this) {
result = this.identityField;
if (result == null) {
// Didn't want to add yet another method related to determining the identy field
// so the actual resolving of the field inside the Double-checked locking here
// has been inlined.
Collection<FieldInfo> identityFields = getFieldInfos(FieldInfo::isInternalIdentity);
if (identityFields.size() == 1) {
this.identityField = Optional.of(identityFields.iterator().next());
} else if (identityFields.size() > 1) {
throw new MetadataException("Expected exactly one internal identity field (@Id with " + "InternalIdStrategy), found " + identityFields.size() + " " + identityFields);
} else {
this.identityField = fieldsInfo.fields().stream().filter(f -> "id".equals(f.getName())).filter(f -> "java.lang.Long".equals(f.getTypeDescriptor())).findFirst();
}
result = this.identityField;
}
}
}
return result;
}
Aggregations