replaced part of the aspect with field-accessors
This commit is contained in:
@@ -7,6 +7,8 @@ import org.springframework.datastore.graph.api.NodeBacked;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.springframework.datastore.graph.neo4j.fieldaccess.DoReturn.doReturn;
|
||||
|
||||
/**
|
||||
* @author Michael Hunger
|
||||
* @since 12.09.2010
|
||||
@@ -28,8 +30,8 @@ public class ConvertingNodePropertyFieldAccessor extends NodePropertyFieldAccess
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(final NodeBacked nodeBacked) {
|
||||
return deserializePropertyValue(super.getValue(nodeBacked));
|
||||
public Object doGetValue(final NodeBacked nodeBacked) {
|
||||
return deserializePropertyValue(super.doGetValue(nodeBacked));
|
||||
}
|
||||
|
||||
private Object serializePropertyValue(final Object newVal) {
|
||||
|
||||
@@ -42,12 +42,13 @@ public class DelegatingFieldAccessorFactory<T> implements FieldAccessorFactory<T
|
||||
if (isAspectjField(field)) return null;
|
||||
for (FieldAccessorFactory<?> fieldAccessorFactory : fieldAccessorFactories) {
|
||||
if (fieldAccessorFactory.accept(field)) {
|
||||
System.out.println("Factory " + fieldAccessorFactory + " used for field: " + field);
|
||||
if (log.isInfoEnabled()) log.info("Factory " + fieldAccessorFactory + " used for field: " + field);
|
||||
return fieldAccessorFactory.forField(field);
|
||||
}
|
||||
}
|
||||
log.warn("No FieldAccessor configured for field: " + field);
|
||||
return null;
|
||||
throw new RuntimeException("No FieldAccessor configured for field: " + field);
|
||||
//log.warn("No FieldAccessor configured for field: " + field);
|
||||
//return null;
|
||||
}
|
||||
|
||||
private boolean isAspectjField(Field field) {
|
||||
|
||||
@@ -38,12 +38,17 @@ public class EntityStateAccessors<ENTITY, STATE> {
|
||||
|
||||
public Object getValue(final Field field) {
|
||||
final FieldAccessor<ENTITY, ?> accessor = accessorFor(field);
|
||||
return accessor == null ? null : accessor.getValue(entity);
|
||||
if (accessor == null) {
|
||||
System.err.println("No accessor for "+field);
|
||||
return null;
|
||||
}
|
||||
else return accessor.getValue(entity);
|
||||
}
|
||||
public Object setValue(final Field field, final Object newVal) {
|
||||
final FieldAccessor<ENTITY, ?> accessor = accessorFor(field);
|
||||
Object result=newVal;
|
||||
if (accessor!=null) result = accessor.setValue(entity, newVal);
|
||||
else System.err.println("No accessor for "+field);
|
||||
notifyListeners(field, result); // async ?
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import org.springframework.datastore.graph.api.NodeBacked;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.springframework.datastore.graph.neo4j.fieldaccess.DoReturn.doReturn;
|
||||
|
||||
/**
|
||||
* @author Michael Hunger
|
||||
* @since 12.09.2010
|
||||
@@ -17,12 +19,12 @@ public class IdFieldAccessor implements FieldAccessor<NodeBacked, Object> {
|
||||
|
||||
@Override
|
||||
public Object setValue(final NodeBacked nodeBacked, final Object newVal) {
|
||||
return null;
|
||||
return doReturn(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(final NodeBacked nodeBacked) {
|
||||
return nodeBacked.getUnderlyingNode().getId();
|
||||
return doReturn(nodeBacked.getUnderlyingNode().getId());
|
||||
}
|
||||
|
||||
public static FieldAccessorFactory<NodeBacked> factory() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.springframework.datastore.graph.neo4j.fieldaccess;
|
||||
|
||||
import org.neo4j.index.IndexService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.datastore.graph.api.NodeBacked;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -31,19 +32,22 @@ public class IndexingNodePropertyFieldAccessorListener implements FieldAccessLis
|
||||
}
|
||||
|
||||
public static FieldAccessorListenerFactory<NodeBacked> factory() {
|
||||
return new FieldAccessorListenerFactory<NodeBacked>() {
|
||||
@Autowired
|
||||
IndexService indexService;
|
||||
return new NodeBackedFieldAccessorListenerFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(final Field f) {
|
||||
return NodePropertyFieldAccessor.factory().accept(f) || ConvertingNodePropertyFieldAccessor.factory().accept(f);
|
||||
}
|
||||
@Configurable
|
||||
private static class NodeBackedFieldAccessorListenerFactory implements FieldAccessorListenerFactory<NodeBacked> {
|
||||
@Autowired
|
||||
IndexService indexService;
|
||||
|
||||
@Override
|
||||
public FieldAccessListener<NodeBacked,?> forField(final Field field) {
|
||||
return new IndexingNodePropertyFieldAccessorListener(field,indexService);
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public boolean accept(final Field f) {
|
||||
return NodePropertyFieldAccessor.factory().accept(f) || ConvertingNodePropertyFieldAccessor.factory().accept(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldAccessListener<NodeBacked,?> forField(final Field field) {
|
||||
return new IndexingNodePropertyFieldAccessorListener(field,indexService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import org.springframework.datastore.graph.api.NodeBacked;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.springframework.datastore.graph.neo4j.fieldaccess.DoReturn.doReturn;
|
||||
|
||||
/**
|
||||
* @author Michael Hunger
|
||||
* @since 12.09.2010
|
||||
@@ -22,7 +24,11 @@ public class NodePropertyFieldAccessor implements FieldAccessor<NodeBacked, Obje
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(final NodeBacked nodeBacked) {
|
||||
public final Object getValue(final NodeBacked nodeBacked) {
|
||||
return doReturn(doGetValue(nodeBacked));
|
||||
}
|
||||
|
||||
protected Object doGetValue(NodeBacked nodeBacked) {
|
||||
return nodeBacked.getUnderlyingNode().getProperty(getPropertyName());
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.lang.reflect.Field;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.springframework.datastore.graph.neo4j.fieldaccess.DoReturn.doReturn;
|
||||
|
||||
public class OneToNRelationshipEntityFieldAccessor extends AbstractRelationshipFieldAccessor<NodeBacked, Node, RelationshipBacked, Relationship> {
|
||||
|
||||
public OneToNRelationshipEntityFieldAccessor(final RelationshipType type, final Direction direction, final Class<? extends RelationshipBacked> elementClass, final GraphDatabaseContext graphDatabaseContext) {
|
||||
@@ -28,7 +30,7 @@ public class OneToNRelationshipEntityFieldAccessor extends AbstractRelationshipF
|
||||
public Object getValue(final NodeBacked entity) {
|
||||
checkUnderlyingNode(entity);
|
||||
final Set<RelationshipBacked> result = createEntitySetFromRelationships(entity);
|
||||
return new ManagedFieldAccessorSet<NodeBacked, RelationshipBacked>(entity, result, this);
|
||||
return doReturn(new ManagedFieldAccessorSet<NodeBacked, RelationshipBacked>(entity, result, this));
|
||||
}
|
||||
|
||||
private Set<RelationshipBacked> createEntitySetFromRelationships(final NodeBacked entity) {
|
||||
|
||||
@@ -12,6 +12,8 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.springframework.datastore.graph.neo4j.fieldaccess.DoReturn.doReturn;
|
||||
|
||||
public class OneToNRelationshipFieldAccessor extends NodeToNodesRelationshipFieldAccessor<NodeBacked> {
|
||||
|
||||
public OneToNRelationshipFieldAccessor(final RelationshipType type, final Direction direction, final Class<? extends NodeBacked> elementClass, final GraphDatabaseContext graphDatabaseContext) {
|
||||
@@ -35,7 +37,7 @@ public class OneToNRelationshipFieldAccessor extends NodeToNodesRelationshipFiel
|
||||
public Object getValue(final NodeBacked entity) {
|
||||
checkUnderlyingNode(entity);
|
||||
final Set<NodeBacked> result = createEntitySetFromRelationshipEndNodes(entity);
|
||||
return createManagedSet(entity, result);
|
||||
return doReturn(createManagedSet(entity, result));
|
||||
}
|
||||
|
||||
public static FieldAccessorFactory<NodeBacked> factory() {
|
||||
|
||||
@@ -344,12 +344,19 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
|
||||
log.trace("Inside of transaction, FLUSH-SET value "+newVal+" to field "+f+" has node "+entity.hasUnderlyingNode()+" dirty "+entity.isDirty()+" "+entity.dump());
|
||||
flushDirty(entity);
|
||||
|
||||
|
||||
Object result=entity.underlyingState.setValue(f,newVal);
|
||||
if (result instanceof DoReturn) return ((DoReturn)result).value;
|
||||
return proceed(entity,result);
|
||||
|
||||
/*
|
||||
ShouldProceedOrReturn shouldProceedOrReturn=setNodePropertyOrRelationship(f,entity,newVal);
|
||||
if (shouldProceedOrReturn.proceed) {
|
||||
return proceed(entity,shouldProceedOrReturn.value);
|
||||
} else {
|
||||
return shouldProceedOrReturn.value;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private boolean isNeo4jPropertyType(Class<?> fieldType) {
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ShouldProceedOrReturn {
|
||||
}
|
||||
|
||||
public ShouldProceedOrReturn(final boolean proceed, final Object value) {
|
||||
this.proceed = true;
|
||||
this.proceed = proceed;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user