, STATE> imple
// todo always create an transaction for persist, atomic operation when no outside tx exists
@Override
- public ENTITY persist() {
+ public Object persist() {
if (!isDetached()) return getEntity();
Transaction tx = graphDatabaseContext.beginTx();
try {
- ENTITY result = delegate.persist();
+ Object result = delegate.persist();
flushDirty();
tx.success();
diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DynamicProperties.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DynamicProperties.java
index 53bb9332b..531660a47 100644
--- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DynamicProperties.java
+++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DynamicProperties.java
@@ -38,12 +38,12 @@ import org.springframework.data.neo4j.fieldaccess.DynamicPropertiesFieldAccessor
* Person p = new Person();
* p.persist();
* p.personalProperties.setProperty("ZIP", 8000);
- * p.personalProperties.setProperty("City", "Zürich");
+ * p.personalProperties.setProperty("City", "Zürich");
*
* results in a node with the properties:
*
* "personalProperties-ZIP" => 8000
- * "personalProperties-City" => "Zürich"
+ * "personalProperties-City" => "Zürich"
*
*/
public interface DynamicProperties {
diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DynamicPropertiesFieldAccessorFactory.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DynamicPropertiesFieldAccessorFactory.java
index 91f66589e..eb74c634d 100644
--- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DynamicPropertiesFieldAccessorFactory.java
+++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/DynamicPropertiesFieldAccessorFactory.java
@@ -15,68 +15,70 @@
*/
package org.springframework.data.neo4j.fieldaccess;
-import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.helpers.collection.IteratorUtil;
import org.springframework.core.convert.ConversionService;
-import org.springframework.data.neo4j.core.GraphBacked;
-import org.springframework.data.neo4j.mapping.Neo4JPersistentProperty;
+
+import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.DoReturn;
+import org.springframework.data.neo4j.support.GraphDatabaseContext;
/**
* This accessor factory creates {@link DynamicPropertiesFieldAccessor}s for @NodeEntity properties of type
* {@link DynamicProperties}.
*/
-public class DynamicPropertiesFieldAccessorFactory implements FieldAccessorFactory> {
+public class DynamicPropertiesFieldAccessorFactory implements FieldAccessorFactory {
- private final ConversionService conversionService;
+ private final GraphDatabaseContext graphDatabaseContext;
- public DynamicPropertiesFieldAccessorFactory(final ConversionService conversionService) {
- this.conversionService = conversionService;
+ public DynamicPropertiesFieldAccessorFactory(final GraphDatabaseContext graphDatabaseContext) {
+ this.graphDatabaseContext = graphDatabaseContext;
}
@Override
- public boolean accept(Neo4JPersistentProperty f) {
+ public boolean accept(Neo4jPersistentProperty f) {
return DynamicProperties.class.isAssignableFrom(f.getType());
}
@Override
- public FieldAccessor> forField(Neo4JPersistentProperty field) {
- return new DynamicPropertiesFieldAccessor(conversionService,
+ public FieldAccessor forField(Neo4jPersistentProperty field) {
+ return new DynamicPropertiesFieldAccessor(graphDatabaseContext,
field.getNeo4jPropertyName(), field);
}
- public static class DynamicPropertiesFieldAccessor implements FieldAccessor> {
- private final ConversionService conversionService;
+ public static class DynamicPropertiesFieldAccessor implements FieldAccessor {
private final String propertyNamePrefix;
- private final Neo4JPersistentProperty field;
+ private final Neo4jPersistentProperty field;
+ private final GraphDatabaseContext graphDatabaseContext;
- public DynamicPropertiesFieldAccessor(ConversionService conversionService, String propertyName, Neo4JPersistentProperty field) {
- this.conversionService = conversionService;
+ public DynamicPropertiesFieldAccessor(GraphDatabaseContext graphDatabaseContext, String propertyName, Neo4jPersistentProperty field) {
+ this.graphDatabaseContext = graphDatabaseContext;
this.propertyNamePrefix = propertyName;
this.field = field;
}
@Override
- public Object setValue(final GraphBacked entity, final Object newVal) {
- final PropertyContainer propertyContainer = entity.getPersistentState();
+ public Object setValue(final Object entity, final Object newVal) {
+ final PropertyContainer propertyContainer = graphDatabaseContext.getPersistentState(entity);
PrefixedDynamicProperties dynamicProperties;
if (newVal instanceof ManagedPrefixedDynamicProperties) {
// newVal is already a managed container
- dynamicProperties = (ManagedPrefixedDynamicProperties>) newVal;
+ dynamicProperties = (ManagedPrefixedDynamicProperties) newVal;
}
else {
// newVal is not a managed prefixed container and therefore contains
// pure key/values that must be converted to a prefixed form
dynamicProperties = new PrefixedDynamicProperties(propertyNamePrefix);
- DynamicProperties newPropertiesVal = (DynamicProperties)newVal;
- for(String key : newPropertiesVal.getPropertyKeys()) {
- dynamicProperties.setProperty(key, newPropertiesVal.getProperty(key));
- }
- }
+ if (newVal != null) {
+ DynamicProperties newPropertiesVal = (DynamicProperties) newVal;
+ for (String key : newPropertiesVal.getPropertyKeys()) {
+ dynamicProperties.setProperty(key, newPropertiesVal.getProperty(key));
+ }
+ }
+ }
Set dynamicProps = dynamicProperties.getPrefixedPropertyKeys();
@@ -105,10 +107,9 @@ public class DynamicPropertiesFieldAccessorFactory implements FieldAccessorFacto
}
@Override
- public Object getValue(final GraphBacked entity) {
- PropertyContainer element = entity.getPersistentState();
- ManagedPrefixedDynamicProperties> props = ManagedPrefixedDynamicProperties.create(propertyNamePrefix,
- field, entity);
+ public Object getValue(final Object entity) {
+ PropertyContainer element = graphDatabaseContext.getPersistentState(entity);
+ ManagedPrefixedDynamicProperties props = ManagedPrefixedDynamicProperties.create(propertyNamePrefix, field, entity,graphDatabaseContext,this);
for (String key : element.getPropertyKeys()) {
props.setPropertyIfPrefixed(key, element.getProperty(key));
}
@@ -116,7 +117,7 @@ public class DynamicPropertiesFieldAccessorFactory implements FieldAccessorFacto
}
@Override
- public boolean isWriteable(final GraphBacked entity) {
+ public boolean isWriteable(final Object entity) {
return true;
}
diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessListener.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessListener.java
index d58dcede7..8bcd7f1ee 100644
--- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessListener.java
+++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessListener.java
@@ -18,10 +18,8 @@ package org.springframework.data.neo4j.fieldaccess;
/**
* interface for listeners for field modifications, used for instance for indexing or tracing
- * @param
- * @param
*/
-public interface FieldAccessListener {
+public interface FieldAccessListener {
/**
* callback method after modifying field write operation
@@ -29,6 +27,6 @@ public interface FieldAccessListener {
* @param oldVal
* @param newVal
*/
- void valueChanged(ENTITY entity, Object oldVal, Object newVal);
+ void valueChanged(Object entity, Object oldVal, Object newVal);
}
diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessor.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessor.java
index 22b7f85a0..69f25338d 100644
--- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessor.java
+++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessor.java
@@ -18,12 +18,9 @@ package org.springframework.data.neo4j.fieldaccess;
/**
* interface for field accessors, encapsulates reading and writing from fields and write support information about the field.
- * It is used by the {@link org.springframework.data.neo4j.core.EntityState} which is delegated to by the
- * {@link org.springframework.data.neo4j.support.node.Neo4jNodeBacking} {@link org.springframework.data.neo4j.support.relationship.Neo4jRelationshipBacking}
- * aspects.
- * @param
+ * It is used by the {@link org.springframework.data.neo4j.core.EntityState}.
*/
-public interface FieldAccessor {
+public interface FieldAccessor {
/**
* Returns a default implementation for a field or {@code null} if none is provided.
@@ -41,18 +38,18 @@ public interface FieldAccessor {
* @return the written value or a DoReturn wrapper with the written value or null.
* DoReturn indicates that the aspect should not proceed to the original field access but instead return immediately.
*/
- Object setValue(ENTITY entity, Object newVal);
+ Object setValue(Object entity, Object newVal);
/**
* @param entity
* @return the value or a DoReturn wrapper with the value for the field.
* DoReturn indicates that the aspect should not proceed to the original field access but instead return immediately.
*/
- Object getValue(ENTITY entity);
+ Object getValue(Object entity);
/**
* @param entity
* @return false for read only or computed fields, true otherwise
*/
- boolean isWriteable(ENTITY entity);
+ boolean isWriteable(Object entity);
}
diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessorFactory.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessorFactory.java
index d0f2060d0..aaf71259a 100644
--- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessorFactory.java
+++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessorFactory.java
@@ -16,9 +16,7 @@
package org.springframework.data.neo4j.fieldaccess;
-import org.springframework.data.neo4j.mapping.Neo4JPersistentProperty;
-
-import java.lang.reflect.Field;
+import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
/**
* Factory interface for a single field / field accessor. Provides means to check if a certain field is eligible for this
@@ -27,18 +25,18 @@ import java.lang.reflect.Field;
* @author Michael Hunger
* @since 12.09.2010
*/
-public interface FieldAccessorFactory {
+public interface FieldAccessorFactory {
/**
*
* @param f field to check
* @return true if this factory is responsible for creating a accessor for this field
*/
- boolean accept(Neo4JPersistentProperty f);
+ boolean accept(Neo4jPersistentProperty f);
/**
*
* @param f the field to create an accessor for
* @return a field accessor for the field or null if none can be created
*/
- FieldAccessor forField(Neo4JPersistentProperty f);
+ FieldAccessor forField(Neo4jPersistentProperty f);
}
diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessorFactoryProviders.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessorFactoryProviders.java
index 04d61174e..f45da0230 100644
--- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessorFactoryProviders.java
+++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/FieldAccessorFactoryProviders.java
@@ -16,10 +16,11 @@
package org.springframework.data.neo4j.fieldaccess;
-import org.springframework.data.neo4j.mapping.Neo4JPersistentProperty;
+import org.springframework.data.mapping.PersistentProperty;
+import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
+import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.util.TypeInformation;
-import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -32,31 +33,31 @@ import java.util.Map;
public class FieldAccessorFactoryProviders {
static class FieldAccessorFactoryProvider {
- private final Neo4JPersistentProperty property;
- private final FieldAccessorFactory fieldAccessorFactory;
- private final List> fieldAccessorListenerFactories;
+ private final Neo4jPersistentProperty property;
+ private final FieldAccessorFactory fieldAccessorFactory;
+ private final List fieldAccessorListenerFactories;
- FieldAccessorFactoryProvider(final Neo4JPersistentProperty property, final FieldAccessorFactory fieldAccessorFactory, final List fieldAccessorListenerFactories) {
+ FieldAccessorFactoryProvider(final Neo4jPersistentProperty property, final FieldAccessorFactory fieldAccessorFactory, final List fieldAccessorListenerFactories) {
this.property = property;
this.fieldAccessorFactory = fieldAccessorFactory;
this.fieldAccessorListenerFactories = fieldAccessorListenerFactories;
}
- public FieldAccessor accessor() {
+ public FieldAccessor accessor() {
if (fieldAccessorFactory == null) return null;
return fieldAccessorFactory.forField(property);
}
- public List> listeners() {
+ public List listeners() {
if (fieldAccessorListenerFactories == null) return null;
- final List> listeners = new ArrayList>(fieldAccessorListenerFactories.size());
- for (final FieldAccessorListenerFactory fieldAccessorListenerFactory : fieldAccessorListenerFactories) {
+ final List listeners = new ArrayList(fieldAccessorListenerFactories.size());
+ for (final FieldAccessorListenerFactory fieldAccessorListenerFactory : fieldAccessorListenerFactories) {
listeners.add(fieldAccessorListenerFactory.forField(property));
}
return listeners;
}
- public Neo4JPersistentProperty getProperty() {
+ public Neo4jPersistentProperty getProperty() {
return property;
}
}
@@ -64,37 +65,37 @@ public class FieldAccessorFactoryProviders {
private final TypeInformation> type;
private final List> fieldAccessorFactoryProviders = new ArrayList>();
private final IdFieldAccessorFactory idFieldAccessorFactory;
- private Neo4JPersistentProperty idProperty;
+ private Neo4jPersistentProperty idProperty;
- FieldAccessorFactoryProviders(TypeInformation> type) {
+ FieldAccessorFactoryProviders(TypeInformation> type, GraphDatabaseContext graphDatabaseContext) {
this.type = type;
- idFieldAccessorFactory = new IdFieldAccessorFactory();
+ idFieldAccessorFactory= new IdFieldAccessorFactory(graphDatabaseContext);
}
- public Map> getFieldAccessors() {
- final Map> result = new HashMap>(fieldAccessorFactoryProviders.size(),1);
+ public Map getFieldAccessors() {
+ final Map result = new HashMap(fieldAccessorFactoryProviders.size(),1);
for (final FieldAccessorFactoryProvider fieldAccessorFactoryProvider : fieldAccessorFactoryProviders) {
- final FieldAccessor accessor = fieldAccessorFactoryProvider.accessor();
+ final FieldAccessor accessor = fieldAccessorFactoryProvider.accessor();
result.put(fieldAccessorFactoryProvider.getProperty(), accessor);
}
return result;
}
- public Map