@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.data.neo4j.config;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import org.neo4j.graphdb.GraphDatabaseService;
|
||||
import org.neo4j.graphdb.Node;
|
||||
import org.neo4j.graphdb.Relationship;
|
||||
@@ -33,6 +36,7 @@ import org.springframework.data.neo4j.core.RelationshipBacked;
|
||||
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean;
|
||||
import org.springframework.data.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.repository.DirectGraphRepositoryFactory;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
import org.springframework.data.neo4j.support.node.Neo4jNodeBacking;
|
||||
@@ -51,9 +55,6 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.jta.JtaTransactionManager;
|
||||
import org.springframework.transaction.jta.UserTransactionAdapter;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.validation.Validator;
|
||||
|
||||
/**
|
||||
* Abstract base class for code based configuration of Spring managed Neo4j infrastructure.
|
||||
* <p>Subclasses are required to provide an implementation of graphDbService ....
|
||||
@@ -149,6 +150,7 @@ public class Neo4jConfiguration {
|
||||
public RelationshipEntityStateFactory relationshipEntityStateFactory() throws Exception {
|
||||
RelationshipEntityStateFactory entityStateFactory = new RelationshipEntityStateFactory();
|
||||
entityStateFactory.setGraphDatabaseContext(graphDatabaseContext());
|
||||
entityStateFactory.setRelationshipDelegatingFieldAccessorFactory(relationshipDelegatingFieldAccessorFactory());
|
||||
return entityStateFactory;
|
||||
}
|
||||
|
||||
@@ -175,6 +177,11 @@ public class Neo4jConfiguration {
|
||||
public DelegatingFieldAccessorFactory<NodeBacked> nodeDelegatingFieldAccessorFactory() throws Exception {
|
||||
return new NodeDelegatingFieldAccessorFactory(graphDatabaseContext());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DelegatingFieldAccessorFactory<RelationshipBacked> relationshipDelegatingFieldAccessorFactory() throws Exception {
|
||||
return new RelationshipDelegatingFieldAccessorFactory(graphDatabaseContext());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager transactionManager() {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright 2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.neo4j.fieldaccess;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.neo4j.core.NodeBacked;
|
||||
import org.springframework.data.neo4j.core.RelationshipBacked;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
public class RelationshipDelegatingFieldAccessorFactory extends DelegatingFieldAccessorFactory<RelationshipBacked> {
|
||||
public RelationshipDelegatingFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
|
||||
super(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<FieldAccessorListenerFactory<?>> createListenerFactories() {
|
||||
return Arrays.<FieldAccessorListenerFactory<?>>asList(
|
||||
new IndexingPropertyFieldAccessorListenerFactory(
|
||||
graphDatabaseContext,
|
||||
new PropertyFieldAccessorFactory(graphDatabaseContext.getConversionService()),
|
||||
new ConvertingNodePropertyFieldAccessorFactory(graphDatabaseContext.getConversionService())
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<? extends FieldAccessorFactory<?>> createAccessorFactories() {
|
||||
return Arrays.<FieldAccessorFactory<?>>asList(
|
||||
new TransientFieldAccessorFactory(),
|
||||
new RelationshipNodeFieldAccessorFactory(graphDatabaseContext),
|
||||
new PropertyFieldAccessorFactory(graphDatabaseContext.getConversionService()),
|
||||
new ConvertingNodePropertyFieldAccessorFactory(graphDatabaseContext.getConversionService())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.data.neo4j.support.node;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.PersistenceUnitUtil;
|
||||
|
||||
import org.neo4j.graphdb.Node;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.core.EntityState;
|
||||
@@ -24,10 +28,6 @@ import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory
|
||||
import org.springframework.data.neo4j.fieldaccess.DetachedEntityState;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.PersistenceUnitUtil;
|
||||
|
||||
public class NodeEntityStateFactory {
|
||||
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
@@ -61,7 +61,7 @@ public class NodeEntityStateFactory {
|
||||
}
|
||||
|
||||
public void setNodeDelegatingFieldAccessorFactory(
|
||||
DelegatingFieldAccessorFactory<NodeBacked> nodeDelegatingFieldAccessorFactory) {
|
||||
DelegatingFieldAccessorFactory<NodeBacked> nodeDelegatingFieldAccessorFactory) {
|
||||
this.nodeDelegatingFieldAccessorFactory = nodeDelegatingFieldAccessorFactory;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ import org.springframework.data.neo4j.core.RelationshipBacked;
|
||||
import org.springframework.data.neo4j.fieldaccess.*;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Michael Hunger
|
||||
@@ -34,7 +32,7 @@ public class RelationshipEntityState<ENTITY extends RelationshipBacked> extends
|
||||
|
||||
private final GraphDatabaseContext graphDatabaseContext;
|
||||
|
||||
public RelationshipEntityState(final Relationship underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final RelationshipStateDelegatingFieldAccessorFactory delegatingFieldAccessorFactory) {
|
||||
public RelationshipEntityState(final Relationship underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final DelegatingFieldAccessorFactory<RelationshipBacked> delegatingFieldAccessorFactory) {
|
||||
super(underlyingState, entity, type, delegatingFieldAccessorFactory);
|
||||
this.graphDatabaseContext = graphDatabaseContext;
|
||||
}
|
||||
@@ -65,30 +63,4 @@ public class RelationshipEntityState<ENTITY extends RelationshipBacked> extends
|
||||
createAndAssignState();
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static class RelationshipStateDelegatingFieldAccessorFactory extends DelegatingFieldAccessorFactory {
|
||||
public RelationshipStateDelegatingFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
|
||||
super(graphDatabaseContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<FieldAccessorListenerFactory<?>> createListenerFactories() {
|
||||
return Arrays.<FieldAccessorListenerFactory<?>>asList(
|
||||
new IndexingPropertyFieldAccessorListenerFactory(
|
||||
graphDatabaseContext,
|
||||
new PropertyFieldAccessorFactory(graphDatabaseContext.getConversionService()),
|
||||
new ConvertingNodePropertyFieldAccessorFactory(graphDatabaseContext.getConversionService())
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<? extends FieldAccessorFactory<?>> createAccessorFactories() {
|
||||
return Arrays.<FieldAccessorFactory<?>>asList(
|
||||
new TransientFieldAccessorFactory(),
|
||||
new RelationshipNodeFieldAccessorFactory(graphDatabaseContext),
|
||||
new PropertyFieldAccessorFactory(graphDatabaseContext.getConversionService()),
|
||||
new ConvertingNodePropertyFieldAccessorFactory(graphDatabaseContext.getConversionService())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,27 +19,25 @@ package org.springframework.data.neo4j.support.relationship;
|
||||
import org.neo4j.graphdb.Relationship;
|
||||
import org.springframework.data.neo4j.core.EntityState;
|
||||
import org.springframework.data.neo4j.core.RelationshipBacked;
|
||||
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseContext;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
public class RelationshipEntityStateFactory {
|
||||
|
||||
private GraphDatabaseContext graphDatabaseContext;
|
||||
|
||||
private RelationshipEntityState.RelationshipStateDelegatingFieldAccessorFactory delegatingFieldAccessorFactory;
|
||||
private DelegatingFieldAccessorFactory<RelationshipBacked> relationshipDelegatingFieldAccessorFactory;
|
||||
|
||||
public EntityState<RelationshipBacked, Relationship> getEntityState(final RelationshipBacked entity) {
|
||||
return new RelationshipEntityState<RelationshipBacked>(null,entity,entity.getClass(), graphDatabaseContext, delegatingFieldAccessorFactory);
|
||||
return new RelationshipEntityState<RelationshipBacked>(null,entity,entity.getClass(), graphDatabaseContext, relationshipDelegatingFieldAccessorFactory);
|
||||
}
|
||||
|
||||
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {
|
||||
this.graphDatabaseContext = graphDatabaseContext;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void setUp() {
|
||||
this.delegatingFieldAccessorFactory = new RelationshipEntityState.RelationshipStateDelegatingFieldAccessorFactory(graphDatabaseContext);
|
||||
}
|
||||
|
||||
public void setRelationshipDelegatingFieldAccessorFactory(
|
||||
DelegatingFieldAccessorFactory<RelationshipBacked> delegatingFieldAccessorFactory) {
|
||||
this.relationshipDelegatingFieldAccessorFactory = delegatingFieldAccessorFactory;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user