Search in sources :

Example 1 with InternalIdStrategy

use of org.neo4j.ogm.id.InternalIdStrategy 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;
}
Also used : org.neo4j.ogm.annotation(org.neo4j.ogm.annotation) MetadataException(org.neo4j.ogm.exception.core.MetadataException) java.util(java.util) Logger(org.slf4j.Logger) IdStrategy(org.neo4j.ogm.id.IdStrategy) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AutoIndexManager(org.neo4j.ogm.autoindex.AutoIndexManager) LoggerFactory(org.slf4j.LoggerFactory) InternalIdStrategy(org.neo4j.ogm.id.InternalIdStrategy) InvalidPropertyFieldException(org.neo4j.ogm.exception.core.InvalidPropertyFieldException) Field(java.lang.reflect.Field) PrivilegedAction(java.security.PrivilegedAction) Direction(org.neo4j.ogm.annotation.Relationship.Direction) Collectors(java.util.stream.Collectors) Function(java.util.function.Function) InvocationTargetException(java.lang.reflect.InvocationTargetException) Matcher(java.util.regex.Matcher) TypeSystem(org.neo4j.ogm.driver.TypeSystem) Modifier(java.lang.reflect.Modifier) UuidStrategy(org.neo4j.ogm.id.UuidStrategy) MappingException(org.neo4j.ogm.exception.core.MappingException) AccessController(java.security.AccessController) MetadataException(org.neo4j.ogm.exception.core.MetadataException)

Aggregations

Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Modifier (java.lang.reflect.Modifier)1 AccessController (java.security.AccessController)1 PrivilegedAction (java.security.PrivilegedAction)1 java.util (java.util)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Matcher (java.util.regex.Matcher)1 Collectors (java.util.stream.Collectors)1 org.neo4j.ogm.annotation (org.neo4j.ogm.annotation)1 Direction (org.neo4j.ogm.annotation.Relationship.Direction)1 AutoIndexManager (org.neo4j.ogm.autoindex.AutoIndexManager)1 TypeSystem (org.neo4j.ogm.driver.TypeSystem)1 InvalidPropertyFieldException (org.neo4j.ogm.exception.core.InvalidPropertyFieldException)1 MappingException (org.neo4j.ogm.exception.core.MappingException)1 MetadataException (org.neo4j.ogm.exception.core.MetadataException)1 IdStrategy (org.neo4j.ogm.id.IdStrategy)1 InternalIdStrategy (org.neo4j.ogm.id.InternalIdStrategy)1