Revert "DATAGRAPH-441 - Adapt to latest changes in Spring Data Commons mapping metadata API."
This reverts commit 48ab04c3da.
This commit is contained in:
@@ -36,7 +36,7 @@ public class JpaIdFieldAccessListenerFactory implements FieldAccessorListenerFac
|
||||
|
||||
@Override
|
||||
public boolean accept(final Neo4jPersistentProperty property) {
|
||||
return property.findAnnotation(Id.class) != null;
|
||||
return property.getAnnotation(Id.class) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -57,7 +57,7 @@ public class CrossStoreNodeDelegatingFieldAccessorFactory extends DelegatingFiel
|
||||
newConvertingNodePropertyFieldAccessorFactory()) {
|
||||
@Override
|
||||
public boolean accept(Neo4jPersistentProperty property) {
|
||||
return property.findAnnotation(GraphProperty.class) != null && super.accept(property);
|
||||
return property.getAnnotation(GraphProperty.class) != null && super.accept(property);
|
||||
}
|
||||
},
|
||||
new JpaIdFieldAccessListenerFactory(template));
|
||||
@@ -75,7 +75,7 @@ public class CrossStoreNodeDelegatingFieldAccessorFactory extends DelegatingFiel
|
||||
new RelatedToSingleFieldAccessorFactory(getTemplate()) {
|
||||
@Override
|
||||
public boolean accept(Neo4jPersistentProperty property) {
|
||||
return property.findAnnotation(RelatedTo.class) != null && super.accept(property);
|
||||
return property.getAnnotation(RelatedTo.class) != null && super.accept(property);
|
||||
}
|
||||
},
|
||||
new RelatedToCollectionFieldAccessorFactory(getTemplate()),
|
||||
@@ -89,7 +89,7 @@ public class CrossStoreNodeDelegatingFieldAccessorFactory extends DelegatingFiel
|
||||
return new ConvertingNodePropertyFieldAccessorFactory(getTemplate()) {
|
||||
@Override
|
||||
public boolean accept(Neo4jPersistentProperty property) {
|
||||
return property.findAnnotation(GraphProperty.class) != null && super.accept(property);
|
||||
return property.getAnnotation(GraphProperty.class) != null && super.accept(property);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class CrossStoreNodeDelegatingFieldAccessorFactory extends DelegatingFiel
|
||||
return new PropertyFieldAccessorFactory(getTemplate()) {
|
||||
@Override
|
||||
public boolean accept(Neo4jPersistentProperty property) {
|
||||
return property.findAnnotation(GraphProperty.class) != null && super.accept(property);
|
||||
return property.getAnnotation(GraphProperty.class) != null && super.accept(property);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class QueryFieldAccessorFactory implements FieldAccessorFactory {
|
||||
public QueryFieldAccessor(final Neo4jPersistentProperty property, Neo4jTemplate template) {
|
||||
this.property = property;
|
||||
this.template = template;
|
||||
final Query query = property.findAnnotation(Query.class);
|
||||
final Query query = property.getAnnotation(Query.class);
|
||||
this.annotationParams = query.params();
|
||||
if ((this.annotationParams.length % 2) != 0) {
|
||||
throw new IllegalArgumentException("Number of parameters has to be even to construct a parameter map");
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TraversalFieldAccessorFactory implements FieldAccessorFactory {
|
||||
|
||||
@Override
|
||||
public boolean accept(final Neo4jPersistentProperty f) {
|
||||
final GraphTraversal graphEntityTraversal = f.findAnnotation(GraphTraversal.class);
|
||||
final GraphTraversal graphEntityTraversal = f.getAnnotation(GraphTraversal.class);
|
||||
return graphEntityTraversal != null
|
||||
&& graphEntityTraversal.traversal() != FieldTraversalDescriptionBuilder.class
|
||||
&& f.getType().equals(Iterable.class);
|
||||
@@ -68,7 +68,7 @@ public class TraversalFieldAccessorFactory implements FieldAccessorFactory {
|
||||
public TraversalFieldAccessor(final Neo4jPersistentProperty property, Neo4jTemplate template) {
|
||||
this.property = property;
|
||||
this.template = template;
|
||||
final GraphTraversal graphEntityTraversal = property.findAnnotation(GraphTraversal.class);
|
||||
final GraphTraversal graphEntityTraversal = property.getAnnotation(GraphTraversal.class);
|
||||
this.target = resolveTarget(graphEntityTraversal,property);
|
||||
this.params = graphEntityTraversal.params();
|
||||
this.fieldTraversalDescriptionBuilder = createTraversalDescription(graphEntityTraversal);
|
||||
|
||||
@@ -45,7 +45,10 @@ class ValidatingNodePropertyFieldAccessorListenerFactory implements FieldAccesso
|
||||
}
|
||||
|
||||
private boolean hasValidationAnnotation(final Neo4jPersistentProperty property) {
|
||||
return property.findAnnotation(Constraint.class) != null;
|
||||
for (Annotation annotation : property.getAnnotations()) {
|
||||
if (annotation.annotationType().isAnnotationPresent(Constraint.class)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.data.neo4j.mapping;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
|
||||
@@ -60,6 +63,10 @@ public interface Neo4jPersistentProperty extends PersistentProperty<Neo4jPersist
|
||||
boolean isNeo4jPropertyValue(Object value);
|
||||
|
||||
boolean isSyntheticField();
|
||||
|
||||
Collection<? extends Annotation> getAnnotations();
|
||||
|
||||
<T extends Annotation> T getAnnotation(Class<? extends T> annotationType);
|
||||
|
||||
boolean isStartNode();
|
||||
|
||||
|
||||
@@ -67,13 +67,13 @@ public class RelationshipInfo {
|
||||
this.readonly = isCollection() && typeInformation.getType().equals(Iterable.class);
|
||||
}
|
||||
|
||||
public static RelationshipInfo fromField(String name, TypeInformation<?> typeInformation, Neo4jMappingContext ctx) {
|
||||
return new RelationshipInfo(name, Direction.OUTGOING, typeInformation,null, ctx);
|
||||
public static RelationshipInfo fromField(Field field, TypeInformation<?> typeInformation, Neo4jMappingContext ctx) {
|
||||
return new RelationshipInfo(field.getName(), Direction.OUTGOING, typeInformation,null, ctx);
|
||||
}
|
||||
|
||||
public static RelationshipInfo fromField(String name, RelatedTo annotation, TypeInformation<?> typeInformation, Neo4jMappingContext ctx) {
|
||||
public static RelationshipInfo fromField(Field field, RelatedTo annotation, TypeInformation<?> typeInformation, Neo4jMappingContext ctx) {
|
||||
RelationshipInfo relationshipInfo = new RelationshipInfo(
|
||||
annotation.type().isEmpty() ? name : annotation.type(),
|
||||
annotation.type().isEmpty() ? field.getName() : annotation.type(),
|
||||
annotation.direction(),
|
||||
typeInformation,
|
||||
annotation.elementClass() != Object.class ? ClassTypeInformation.from(annotation.elementClass()) : null,
|
||||
@@ -85,10 +85,10 @@ public class RelationshipInfo {
|
||||
return relationshipInfo;
|
||||
}
|
||||
|
||||
public static RelationshipInfo fromField(String name, RelatedToVia annotation, TypeInformation<?> typeInformation, Neo4jMappingContext ctx) {
|
||||
public static RelationshipInfo fromField(Field field, RelatedToVia annotation, TypeInformation<?> typeInformation, Neo4jMappingContext ctx) {
|
||||
final TypeInformation<?> elementClass = elementClass(annotation, typeInformation);
|
||||
RelationshipInfo relationshipInfo = new RelationshipInfo(
|
||||
relationshipType(annotation, typeInformation),
|
||||
relationshipType(field, annotation, typeInformation),
|
||||
annotation.direction(),
|
||||
typeInformation,
|
||||
elementClass,
|
||||
@@ -98,7 +98,7 @@ public class RelationshipInfo {
|
||||
return relationshipInfo;
|
||||
}
|
||||
|
||||
private static String relationshipType(RelatedToVia annotation, TypeInformation<?> typeInformation) {
|
||||
private static String relationshipType(Field field, RelatedToVia annotation, TypeInformation<?> typeInformation) {
|
||||
if (!annotation.type().isEmpty()) return annotation.type();
|
||||
final TypeInformation<?> relationshipEntityType = elementClass(annotation, typeInformation);
|
||||
final RelationshipEntity relationshipEntity = relationshipEntityType.getType().getAnnotation(RelationshipEntity.class);
|
||||
|
||||
@@ -93,7 +93,7 @@ public class IndexProviderImpl implements IndexProvider {
|
||||
|
||||
@Override
|
||||
public <S extends PropertyContainer> Index<S> getIndex(Neo4jPersistentProperty property, final Class<?> instanceType) {
|
||||
final Indexed indexedAnnotation = property.findAnnotation(Indexed.class);
|
||||
final Indexed indexedAnnotation = property.getAnnotation(Indexed.class);
|
||||
final Neo4jPersistentEntity<?> declaringType = property.getOwner();
|
||||
final String providedIndexName = providedIndexName(indexedAnnotation);
|
||||
final Indexed.Level level = indexingLevel(indexedAnnotation);
|
||||
|
||||
@@ -20,15 +20,19 @@ import java.beans.PropertyDescriptor;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
|
||||
import org.springframework.data.mapping.model.BeanWrapper;
|
||||
import org.springframework.data.mapping.model.MappingException;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.neo4j.annotation.EndNode;
|
||||
import org.springframework.data.neo4j.annotation.Fetch;
|
||||
@@ -64,21 +68,24 @@ class Neo4jPersistentPropertyImpl extends AnnotationBasedPersistentProperty<Neo4
|
||||
private final RelationshipInfo relationshipInfo;
|
||||
private final boolean isIdProperty;
|
||||
private IndexInfo indexInfo;
|
||||
private Map<Class<? extends Annotation>, ? extends Annotation> annotations;
|
||||
private Association<Neo4jPersistentProperty> myAssociation;
|
||||
private String defaultValue;
|
||||
private Class<?> propertyType;
|
||||
private String query;
|
||||
private final boolean isNeo4jEntityType;
|
||||
private Boolean isAssociation;
|
||||
private final Boolean isAssociation;
|
||||
private final String neo4jPropertyName;
|
||||
private final int hash;
|
||||
|
||||
public Neo4jPersistentPropertyImpl(Field field, PropertyDescriptor propertyDescriptor,
|
||||
PersistentEntity<?, Neo4jPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder, Neo4jMappingContext ctx) {
|
||||
super(field, propertyDescriptor, owner, simpleTypeHolder);
|
||||
this.hash = field == null ? propertyDescriptor.hashCode() : field.hashCode();
|
||||
this.hash = getField().hashCode();
|
||||
this.relationshipInfo = extractRelationshipInfo(field, ctx);
|
||||
this.annotations = extractAnnotations(field);
|
||||
this.propertyType = extractPropertyType();
|
||||
this.isAssociation = ctx.isReference(this);
|
||||
this.isNeo4jEntityType = isNeo4jPropertyType(getType());
|
||||
this.neo4jPropertyName = createNeo4jPropertyName();
|
||||
this.indexInfo = extractIndexInfo();
|
||||
@@ -114,6 +121,14 @@ class Neo4jPersistentPropertyImpl extends AnnotationBasedPersistentProperty<Neo4
|
||||
return myAssociation;
|
||||
}
|
||||
|
||||
private Map<Class<? extends Annotation>,? extends Annotation> extractAnnotations(Field field) {
|
||||
Map<Class<? extends Annotation>, Annotation> result=new IdentityHashMap<Class<? extends Annotation>, Annotation>();
|
||||
for (Annotation annotation : field.getAnnotations()) {
|
||||
result.put(annotation.annotationType(), annotation);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private IndexInfo extractIndexInfo() {
|
||||
final Indexed annotation = getAnnotation(Indexed.class);
|
||||
return annotation!=null ? new IndexInfo(annotation,this) : null;
|
||||
@@ -125,14 +140,14 @@ class Neo4jPersistentPropertyImpl extends AnnotationBasedPersistentProperty<Neo4
|
||||
|
||||
private RelationshipInfo extractRelationshipInfo(final Field field, Neo4jMappingContext ctx) {
|
||||
if (isAnnotationPresent(RelatedTo.class)) {
|
||||
return RelationshipInfo.fromField(getName(), getAnnotation(RelatedTo.class), getTypeInformation(), ctx);
|
||||
return RelationshipInfo.fromField(field, getAnnotation(RelatedTo.class), getTypeInformation(), ctx);
|
||||
}
|
||||
|
||||
if (isAnnotationPresent(RelatedToVia.class)) {
|
||||
return RelationshipInfo.fromField(getName(), getAnnotation(RelatedToVia.class), getTypeInformation(),ctx);
|
||||
return RelationshipInfo.fromField(field, getAnnotation(RelatedToVia.class), getTypeInformation(),ctx);
|
||||
}
|
||||
if (hasAnnotation(getTypeInformation(), NodeEntity.class)) {
|
||||
return RelationshipInfo.fromField(getName(), getTypeInformation(), ctx);
|
||||
return RelationshipInfo.fromField(field, getTypeInformation(), ctx);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -140,9 +155,12 @@ class Neo4jPersistentPropertyImpl extends AnnotationBasedPersistentProperty<Neo4
|
||||
|
||||
@Override
|
||||
public void setValue(Object entity, Object newValue) {
|
||||
|
||||
BeanWrapper<PersistentEntity<Object,?>,Object> wrapper = BeanWrapper.create(entity, null);
|
||||
wrapper.setProperty(this, newValue);
|
||||
try {
|
||||
if (!field.isAccessible()) field.setAccessible(true);
|
||||
field.set(entity, newValue);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new MappingException("Could not access field "+field+" for setting value "+newValue+" on "+this);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasAnnotation(TypeInformation<?> typeInformation, final Class<NodeEntity> annotationClass) {
|
||||
@@ -156,12 +174,7 @@ class Neo4jPersistentPropertyImpl extends AnnotationBasedPersistentProperty<Neo4
|
||||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
|
||||
if (this.isAssociation == null) {
|
||||
this.isAssociation = super.isAssociation();
|
||||
}
|
||||
|
||||
return this.isAssociation || isRelationship();
|
||||
return isAssociation==null ? super.isAssociation() : isAssociation|| isRelationship();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,7 +202,7 @@ class Neo4jPersistentPropertyImpl extends AnnotationBasedPersistentProperty<Neo4
|
||||
}
|
||||
|
||||
private String createNeo4jPropertyName() {
|
||||
final Neo4jPersistentEntity<?> entityClass = (Neo4jPersistentEntity<?>) getOwner();
|
||||
final Neo4jPersistentEntity entityClass = (Neo4jPersistentEntity) getOwner();
|
||||
if (entityClass.useShortNames()) return getName();
|
||||
return String.format("%s.%s", entityClass.getType().getSimpleName(), getName());
|
||||
}
|
||||
@@ -246,18 +259,32 @@ class Neo4jPersistentPropertyImpl extends AnnotationBasedPersistentProperty<Neo4
|
||||
return getName().contains("$");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Annotation> getAnnotations() {
|
||||
|
||||
if (annotations == null) {
|
||||
|
||||
}
|
||||
|
||||
return annotations.values();
|
||||
}
|
||||
|
||||
public Object getValue(final Object entity, final MappingPolicy mappingPolicy) {
|
||||
if (entity instanceof ManagedEntity && !mappingPolicy.accessField()) {
|
||||
return DoReturn.unwrap(((ManagedEntity<?,?>) entity).getEntityState().getValue(this, mappingPolicy));
|
||||
return DoReturn.unwrap(((ManagedEntity) entity).getEntityState().getValue(this, mappingPolicy));
|
||||
}
|
||||
return getValueFromEntity(entity, mappingPolicy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueFromEntity(Object entity, final MappingPolicy mappingPolicy) {
|
||||
|
||||
BeanWrapper<PersistentEntity<Object,?>, Object> wrapper = BeanWrapper.create(entity, null);
|
||||
return wrapper.getProperty(this);
|
||||
try {
|
||||
final Field field = getField();
|
||||
if (!field.isAccessible()) field.setAccessible(true);
|
||||
return field.get(entity);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new MappingException("Could not access field "+field);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -322,12 +349,14 @@ class Neo4jPersistentPropertyImpl extends AnnotationBasedPersistentProperty<Neo4
|
||||
}
|
||||
|
||||
public boolean isTransient() {
|
||||
|
||||
if (super.isTransient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return field == null ? false : Modifier.isTransient(field.getModifiers());
|
||||
return super.isTransient() || Modifier.isTransient(field.getModifiers()); // || isAnnotationPresent(Transient.class) || isAnnotationPresent("javax.persistence.Transient");
|
||||
}
|
||||
|
||||
private boolean isAnnotationPresent(String className) {
|
||||
for (Class<? extends Annotation> annotationType : annotations.keySet()) {
|
||||
if (annotationType.getName().equals(className)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -335,7 +364,7 @@ class Neo4jPersistentPropertyImpl extends AnnotationBasedPersistentProperty<Neo4
|
||||
final Iterable<? extends TypeInformation<?>> result = super.getPersistentEntityType();
|
||||
for (Iterator<? extends TypeInformation<?>> it = result.iterator(); it.hasNext(); ) {
|
||||
final TypeInformation<?> typeInformation = it.next();
|
||||
final Class<?> type = typeInformation.getType();
|
||||
final Class type = typeInformation.getType();
|
||||
if (isNodeEntity(type) || isRelationshipEntity(type)) continue;
|
||||
if (log.isInfoEnabled()) log.info("ignoring "+getName()+" "+type+" "+typeInformation.getActualType().getType());
|
||||
it.remove();
|
||||
|
||||
@@ -222,6 +222,18 @@ public class Neo4jMappingContext extends AbstractMappingContext<Neo4jPersistentE
|
||||
public void setEntityAlias(EntityAlias entityAlias) {
|
||||
this.entityAlias = entityAlias;
|
||||
}
|
||||
|
||||
public boolean isReference(Neo4jPersistentProperty property) {
|
||||
for (Annotation annotation : property.getAnnotations()) {
|
||||
Boolean isReference = referenceAnnotations.get(annotation);
|
||||
if (isReference == null) {
|
||||
isReference = Reference.class.isInstance(annotation) || annotation.annotationType().isAnnotationPresent(Reference.class);
|
||||
referenceAnnotations.put(annotation, isReference);
|
||||
}
|
||||
if (isReference) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setEntityIndexCreator(EntityIndexCreator entityIndexCreator) {
|
||||
this.entityIndexCreator = entityIndexCreator;
|
||||
|
||||
Reference in New Issue
Block a user