Search in sources :

Example 1 with SimpleAssociationHandler

use of org.springframework.data.mapping.SimpleAssociationHandler in project spring-data-commons by spring-projects.

the class ClassGeneratingPropertyAccessorFactory method hasUniquePropertyHashCodes.

private boolean hasUniquePropertyHashCodes(PersistentEntity<?, ?> entity) {
    Set<Integer> hashCodes = new HashSet<>();
    AtomicInteger propertyCount = new AtomicInteger();
    entity.doWithProperties((SimplePropertyHandler) property -> {
        hashCodes.add(property.getName().hashCode());
        propertyCount.incrementAndGet();
    });
    entity.doWithAssociations((SimpleAssociationHandler) association -> {
        if (association.getInverse() != null) {
            hashCodes.add(association.getInverse().getName().hashCode());
            propertyCount.incrementAndGet();
        }
    });
    return hashCodes.size() == propertyCount.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClassWriter(org.springframework.asm.ClassWriter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Label(org.springframework.asm.Label) HashMap(java.util.HashMap) TypeInformation(org.springframework.data.util.TypeInformation) Constructor(java.lang.reflect.Constructor) PersistentPropertyAccessor(org.springframework.data.mapping.PersistentPropertyAccessor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Optionals(org.springframework.data.util.Optionals) Map(java.util.Map) Opcodes(org.springframework.asm.Opcodes) Nullable(org.springframework.lang.Nullable) Method(java.lang.reflect.Method) PersistentProperty(org.springframework.data.mapping.PersistentProperty) NonNull(lombok.NonNull) ReflectUtils(org.springframework.cglib.core.ReflectUtils) Member(java.lang.reflect.Member) SimpleAssociationHandler(org.springframework.data.mapping.SimpleAssociationHandler) Set(java.util.Set) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) PersistentEntity(org.springframework.data.mapping.PersistentEntity) List(java.util.List) ReflectionUtils(org.springframework.util.ReflectionUtils) Modifier(java.lang.reflect.Modifier) ProtectionDomain(java.security.ProtectionDomain) Optional(java.util.Optional) MethodVisitor(org.springframework.asm.MethodVisitor) Collections(java.util.Collections) SimplePropertyHandler(org.springframework.data.mapping.SimplePropertyHandler) Type(org.springframework.asm.Type) Assert(org.springframework.util.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashSet(java.util.HashSet)

Aggregations

Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1 Member (java.lang.reflect.Member)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 ProtectionDomain (java.security.ProtectionDomain)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 NonNull (lombok.NonNull)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 ClassWriter (org.springframework.asm.ClassWriter)1 Label (org.springframework.asm.Label)1