merged GraphDatabaseContext and Neo4jTemplate, fixed remaining configuration and tests

This commit is contained in:
Michael Hunger
2011-10-16 21:33:46 +02:00
parent 2ae9abee7d
commit b779521382
119 changed files with 1018 additions and 1050 deletions

View File

@@ -46,7 +46,7 @@ import org.springframework.data.neo4j.support.node.NodeEntityStateFactory;
import org.springframework.data.neo4j.support.DoReturn;
import org.springframework.data.neo4j.core.EntityPath;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.path.EntityPathPathIterableWrapper;
import org.springframework.data.neo4j.support.query.CypherQueryExecutor;
@@ -74,11 +74,11 @@ public privileged aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMix
//declare @type: NodeBacked+: @Configurable;
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
private NodeEntityStateFactory entityStateFactory;
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public void setTemplate(Neo4jTemplate template) {
this.template = template;
}
public void setNodeEntityStateFactory(NodeEntityStateFactory entityStateFactory) {
this.entityStateFactory = entityStateFactory;
@@ -226,8 +226,8 @@ public privileged aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMix
return (R)graphDatabaseContext().getRelationshipTo(this,target,relationshipClass,type);
}
public static GraphDatabaseContext graphDatabaseContext() {
return Neo4jNodeBacking.aspectOf().graphDatabaseContext;
public static Neo4jTemplate graphDatabaseContext() {
return Neo4jNodeBacking.aspectOf().template;
}
/**

View File

@@ -26,7 +26,7 @@ import org.springframework.data.neo4j.aspects.core.NodeBacked;
import org.springframework.data.neo4j.aspects.core.RelationshipBacked;
import org.springframework.data.neo4j.support.DoReturn;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory;
import java.lang.reflect.Field;
@@ -56,12 +56,12 @@ public aspect Neo4jRelationshipBacking {
args(newVal) &&
!set(* RelationshipBacked.*);
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
private RelationshipEntityStateFactory entityStateFactory;
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public void setTemplate(Neo4jTemplate template) {
this.template = template;
}
public void setRelationshipEntityStateFactory(RelationshipEntityStateFactory entityStateFactory) {
@@ -125,11 +125,11 @@ public aspect Neo4jRelationshipBacking {
}
public void RelationshipBacked.remove() {
Neo4jRelationshipBacking.aspectOf().graphDatabaseContext.removeRelationshipEntity(this);
Neo4jRelationshipBacking.aspectOf().template.removeRelationshipEntity(this);
}
public <R extends RelationshipBacked> R RelationshipBacked.projectTo(Class<R> targetType) {
return (R)Neo4jRelationshipBacking.aspectOf().graphDatabaseContext.projectTo(this, targetType);
return (R)Neo4jRelationshipBacking.aspectOf().template.projectTo(this, targetType);
}
Object around(RelationshipBacked entity): entityFieldGet(entity) {

View File

@@ -34,7 +34,7 @@ public class Neo4jAspectConfiguration extends Neo4jConfiguration
@Bean
public Neo4jRelationshipBacking neo4jRelationshipBacking() throws Exception {
Neo4jRelationshipBacking aspect = Neo4jRelationshipBacking.aspectOf();
aspect.setGraphDatabaseContext(graphDatabaseContext());
aspect.setTemplate(neo4jTemplate());
aspect.setRelationshipEntityStateFactory(relationshipEntityStateFactory());
return aspect;
}
@@ -42,7 +42,7 @@ public class Neo4jAspectConfiguration extends Neo4jConfiguration
@Bean
public Neo4jNodeBacking neo4jNodeBacking() throws Exception {
Neo4jNodeBacking aspect = Neo4jNodeBacking.aspectOf();
aspect.setGraphDatabaseContext(graphDatabaseContext());
aspect.setTemplate(neo4jTemplate());
NodeEntityStateFactory entityStateFactory = nodeEntityStateFactory();
aspect.setNodeEntityStateFactory(entityStateFactory);
return aspect;

View File

@@ -42,7 +42,7 @@ public interface GraphBacked<STATE,ENTITY extends GraphBacked<STATE,ENTITY>> ext
boolean hasPersistentState();
/**
* removes the entity using @{link GraphDatabaseContext.removeNodeEntity}
* removes the entity using @{link Neo4jTemplate.removeNodeEntity}
* the entity and relationship are still accessible after removal but before transaction commit
* but all modifications will throw an exception
*/

View File

@@ -16,12 +16,10 @@
package org.springframework.data.neo4j.aspects.fieldaccess;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.aspects.core.NodeBacked;
import org.springframework.data.neo4j.fieldaccess.FieldAccessListener;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorListenerFactory;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import javax.persistence.Id;
@@ -31,10 +29,10 @@ import javax.persistence.Id;
*/
public class JpaIdFieldAccessListenerFactory implements FieldAccessorListenerFactory
{
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public JpaIdFieldAccessListenerFactory(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public JpaIdFieldAccessListenerFactory(Neo4jTemplate template) {
this.template = template;
}
@Override
@@ -44,22 +42,22 @@ public class JpaIdFieldAccessListenerFactory implements FieldAccessorListenerFac
@Override
public FieldAccessListener forField(final Neo4jPersistentProperty property) {
return new JpaIdFieldListener(property,graphDatabaseContext);
return new JpaIdFieldListener(property, template);
}
public static class JpaIdFieldListener implements FieldAccessListener {
protected final Neo4jPersistentProperty property;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public JpaIdFieldListener(final Neo4jPersistentProperty property, GraphDatabaseContext graphDatabaseContext) {
public JpaIdFieldListener(final Neo4jPersistentProperty property, Neo4jTemplate template) {
this.property = property;
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
}
@Override
public void valueChanged(Object entity, Object oldVal, Object newVal) {
if (newVal != null) {
graphDatabaseContext.save(entity);
template.save(entity);
/* TODO EntityState entityState = entity.getEntityState();
entityState.persist();
*/

View File

@@ -25,7 +25,7 @@ import org.springframework.data.neo4j.aspects.Friendship;
import org.springframework.data.neo4j.aspects.Person;
import org.springframework.data.neo4j.aspects.PersonRepository;
import org.springframework.data.neo4j.fieldaccess.DynamicProperties;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -43,14 +43,14 @@ import static org.springframework.data.neo4j.aspects.Person.persistedPerson;
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTest-context.xml"})
public class DynamicPropertiesTest extends EntityTestBase {
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@Autowired
private PersonRepository personRepository;
@BeforeTransaction
public void cleanDb() {
Neo4jHelper.cleanDb(graphDatabaseContext);
Neo4jHelper.cleanDb(template);
}
/**

View File

@@ -21,7 +21,7 @@ import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -40,11 +40,11 @@ public class EntityPropertyValidationTest extends EntityTestBase {
protected final Log log = LogFactory.getLog(getClass());
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@BeforeTransaction
public void cleanDb() {
Neo4jHelper.cleanDb(graphDatabaseContext);
Neo4jHelper.cleanDb(template);
}
@Test(expected = ValidationException.class)

View File

@@ -24,7 +24,7 @@ import org.springframework.core.convert.ConversionService;
import org.springframework.data.neo4j.aspects.FriendshipRepository;
import org.springframework.data.neo4j.aspects.GroupRepository;
import org.springframework.data.neo4j.aspects.PersonRepository;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.transaction.BeforeTransaction;
@@ -39,7 +39,7 @@ import java.util.Set;
public class EntityTestBase {
protected final Log log = LogFactory.getLog(getClass());
@Autowired protected GraphDatabaseContext graphDatabaseContext;
@Autowired protected Neo4jTemplate neo4jTemplate;
@Autowired protected ConversionService conversionService;
@Autowired protected GraphDatabaseService graphDatabaseService;
@@ -51,32 +51,32 @@ public class EntityTestBase {
@Before
public void createTeam() throws Exception {
testTeam = new TestTeam(graphDatabaseContext);
testTeam = new TestTeam(neo4jTemplate);
}
protected Node getNodeState(Object entity) {
return graphDatabaseContext.getPersistentState(entity);
return neo4jTemplate.getPersistentState(entity);
}
protected Long getNodeId(Object entity) {
final Node node = graphDatabaseContext.getPersistentState(entity);
final Node node = neo4jTemplate.getPersistentState(entity);
return node == null ? null : node.getId();
}
protected Long getRelationshipId(Object entity) {
final Relationship rel = graphDatabaseContext.getPersistentState(entity);
final Relationship rel = neo4jTemplate.getPersistentState(entity);
return rel == null ? null : rel.getId();
}
protected boolean hasPersistentState(Object entity) {
return graphDatabaseContext.getPersistentState(entity)!=null;
return neo4jTemplate.getPersistentState(entity)!=null;
}
protected Relationship getRelationshipState(Object entity) {
return graphDatabaseContext.getPersistentState(entity);
return neo4jTemplate.getPersistentState(entity);
}
@SuppressWarnings("unchecked")
public <T> T persist(T entity) {
return (T) graphDatabaseContext.save(entity);
return (T) neo4jTemplate.save(entity);
}
protected <T> Set<T> set(T... values) {
@@ -95,6 +95,6 @@ public class EntityTestBase {
@BeforeTransaction
public void cleanDb() {
Neo4jHelper.cleanDb(graphDatabaseContext);
Neo4jHelper.cleanDb(neo4jTemplate);
}
}

View File

@@ -70,7 +70,7 @@ public class FinderTest extends EntityTestBase {
@Test
@Transactional
public void testFindIterableMapsWithQueryAnnotation() {
final TestTeam testTeam = new TestTeam(graphDatabaseContext);
final TestTeam testTeam = new TestTeam(neo4jTemplate);
testTeam.createSDGTeam();
Iterable<Map<String,Object>> teamMembers = personRepository.findAllTeamMemberData(testTeam.sdg);
assertThat(asCollection(teamMembers), hasItems(testTeam.simpleRowFor(testTeam.michael,"member"),testTeam.simpleRowFor(testTeam.david,"member"),testTeam.simpleRowFor(testTeam.emil,"member")));
@@ -79,7 +79,7 @@ public class FinderTest extends EntityTestBase {
@Test
@Transactional
public void testFindByNamedQuery() {
final TestTeam testTeam = new TestTeam(graphDatabaseContext);
final TestTeam testTeam = new TestTeam(neo4jTemplate);
testTeam.createSDGTeam();
Group team = personRepository.findTeam(testTeam.michael);
assertThat(team, is(testTeam.sdg));

View File

@@ -60,7 +60,7 @@ public class IndexTest extends EntityTestBase {
Person p2 = persistedPerson(NAME_VALUE2, 25);
Friendship friendship = p.knows(p2);
friendship.setYears(1);
GraphRepository<Friendship> friendshipFinder = graphDatabaseContext.repositoryFor(Friendship.class);
GraphRepository<Friendship> friendshipFinder = neo4jTemplate.repositoryFor(Friendship.class);
assertEquals(friendship, friendshipFinder.findByPropertyValue("Friendship.years", 1));
}
@@ -78,7 +78,7 @@ public class IndexTest extends EntityTestBase {
//@Transactional
//@Ignore("remove property from index not workin")
public void testRemovePropertyFromIndex() {
Transaction tx = graphDatabaseContext.beginTx();
Transaction tx = neo4jTemplate.beginTx();
try {
Group group = persist(new Group());
group.setName(NAME_VALUE);
@@ -95,7 +95,7 @@ public class IndexTest extends EntityTestBase {
//@Transactional
//@Ignore("remove property from index not workin")
public void testRemoveNodeFromIndex() {
Transaction tx = graphDatabaseContext.beginTx();
Transaction tx = neo4jTemplate.beginTx();
try {
Group group = persist(new Group());
group.setName(NAME_VALUE);
@@ -109,7 +109,7 @@ public class IndexTest extends EntityTestBase {
}
private Index<Node> getGroupIndex() {
return graphDatabaseContext.getIndex(Group.class);
return neo4jTemplate.getIndex(Group.class);
}
@Test
@@ -126,9 +126,9 @@ public class IndexTest extends EntityTestBase {
public void testFindGroupByInstanceIndex() {
Group group = persist(new SubGroup());
group.setIndexLevelName("indexLevelNameValue");
Index<Node> subGroupIndex = graphDatabaseContext.getIndex(SubGroup.class);
Index<Node> subGroupIndex = neo4jTemplate.getIndex(SubGroup.class);
final Node found = subGroupIndex.get("indexLevelName", "indexLevelNameValue").getSingle();
final SubGroup foundEntity = graphDatabaseContext.createEntityFromState(found, SubGroup.class);
final SubGroup foundEntity = neo4jTemplate.createEntityFromState(found, SubGroup.class);
assertEquals(group, foundEntity);
}
@@ -259,9 +259,9 @@ public class IndexTest extends EntityTestBase {
@Test
@Transactional
public void testNodeIsIndexed() {
Node node = graphDatabaseContext.createNode();
Node node = neo4jTemplate.createNode();
node.setProperty(NAME, NAME_VALUE);
Index<Node> nodeIndex = graphDatabaseContext.getGraphDatabaseService().index().forNodes("node");
Index<Node> nodeIndex = neo4jTemplate.getGraphDatabaseService().index().forNodes("node");
nodeIndex.add(node, NAME, NAME_VALUE);
Assert.assertEquals("indexed node found", node, nodeIndex.get(NAME, NAME_VALUE).next());
}
@@ -281,7 +281,7 @@ public class IndexTest extends EntityTestBase {
Transaction tx = null;
final Person p;
try {
tx = graphDatabaseContext.beginTx();
tx = neo4jTemplate.beginTx();
p = persistedPerson(NAME_VALUE2, 30);
tx.success();
} finally {
@@ -289,7 +289,7 @@ public class IndexTest extends EntityTestBase {
}
Assert.assertEquals(p, personRepository.findByPropertyValue(NAME_INDEX, "name", NAME_VALUE2));
try {
tx = graphDatabaseContext.beginTx();
tx = neo4jTemplate.beginTx();
p.setName(NAME_VALUE);
tx.success();
} finally {
@@ -297,7 +297,7 @@ public class IndexTest extends EntityTestBase {
}
Assert.assertEquals(p, personRepository.findByPropertyValue(NAME_INDEX, "name", NAME_VALUE));
try {
tx = graphDatabaseContext.beginTx();
tx = neo4jTemplate.beginTx();
p.setName(NAME_VALUE2);
tx.success();
} finally {
@@ -309,11 +309,11 @@ public class IndexTest extends EntityTestBase {
@Test
@Transactional
public void testRelationshipIsIndexed() {
Node node = graphDatabaseContext.createNode();
Node node2 = graphDatabaseContext.createNode();
Node node = neo4jTemplate.createNode();
Node node2 = neo4jTemplate.createNode();
Relationship indexedRelationship = node.createRelationshipTo(node2, DynamicRelationshipType.withName("relatesTo"));
indexedRelationship.setProperty(NAME, NAME_VALUE);
Index<Relationship> relationshipIndex = graphDatabaseContext.getGraphDatabaseService().index().forRelationships("relationship");
Index<Relationship> relationshipIndex = neo4jTemplate.getGraphDatabaseService().index().forRelationships("relationship");
relationshipIndex.add(indexedRelationship, NAME, NAME_VALUE);
Assert.assertEquals("indexed relationship found", indexedRelationship, relationshipIndex.get(NAME, NAME_VALUE).next());
}

View File

@@ -234,7 +234,7 @@ public class ModificationOutsideOfTransactionTest extends EntityTestBase {
@Test
public void testFindOutsideTransaction()
{
final GraphRepository<Person> finder = graphDatabaseContext.repositoryFor(Person.class);
final GraphRepository<Person> finder = neo4jTemplate.repositoryFor(Person.class);
assertEquals( false, finder.findAll().iterator().hasNext() );
}

View File

@@ -46,13 +46,13 @@ public class NodeEntityInstantiationTest extends EntityTestBase {
Person p = persistedPerson("Rod", 39);
long nodeId = getNodeId(p);
Node node = graphDatabaseContext.getNodeById(nodeId);
Person person1 = (Person) graphDatabaseContext.createEntityFromStoredType(node);
Node node = neo4jTemplate.getNodeById(nodeId);
Person person1 = (Person) neo4jTemplate.createEntityFromStoredType(node);
assertEquals("Rod", person1.getName());
Person person2 = graphDatabaseContext.createEntityFromState(node,Person.class);
Person person2 = neo4jTemplate.createEntityFromState(node,Person.class);
assertEquals("Rod", person2.getName());
GraphRepository<Person> finder = graphDatabaseContext.repositoryFor(Person.class);
GraphRepository<Person> finder = neo4jTemplate.repositoryFor(Person.class);
Person found = finder.findOne(nodeId);
assertEquals("Rod", found.getName());
}

View File

@@ -45,7 +45,7 @@ public class NodeEntityQueryTest extends EntityTestBase {
@Before
public void setUp() throws Exception {
testTeam = new TestTeam(graphDatabaseContext);
testTeam = new TestTeam(neo4jTemplate);
testTeam.createSDGTeam();
michael = testTeam.michael;
}

View File

@@ -232,9 +232,9 @@ public class NodeEntityRelationshipTest extends EntityTestBase {
public void multipleRelationshipsOfSameTypeBetweenTwoEntities() {
Person michael = persistedPerson("Michael", 35);
Person david = persistedPerson("David", 25);
Friendship friendship1 = graphDatabaseContext.relateTo(michael,david, Friendship.class, "knows", true);
Friendship friendship1 = neo4jTemplate.relateTo(michael,david, Friendship.class, "knows", true);
friendship1.setYears(1);
Friendship friendship2 = graphDatabaseContext.relateTo(michael,david, Friendship.class, "knows",true);
Friendship friendship2 = neo4jTemplate.relateTo(michael,david, Friendship.class, "knows",true);
friendship2.setYears(2);
assertTrue("two different relationships", friendship1 != friendship2);
assertTrue("two different relationships", getRelationshipState(friendship1) != getRelationshipState(friendship2));

View File

@@ -42,7 +42,7 @@ public class NodeEntityTest extends EntityTestBase {
Person p = persistedPerson("Rod", 39);
assertEquals(p.getName(), getNodeState(p).getProperty("name"));
assertEquals(p.getAge(), getNodeState(p).getProperty("age"));
Person found = graphDatabaseContext.createEntityFromState(graphDatabaseContext.getNodeById(getNodeId(p)), Person.class);
Person found = neo4jTemplate.createEntityFromState(neo4jTemplate.getNodeById(getNodeId(p)), Person.class);
assertEquals("Rod", getNodeState(found).getProperty("name"));
assertEquals(39, getNodeState(found).getProperty("age"));
}
@@ -81,34 +81,34 @@ public class NodeEntityTest extends EntityTestBase {
// own transaction handling because of http://wiki.neo4j.org/content/Delete_Semantics
@Test(expected = NotFoundException.class)
public void testDeleteEntityFromGDC() {
Transaction tx = graphDatabaseContext.beginTx();
Transaction tx = neo4jTemplate.beginTx();
Person p = persistedPerson("Michael", 35);
Person spouse = persistedPerson("Tina", 36);
p.setSpouse(spouse);
long id = spouse.getId();
graphDatabaseContext.removeNodeEntity(spouse);
neo4jTemplate.removeNodeEntity(spouse);
tx.success();
tx.finish();
Assert.assertNull("spouse removed " + p.getSpouse(), p.getSpouse());
Person spouseFromIndex = personRepository.findByPropertyValue(Person.NAME_INDEX, "name", "Tina");
Assert.assertNull("spouse not found in index",spouseFromIndex);
Assert.assertNull("node deleted " + id, graphDatabaseContext.getNodeById(id));
Assert.assertNull("node deleted " + id, neo4jTemplate.getNodeById(id));
}
@Test(expected = NotFoundException.class)
public void testDeleteEntity() {
Transaction tx = graphDatabaseContext.beginTx();
Transaction tx = neo4jTemplate.beginTx();
Person p = persistedPerson("Michael", 35);
Person spouse = persistedPerson("Tina", 36);
p.setSpouse(spouse);
long id = spouse.getId();
graphDatabaseContext.remove(spouse);
neo4jTemplate.remove(spouse);
tx.success();
tx.finish();
Assert.assertNull("spouse removed " + p.getSpouse(), p.getSpouse());
Person spouseFromIndex = personRepository.findByPropertyValue(Person.NAME_INDEX, "name", "Tina");
Assert.assertNull("spouse not found in index", spouseFromIndex);
Assert.assertNull("node deleted " + id, graphDatabaseContext.getNodeById(id));
Assert.assertNull("node deleted " + id, neo4jTemplate.getNodeById(id));
}
@Test

View File

@@ -37,7 +37,7 @@ public class ProjectionTest extends EntityTestBase {
Group group = persist(new Group());
group.setName("developers");
Named named = graphDatabaseContext.projectTo(group,Named.class);
Named named = neo4jTemplate.projectTo(group,Named.class);
assertEquals("named.name","developers", named.getName());
assertEquals("nameds node name property","developers", getNodeState(named).getProperty("name"));
}

View File

@@ -96,7 +96,7 @@ public class RelationshipEntityTest extends EntityTestBase {
Person p = persistedPerson("Michael", 35);
Person p2 = persistedPerson("David", 25);
Friendship f = p.knows(p2);
assertEquals(f,graphDatabaseContext.getRelationshipTo(p,p2, Friendship.class, "knows"));
assertEquals(f, neo4jTemplate.getRelationshipTo(p,p2, Friendship.class, "knows"));
}
@Test
@@ -118,7 +118,7 @@ public class RelationshipEntityTest extends EntityTestBase {
Transaction tx2 = graphDatabaseService.beginTx();
try
{
graphDatabaseContext.removeRelationshipEntity(f);
neo4jTemplate.removeRelationshipEntity(f);
tx2.success();
}
finally
@@ -147,7 +147,7 @@ public class RelationshipEntityTest extends EntityTestBase {
Transaction tx2 = graphDatabaseService.beginTx();
try
{
graphDatabaseContext.removeNodeEntity(p);
neo4jTemplate.removeNodeEntity(p);
tx2.success();
}
finally

View File

@@ -20,7 +20,7 @@ import org.neo4j.helpers.collection.MapUtil;
import org.springframework.data.neo4j.aspects.Group;
import org.springframework.data.neo4j.aspects.Person;
import org.springframework.data.neo4j.aspects.Personality;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.util.Map;
@@ -33,10 +33,10 @@ public class TestTeam {
public Person emil;
public Person david;
public Group sdg;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public TestTeam(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public TestTeam(Neo4jTemplate template) {
this.template = template;
}
public void createSDGTeam() {
@@ -46,16 +46,16 @@ public class TestTeam {
michael.setPersonality(Personality.EXTROVERT);
david = Person.persistedPerson("David", 25);
david.setBoss(emil);
sdg = graphDatabaseContext.save(new Group());
sdg = template.save(new Group());
sdg.setName("SDG");
sdg.addPerson(michael);
sdg.addPerson(emil);
sdg.addPerson(david);
// todo those should be attached and automatically written through to the db
graphDatabaseContext.save(david);
graphDatabaseContext.save(emil);
graphDatabaseContext.save(michael);
graphDatabaseContext.save(sdg);
template.save(david);
template.save(emil);
template.save(michael);
template.save(sdg);
}
public Map<String, Object> simpleRowFor(final Person person, String prefix) {

View File

@@ -53,7 +53,7 @@ public class TraversalTest extends EntityTestBase {
group.setName("dev");
group.addPerson(p);
final TraversalDescription traversalDescription = Traversal.description().relationships(DynamicRelationshipType.withName("persons")).evaluator(Evaluators.excludeStartPosition());
Iterable<Person> people = graphDatabaseContext.<Person>findAllByTraversal(group,Person.class, traversalDescription);
Iterable<Person> people = neo4jTemplate.<Person>findAllByTraversal(group,Person.class, traversalDescription);
final HashSet<Person> found = new HashSet<Person>();
for (Person person : people) {
found.add(person);
@@ -69,7 +69,7 @@ public class TraversalTest extends EntityTestBase {
group.setName("dev");
group.addPerson(p);
final TraversalDescription traversalDescription = Traversal.description().relationships(DynamicRelationshipType.withName("persons"), Direction.OUTGOING).evaluator(Evaluators.excludeStartPosition());
Iterable<EntityPath<Group,Person>> paths = (Iterable<EntityPath<Group, Person>>) graphDatabaseContext.<EntityPath<Group,Person>>findAllByTraversal(group, EntityPath.class, traversalDescription);
Iterable<EntityPath<Group,Person>> paths = (Iterable<EntityPath<Group, Person>>) neo4jTemplate.<EntityPath<Group,Person>>findAllByTraversal(group, EntityPath.class, traversalDescription);
for (EntityPath<Group, Person> path : paths) {
assertEquals(group, path.startEntity());
assertEquals(p, path.endEntity());
@@ -107,7 +107,7 @@ public class TraversalTest extends EntityTestBase {
@Test
@Transactional
public void testTraverseFromGroupToPeopleWithFinder() {
final GraphRepository<Person> finder = graphDatabaseContext.repositoryFor(Person.class);
final GraphRepository<Person> finder = neo4jTemplate.repositoryFor(Person.class);
Person p = persistedPerson("Michael", 35);
Group group = persist(new Group());
group.setName("dev");

View File

@@ -40,7 +40,7 @@ public class EntityMapperTest extends EntityTestBase {
@Transactional
public void entityMapperShouldForwardEntityPath() throws Exception {
Person michael = persist(new Person("Michael", 36));
EntityMapper<Person, Person, String> mapper = new EntityMapper<Person, Person, String>(graphDatabaseContext) {
EntityMapper<Person, Person, String> mapper = new EntityMapper<Person, Person, String>(neo4jTemplate) {
@Override
public String mapPath(EntityPath<Person, Person> entityPath) {
return entityPath.<Person>startEntity().getName();

View File

@@ -43,7 +43,7 @@ public class EntityPathTest extends EntityTestBase {
Person michael = persist(new Person("Michael", 36));
Node node = getNodeState(michael);
NodePath path = new NodePath(node);
EntityPath<Person, Person> entityPath = new ConvertingEntityPath<Person, Person>(graphDatabaseContext, path);
EntityPath<Person, Person> entityPath = new ConvertingEntityPath<Person, Person>(neo4jTemplate, path);
Assert.assertEquals("start entity",michael, entityPath.startEntity());
Assert.assertEquals("start node",node, path.startNode());

View File

@@ -57,7 +57,7 @@ public class GremlinQueryEngineTest extends EntityTestBase {
}
protected GraphDatabase createGraphDatabase() throws Exception {
final DelegatingGraphDatabase graphDatabase = new DelegatingGraphDatabase(graphDatabaseContext.getGraphDatabaseService());
final DelegatingGraphDatabase graphDatabase = new DelegatingGraphDatabase(neo4jTemplate.getGraphDatabaseService());
graphDatabase.setConversionService(conversionService);
return graphDatabase;
}

View File

@@ -32,7 +32,7 @@ import org.springframework.data.neo4j.conversion.Result;
import org.springframework.data.neo4j.conversion.ResultConverter;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.conversion.EntityResultConverter;
import org.springframework.data.neo4j.support.query.QueryEngine;
import org.springframework.test.context.ContextConfiguration;
@@ -57,7 +57,7 @@ public class QueryEngineTest extends EntityTestBase {
@Autowired
protected ConversionService conversionService;
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
private QueryEngine<Map<String,Object>> queryEngine;
private Person michael;
@@ -70,7 +70,7 @@ public class QueryEngineTest extends EntityTestBase {
}
protected GraphDatabase createGraphDatabase() throws Exception {
final DelegatingGraphDatabase graphDatabase = new DelegatingGraphDatabase(graphDatabaseContext.getGraphDatabaseService());
final DelegatingGraphDatabase graphDatabase = new DelegatingGraphDatabase(template.getGraphDatabaseService());
graphDatabase.setConversionService(conversionService);
return graphDatabase;
}
@@ -95,7 +95,7 @@ public class QueryEngineTest extends EntityTestBase {
@Test
public void testQueryListOfTypePerson() throws Exception {
final String queryString = "start person=node:name_index(name={name}) match (person) <-[:boss]- (boss) return boss";
final Collection<Person> result = IteratorUtil.asCollection(queryEngine.query(queryString, michaelsName()).to(Person.class, new EntityResultConverter(graphDatabaseContext)));
final Collection<Person> result = IteratorUtil.asCollection(queryEngine.query(queryString, michaelsName()).to(Person.class, new EntityResultConverter(template)));
assertEquals(asList(testTeam.emil),result);
}
@@ -107,7 +107,7 @@ public class QueryEngineTest extends EntityTestBase {
@Test
public void testQuerySingleOfTypePerson() throws Exception {
final String queryString = "start person=node:name_index(name={name}) match (person) <-[:boss]- (boss) return boss";
final Person result = queryEngine.query(queryString, michaelsName()).to(Person.class, new EntityResultConverter<Map<String,Object>,Person>(graphDatabaseContext)).single();
final Person result = queryEngine.query(queryString, michaelsName()).to(Person.class, new EntityResultConverter<Map<String,Object>,Person>(template)).single();
assertEquals(testTeam.emil,result);
}

View File

@@ -169,11 +169,11 @@ public class IndexingNodeTypeRepresentationStrategyTest extends EntityTestBase {
Transaction tx = graphDatabaseService.beginTx();
try {
Node n1 = graphDatabaseService.createNode();
thing = graphDatabaseContext.setPersistentState(new Thing(),n1);
thing = neo4jTemplate.setPersistentState(new Thing(),n1);
nodeTypeRepresentationStrategy.postEntityCreation(n1, Thing.class);
thing.setName("thing");
Node n2 = graphDatabaseService.createNode();
subThing = graphDatabaseContext.setPersistentState(new SubThing(),n2);
subThing = neo4jTemplate.setPersistentState(new SubThing(),n2);
nodeTypeRepresentationStrategy.postEntityCreation(n2, SubThing.class);
subThing.setName("subThing");
tx.success();

View File

@@ -153,7 +153,7 @@ public class IndexingRelationshipTypeRepresentationStrategyTest extends EntityTe
Node n2 = graphDatabaseService.createNode();
Relationship rel = n1.createRelationshipTo(n2, DynamicRelationshipType.withName("link"));
link = new Link();
graphDatabaseContext.setPersistentState(link,rel);
neo4jTemplate.setPersistentState(link,rel);
relationshipTypeRepresentationStrategy.postEntityCreation(rel, Link.class);
link.setLabel("link");
tx.success();

View File

@@ -104,15 +104,15 @@ public class NoopTypeRepresentationStrategyTest extends EntityTestBase {
}
private Thing createThing() {
Transaction tx = graphDatabaseContext.beginTx();
Transaction tx = neo4jTemplate.beginTx();
try {
Node node = graphDatabaseContext.createNode();
Node node = neo4jTemplate.createNode();
thing = new Thing();
graphDatabaseContext.setPersistentState(thing,node);
neo4jTemplate.setPersistentState(thing,node);
noopNodeStrategy.postEntityCreation(node, Thing.class);
Relationship rel = node.createRelationshipTo(graphDatabaseContext.createNode(), DynamicRelationshipType.withName("link"));
Relationship rel = node.createRelationshipTo(neo4jTemplate.createNode(), DynamicRelationshipType.withName("link"));
link = new Link();
graphDatabaseContext.setPersistentState(link,rel);
neo4jTemplate.setPersistentState(link,rel);
noopRelationshipStrategy.postEntityCreation(rel, Link.class);
tx.success();
return thing;

View File

@@ -80,7 +80,7 @@ public class SubReferenceNodeTypeRepresentationStrategyTest extends EntityTestBa
}
@Test(expected = IllegalArgumentException.class)
public void gettingTypeFromNonTypeNodeShouldThrowAnDescriptiveException() throws Exception {
Node referenceNode = graphDatabaseContext.getReferenceNode();
Node referenceNode = neo4jTemplate.getReferenceNode(Node.class);
nodeTypeRepresentationStrategy.getJavaType(referenceNode);
}
@@ -90,14 +90,14 @@ public class SubReferenceNodeTypeRepresentationStrategyTest extends EntityTestBa
}
private void createThing() {
Transaction tx = graphDatabaseContext.beginTx();
Transaction tx = neo4jTemplate.beginTx();
try {
thingNode = graphDatabaseContext.createNode();
thing = graphDatabaseContext.setPersistentState(new Thing(),thingNode);
thingNode = neo4jTemplate.createNode();
thing = neo4jTemplate.setPersistentState(new Thing(),thingNode);
nodeTypeRepresentationStrategy.postEntityCreation(thingNode, Thing.class);
thing.setName("thing");
subThingNode = graphDatabaseContext.createNode();
subThing = graphDatabaseContext.setPersistentState(new SubThing(),subThingNode);
subThingNode = neo4jTemplate.createNode();
subThing = neo4jTemplate.setPersistentState(new SubThing(),subThingNode);
nodeTypeRepresentationStrategy.postEntityCreation(subThingNode, SubThing.class);
subThing.setName("subThing");
tx.success();
@@ -172,7 +172,7 @@ public class SubReferenceNodeTypeRepresentationStrategyTest extends EntityTestBa
public void testInstantiateConcreteClassWithFinder() {
log.debug("testInstantiateConcreteClassWithFinder");
Volvo v = persist(new Volvo());
GraphRepository<Car> finder = graphDatabaseContext.repositoryFor(Car.class);
GraphRepository<Car> finder = neo4jTemplate.repositoryFor(Car.class);
assertEquals("Wrong concrete class.", Volvo.class, finder.findAll().iterator().next().getClass());
}
@@ -184,16 +184,16 @@ public class SubReferenceNodeTypeRepresentationStrategyTest extends EntityTestBa
log.warn("Created volvo");
persist(new Toyota());
log.warn("Created volvo");
assertEquals("Wrong count for Volvo.", 1L, graphDatabaseContext.repositoryFor(Volvo.class).count());
assertEquals("Wrong count for Toyota.", 1L, graphDatabaseContext.repositoryFor(Toyota.class).count());
assertEquals("Wrong count for Car.", 2L, graphDatabaseContext.repositoryFor(Car.class).count());
assertEquals("Wrong count for Volvo.", 1L, neo4jTemplate.repositoryFor(Volvo.class).count());
assertEquals("Wrong count for Toyota.", 1L, neo4jTemplate.repositoryFor(Toyota.class).count());
assertEquals("Wrong count for Car.", 2L, neo4jTemplate.repositoryFor(Car.class).count());
}
@Test
@Transactional
public void testCountClasses() {
persistedPerson("Michael", 36);
persistedPerson("David", 25);
assertEquals("Wrong Person instance count.", 2L, graphDatabaseContext.repositoryFor(Person.class).count());
assertEquals("Wrong Person instance count.", 2L, neo4jTemplate.repositoryFor(Person.class).count());
}

View File

@@ -18,19 +18,19 @@
<bean id="neo4jNodeBacking" class="org.springframework.data.neo4j.aspects.support.node.Neo4jNodeBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="template" ref="template"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
</bean>
<bean class="org.springframework.data.neo4j.aspects.support.relationship.Neo4jRelationshipBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="template" ref="template"/>
<property name="relationshipEntityStateFactory" ref="relationshipEntityStateFactory"/>
</bean>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown" scope="singleton"/>
<bean id="conversionService" class="org.springframework.data.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean"/>
<bean id="graphDatabaseContext" class="org.springframework.data.neo4j.support.GraphDatabaseContext" init-method="postConstruct">
<bean id="template" class="org.springframework.data.neo4j.support.Neo4jTemplate" init-method="postConstruct">
<property name="graphDatabaseService" ref="graphDatabaseService"/>
<property name="conversionService" ref="conversionService"/>
<property name="mappingContext" ref="mappingContext"/>
@@ -52,6 +52,9 @@
<bean id="entityStateHandler" class="org.springframework.data.neo4j.support.EntityStateHandler">
<constructor-arg ref="mappingContext"/>
<constructor-arg ref="graphDatabase"/>
</bean>
<bean id="graphDatabase" class="org.springframework.data.neo4j.support.DelegatingGraphDatabase">
<constructor-arg ref="graphDatabaseService"/>
</bean>
<bean id="relationshipEntityInstantiator" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator">
@@ -74,10 +77,10 @@
<bean id="nodeEntityStateFactory" class="org.springframework.data.neo4j.support.node.NodeEntityStateFactory">
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
<constructor-arg ref="template"/>
</bean>
</property>
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="template" ref="template"/>
<property name="mappingContext" ref="mappingContext"/>
</bean>
@@ -86,10 +89,10 @@
<bean id="relationshipEntityStateFactory" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory">
<property name="relationshipDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
<constructor-arg ref="template"/>
</bean>
</property>
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="template" ref="template"/>
<property name="mappingContext" ref="mappingContext"/>
</bean>
@@ -114,7 +117,7 @@
<bean id="personRepository" class="org.springframework.data.neo4j.repository.GraphRepositoryFactoryBean">
<property name="repositoryInterface" value="org.springframework.data.neo4j.aspects.PersonRepository" />
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="neo4jTemplate" ref="template"/>
<property name="namedQueries">
<bean class="org.springframework.data.repository.core.support.PropertiesBasedNamedQueries">
<constructor-arg>
@@ -125,11 +128,11 @@
</bean>
<bean id="groupRepository" class="org.springframework.data.neo4j.repository.GraphRepositoryFactoryBean">
<property name="repositoryInterface" value="org.springframework.data.neo4j.aspects.GroupRepository" />
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="neo4jTemplate" ref="template"/>
</bean>
<bean id="friendshipRepository" class="org.springframework.data.neo4j.repository.GraphRepositoryFactoryBean">
<property name="repositoryInterface" value="org.springframework.data.neo4j.aspects.FriendshipRepository" />
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="neo4jTemplate" ref="template"/>
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

View File

@@ -28,7 +28,7 @@ import org.springframework.data.neo4j.aspects.fieldaccess.JpaIdFieldAccessListen
import org.springframework.data.neo4j.fieldaccess.*;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import javax.persistence.PersistenceUnitUtil;
import java.lang.reflect.Field;
@@ -44,12 +44,12 @@ public class CrossStoreNodeEntityState<ENTITY extends NodeBacked> extends Defaul
public static final String FOREIGN_ID = "foreignId";
public static final String FOREIGN_ID_INDEX = "foreign_id";
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
private PersistenceUnitUtil persistenceUnitUtil;
public CrossStoreNodeEntityState(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, PersistenceUnitUtil persistenceUnitUtil, final CrossStoreNodeDelegatingFieldAccessorFactory delegatingFieldAccessorFactory, final Neo4jPersistentEntity persistentEntity) {
public CrossStoreNodeEntityState(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final Neo4jTemplate template, PersistenceUnitUtil persistenceUnitUtil, final CrossStoreNodeDelegatingFieldAccessorFactory delegatingFieldAccessorFactory, final Neo4jPersistentEntity persistentEntity) {
super(underlyingState, entity, type, delegatingFieldAccessorFactory, persistentEntity);
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
this.persistenceUnitUtil = persistenceUnitUtil;
}
@@ -65,11 +65,11 @@ public class CrossStoreNodeEntityState<ENTITY extends NodeBacked> extends Defaul
IndexHits<Node> indexHits = getForeignIdIndex().get(FOREIGN_ID, foreignId);
Node node = indexHits.hasNext() ? indexHits.next() : null;
if (node == null) {
node = graphDatabaseContext.createNode();
node = template.createNode();
persistForeignId(node, id);
setPersistentState(node);
log.info("User-defined constructor called on class " + entity.getClass() + "; created Node [" + entity.getPersistentState() + "]; Updating metamodel");
graphDatabaseContext.postEntityCreation(node, type);
template.postEntityCreation(node, type);
} else {
setPersistentState(node);
entity.setPersistentState(node);
@@ -104,7 +104,7 @@ public class CrossStoreNodeEntityState<ENTITY extends NodeBacked> extends Defaul
}
private Index<Node> getForeignIdIndex() {
return graphDatabaseContext.getIndex(type);
return template.getIndex(type,null,false);
}
private String createForeignId(Object id) {
@@ -117,15 +117,15 @@ public class CrossStoreNodeEntityState<ENTITY extends NodeBacked> extends Defaul
public static class CrossStoreNodeDelegatingFieldAccessorFactory extends DelegatingFieldAccessorFactory {
public CrossStoreNodeDelegatingFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext);
public CrossStoreNodeDelegatingFieldAccessorFactory(Neo4jTemplate template) {
super(template);
}
@Override
protected Collection<FieldAccessorListenerFactory> createListenerFactories() {
return Arrays.asList(
new IndexingPropertyFieldAccessorListenerFactory(
getGraphDatabaseContext(),
getTemplate(),
newPropertyFieldAccessorFactory(),
newConvertingNodePropertyFieldAccessorFactory()) {
@Override
@@ -133,7 +133,7 @@ public class CrossStoreNodeEntityState<ENTITY extends NodeBacked> extends Defaul
return property.isAnnotationPresent(GraphProperty.class) && super.accept(property);
}
},
new JpaIdFieldAccessListenerFactory(graphDatabaseContext));
new JpaIdFieldAccessListenerFactory(template));
}
@Override
@@ -141,24 +141,24 @@ public class CrossStoreNodeEntityState<ENTITY extends NodeBacked> extends Defaul
return Arrays.asList(
//new IdFieldAccessorFactory(),
//new TransientFieldAccessorFactory(),
new TraversalFieldAccessorFactory(graphDatabaseContext),
new QueryFieldAccessorFactory(graphDatabaseContext),
new TraversalFieldAccessorFactory(template),
new QueryFieldAccessorFactory(template),
newPropertyFieldAccessorFactory(),
newConvertingNodePropertyFieldAccessorFactory(),
new SingleRelationshipFieldAccessorFactory(getGraphDatabaseContext()) {
new SingleRelationshipFieldAccessorFactory(getTemplate()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(RelatedTo.class) && super.accept(property);
}
},
new OneToNRelationshipFieldAccessorFactory(getGraphDatabaseContext()),
new ReadOnlyOneToNRelationshipFieldAccessorFactory(getGraphDatabaseContext()),
new OneToNRelationshipEntityFieldAccessorFactory(getGraphDatabaseContext())
new OneToNRelationshipFieldAccessorFactory(getTemplate()),
new ReadOnlyOneToNRelationshipFieldAccessorFactory(getTemplate()),
new OneToNRelationshipEntityFieldAccessorFactory(getTemplate())
);
}
private ConvertingNodePropertyFieldAccessorFactory newConvertingNodePropertyFieldAccessorFactory() {
return new ConvertingNodePropertyFieldAccessorFactory(getGraphDatabaseContext()) {
return new ConvertingNodePropertyFieldAccessorFactory(getTemplate()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(GraphProperty.class) && super.accept(property);
@@ -167,7 +167,7 @@ public class CrossStoreNodeEntityState<ENTITY extends NodeBacked> extends Defaul
}
private PropertyFieldAccessorFactory newPropertyFieldAccessorFactory() {
return new PropertyFieldAccessorFactory(getGraphDatabaseContext()) {
return new PropertyFieldAccessorFactory(getTemplate()) {
@Override
public boolean accept(Neo4jPersistentProperty property) {
return property.isAnnotationPresent(GraphProperty.class) && super.accept(property);

View File

@@ -21,10 +21,8 @@ import org.springframework.data.neo4j.aspects.core.NodeBacked;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.fieldaccess.DetachedEntityState;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.support.node.NodeEntityState;
import org.springframework.data.neo4j.support.node.NodeEntityStateFactory;
import javax.annotation.PostConstruct;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnitUtil;
@@ -42,10 +40,10 @@ public class CrossStoreNodeEntityStateFactory extends NodeEntityStateFactory {
final Neo4jPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityType);
@SuppressWarnings("unchecked") final CrossStoreNodeEntityState<NodeBacked> partialNodeEntityState =
new CrossStoreNodeEntityState<NodeBacked>(null, (NodeBacked)entity, (Class<? extends NodeBacked>) entityType,
graphDatabaseContext, getPersistenceUnitUtils(), delegatingFieldAccessorFactory,
template, getPersistenceUnitUtils(), delegatingFieldAccessorFactory,
persistentEntity);
if (!detachable) return partialNodeEntityState;
return new DetachedEntityState<Node>(partialNodeEntityState, graphDatabaseContext) {
return new DetachedEntityState<Node>(partialNodeEntityState, template) {
@Override
protected boolean isDetached() {
return super.isDetached() || partialNodeEntityState.getId(entity) == null;
@@ -71,7 +69,7 @@ public class CrossStoreNodeEntityStateFactory extends NodeEntityStateFactory {
}
public void postConstruct() {
this.delegatingFieldAccessorFactory = new CrossStoreNodeEntityState.CrossStoreNodeDelegatingFieldAccessorFactory(graphDatabaseContext);
this.delegatingFieldAccessorFactory = new CrossStoreNodeEntityState.CrossStoreNodeDelegatingFieldAccessorFactory(template);
}
}

View File

@@ -22,7 +22,7 @@ import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.transaction.PlatformTransactionManager;
/**
@@ -36,7 +36,7 @@ public class DataGraphNamespaceHandlerCrossStoreTest {
@Autowired
GraphDatabaseService graphDatabaseService;
@Autowired
GraphDatabaseContext graphDatabaseContext;
Neo4jTemplate template;
@Autowired
PlatformTransactionManager transactionManager;
}
@@ -49,9 +49,9 @@ public class DataGraphNamespaceHandlerCrossStoreTest {
private Config assertInjected(String testCase) {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:org/springframework/data/neo4j/config/DataGraphNamespaceHandlerTest" + testCase + "-context.xml");
Config config = ctx.getBean("config", Config.class);
GraphDatabaseContext graphDatabaseContext = config.graphDatabaseContext;
Assert.assertNotNull("graphDatabaseContext", graphDatabaseContext);
EmbeddedGraphDatabase graphDatabaseService = (EmbeddedGraphDatabase) graphDatabaseContext.getGraphDatabaseService();
Neo4jTemplate template = config.template;
Assert.assertNotNull("template", template);
EmbeddedGraphDatabase graphDatabaseService = (EmbeddedGraphDatabase) template.getGraphDatabaseService();
Assert.assertEquals("store-dir", "target/config-test", graphDatabaseService.getStoreDir());
Assert.assertNotNull("graphDatabaseService", config.graphDatabaseService);
Assert.assertNotNull("transactionManager", config.transactionManager);

View File

@@ -22,7 +22,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
@@ -50,7 +50,7 @@ public class RecommendationTest {
PlatformTransactionManager transactionManager;
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@PersistenceContext
EntityManager em;
@@ -60,7 +60,7 @@ public class RecommendationTest {
@BeforeTransaction
public void cleanDb() {
Neo4jHelper.cleanDb(graphDatabaseContext);
Neo4jHelper.cleanDb(template);
}
@Test

View File

@@ -71,12 +71,12 @@
-->
<bean id="neo4jNodeBacking" class="org.springframework.data.neo4j.aspects.support.node.Neo4jNodeBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="template" ref="neo4jTemplate"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
</bean>
<bean class="org.springframework.data.neo4j.aspects.support.relationship.Neo4jRelationshipBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="template" ref="neo4jTemplate"/>
<property name="relationshipEntityStateFactory" ref="relationshipEntityStateFactory"/>
</bean>
@@ -86,7 +86,11 @@
<constructor-arg index="0" value="target/data/recommendation" />
</bean>
<bean id="graphDatabaseContext" class="org.springframework.data.neo4j.support.GraphDatabaseContext">
<bean id="graphDatabase" class="org.springframework.data.neo4j.support.DelegatingGraphDatabase">
<constructor-arg ref="graphDatabaseService"/>
</bean>
<bean id="neo4jTemplate" class="org.springframework.data.neo4j.support.Neo4jTemplate">
<property name="graphDatabaseService" ref="graphDatabaseService"/>
<property name="conversionService">
<bean class="org.springframework.data.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean"/>
@@ -95,6 +99,8 @@
<property name="relationshipTypeRepresentationStrategy" ref="relationshipTypeRepresentationStrategy"/>
<property name="entityStateHandler" ref="entityStateHandler"/>
<property name="mappingContext" ref="mappingContext"/>
<property name="graphDatabase" ref="graphDatabase"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="graphEntityInstantiator" class="org.springframework.data.neo4j.cross_store.support.node.CrossStoreNodeEntityInstantiator">
<constructor-arg ref="nodeEntityInstantiator"/>
@@ -102,7 +108,7 @@
</bean>
<bean id="entityStateHandler" class="org.springframework.data.neo4j.support.EntityStateHandler">
<constructor-arg ref="mappingContext"/>
<constructor-arg ref="graphDatabaseService"/>
<constructor-arg ref="graphDatabase"/>
</bean>
<bean id="relationshipEntityInstantiator" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator">
<constructor-arg ref="entityStateHandler"/>
@@ -124,10 +130,10 @@
<bean id="nodeEntityStateFactory" class="org.springframework.data.neo4j.cross_store.support.node.CrossStoreNodeEntityStateFactory" init-method="postConstruct">
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
<constructor-arg ref="neo4jTemplate"/>
</bean>
</property>
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="template" ref="neo4jTemplate"/>
<property name="entityManagerFactory" ref="entityManagerFactory"/>
<property name="mappingContext" ref="mappingContext"/>
</bean>
@@ -138,10 +144,10 @@
<bean id="relationshipEntityStateFactory" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory">
<property name="relationshipDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.neo4j.fieldaccess.RelationshipDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
<constructor-arg ref="neo4jTemplate"/>
</bean>
</property>
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="template" ref="neo4jTemplate"/>
<property name="mappingContext" ref="mappingContext"/>
</bean>

View File

@@ -6,7 +6,7 @@ import org.neo4j.cineasts.movieimport.MovieDbImportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -23,7 +23,7 @@ import static java.util.Arrays.asList;
public class DatabasePopulator {
@Autowired
GraphDatabaseContext ctx;
Neo4jTemplate ctx;
@Autowired
CineastsRepository repository;

View File

@@ -13,8 +13,8 @@
<context:annotation-config/>
<neo4j:config storeDirectory="target/neo4j-db"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.examples.hellograph" graph-database-context-ref="graphDatabaseContext"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.examples.hellograph"/>
<tx:annotation-driven mode="aspectj" transaction-manager="neo4jTransactionManager"/>
<tx:annotation-driven mode="aspectj"/>
</beans>

View File

@@ -3,7 +3,7 @@ package org.springframework.data.neo4j.examples.hellograph;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
@@ -27,13 +27,13 @@ import static org.junit.Assert.assertEquals;
public class WorldCounterTest {
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@Rollback(false)
@BeforeTransaction
public void clearDatabase()
{
Neo4jHelper.cleanDb(graphDatabaseContext);
Neo4jHelper.cleanDb(template);
}
@Test

View File

@@ -4,7 +4,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.aspects.core.NodeBacked;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
@@ -34,13 +34,13 @@ public class WorldRepositoryTest
private WorldRepository galaxy;
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@Rollback(false)
@BeforeTransaction
public void clearDatabase()
{
Neo4jHelper.cleanDb(graphDatabaseContext);
Neo4jHelper.cleanDb(template);
}
@Test

View File

@@ -3,8 +3,7 @@ package org.springframework.data.neo4j.examples.hellograph;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.examples.hellograph.World;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
@@ -27,13 +26,13 @@ public class WorldTest
{
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@Rollback(false)
@BeforeTransaction
public void clearDatabase()
{
Neo4jHelper.cleanDb(graphDatabaseContext);
Neo4jHelper.cleanDb(template);
}
@Test

View File

@@ -5,7 +5,7 @@ import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.kernel.StandardExpander;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
@@ -15,7 +15,7 @@ import java.util.NoSuchElementException;
class ImdbServiceImpl implements ImdbService {
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@Autowired
private ImdbSearchEngine searchEngine;
@Autowired
@@ -58,7 +58,7 @@ class ImdbServiceImpl implements ImdbService {
@Transactional
public void setupReferenceRelationship() {
Node referenceNode = graphDatabaseContext.getReferenceNode();
Node referenceNode = template.getReferenceNode(Node.class);
Actor bacon = actorRepository.findByPropertyValue("name", "Bacon, Kevin");
if (bacon == null) throw new NoSuchElementException("Unable to find Kevin Bacon actor");
@@ -81,9 +81,9 @@ class ImdbServiceImpl implements ImdbService {
int mod = 0;
for (Node node : list.nodes()) {
if (mod++ % 2 == 0) {
actorAndMovieList.add(graphDatabaseContext.createEntityFromState(node, Actor.class));
actorAndMovieList.add(template.createEntityFromState(node, Actor.class));
} else {
actorAndMovieList.add(graphDatabaseContext.createEntityFromState(node, Movie.class));
actorAndMovieList.add(template.createEntityFromState(node, Movie.class));
}
}
return actorAndMovieList;

View File

@@ -14,7 +14,7 @@
<neo4j:config storeDirectory="target/neo4j-db"/>
<neo4j:repositories base-package="org.neo4j.examples.imdb.domain" graph-database-context-ref="graphDatabaseContext"/>
<neo4j:repositories base-package="org.neo4j.examples.imdb.domain" graph-database-context-ref="template"/>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>

View File

@@ -8,7 +8,7 @@ import org.neo4j.kernel.Traversal;
import org.neo4j.kernel.impl.traversal.TraversalDescriptionImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.util.*;
@@ -20,7 +20,7 @@ import java.util.*;
public class TopRatedRestaurantFinder {
@Autowired
GraphDatabaseContext graphDatabaseContext;
Neo4jTemplate template;
private static final int MAXIMUM_DEPTH = 5;
public Collection<RatedRestaurant> getTopNRatedRestaurants(final UserAccount user, final int n) {
@@ -64,9 +64,9 @@ public class TopRatedRestaurantFinder {
}
private RatedRestaurant toRatedRestaurant(final CalculateRatingPredicate calculateRatingPredicate) {
final RatedRestaurant ratedRestaurant = new RatedRestaurant(graphDatabaseContext.createEntityFromState(restaurant, Restaurant.class));
final RatedRestaurant ratedRestaurant = new RatedRestaurant(template.createEntityFromState(restaurant, Restaurant.class));
for (final Relationship recommendation : recommendations) {
ratedRestaurant.add(graphDatabaseContext.createEntityFromState(recommendation, Recommendation.class));
ratedRestaurant.add(template.createEntityFromState(recommendation, Recommendation.class));
}
return ratedRestaurant;
}

View File

@@ -12,9 +12,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.transaction.annotation.Transactional;
@@ -27,7 +26,7 @@ public class AbstractTestWithUserAccount {
protected Long userId;
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@PersistenceContext
protected EntityManager em;
@@ -60,7 +59,7 @@ public class AbstractTestWithUserAccount {
@Transactional
@BeforeTransaction
public void cleanDb() {
Neo4jHelper.cleanDb(graphDatabaseContext);
Neo4jHelper.cleanDb(template);
}
@AfterTransaction

View File

@@ -4,11 +4,10 @@ import com.springone.myrestaurants.domain.Restaurant;
import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
@@ -32,7 +31,7 @@ public class RestaurantRepositoryTest {
PlatformTransactionManager transactionManager;
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@PersistenceContext
EntityManager em;
@@ -43,7 +42,7 @@ public class RestaurantRepositoryTest {
@Transactional
@BeforeTransaction
public void cleanDb() {
Neo4jHelper.cleanDb(graphDatabaseContext);
Neo4jHelper.cleanDb(template);
}
@Transactional

View File

@@ -6,7 +6,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.Node;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.test.annotation.DirtiesContext;
@@ -36,7 +36,7 @@ import static java.util.Arrays.asList;
@Transactional
public class TopRatedRestaurantFinderTest {
@Autowired
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@PersistenceContext
EntityManager em;
@@ -50,7 +50,7 @@ public class TopRatedRestaurantFinderTest {
@Before
@BeforeTransaction
public void cleanDb() {
Neo4jHelper.cleanDb(graphDatabaseContext);
Neo4jHelper.cleanDb(template);
}
@Test

View File

@@ -23,6 +23,7 @@ import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.rest.graphdb.*;
import org.neo4j.rest.graphdb.RestRequest;
import org.neo4j.rest.graphdb.index.RestIndexManager;
import org.neo4j.rest.graphdb.query.RestCypherQueryEngine;
import org.neo4j.rest.graphdb.query.RestGremlinQueryEngine;
import org.springframework.core.convert.ConversionService;
@@ -115,4 +116,36 @@ public class SpringRestGraphDatabase extends org.neo4j.rest.graphdb.RestGraphDat
return resultConverter.convert(value,target);
}
}
@Override
public boolean transactionIsRunning() {
return true;
}
@Override
public void remove(Node node) {
removeFromIndexes(node);
node.delete();
}
@Override
public void remove(Relationship relationship) {
removeFromIndexes(relationship);
relationship.delete();
}
private void removeFromIndexes(Node node) {
final RestIndexManager indexManager = index();
for (String indexName : indexManager.nodeIndexNames()) {
indexManager.forNodes(indexName).remove(node);
}
}
private void removeFromIndexes(Relationship relationship) {
final RestIndexManager indexManager = index();
for (String indexName : indexManager.relationshipIndexNames()) {
indexManager.forRelationships(indexName).remove(relationship);
}
}
}

View File

@@ -23,7 +23,7 @@ import org.neo4j.server.plugins.*;
import org.springframework.context.ApplicationContext;
import org.springframework.data.neo4j.aspects.*;
import org.springframework.data.neo4j.server.ProvidedClassPathXmlApplicationContext;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
/**
* @author mh
@@ -34,7 +34,7 @@ public class TestServerPlugin extends ServerPlugin {
private ApplicationContext ctx;
private PersonRepository personRepository;
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
public TestServerPlugin() {
System.out.println("Initializing ServerPlugin");
@@ -52,7 +52,7 @@ public class TestServerPlugin extends ServerPlugin {
if (ctx==null) {
ctx = new ProvidedClassPathXmlApplicationContext(graphDb, "Plugin-context.xml");
personRepository = ctx.getBean(PersonRepository.class);
graphDatabaseContext = ctx.getBean(GraphDatabaseContext.class);
template = ctx.getBean(Neo4jTemplate.class);
}
return ctx;
}
@@ -62,7 +62,7 @@ public class TestServerPlugin extends ServerPlugin {
@PluginTarget(Node.class)
public Iterable<Node> allFriendsOf(@Source Node target) {
context(target.getGraphDatabase());
final Person person = graphDatabaseContext.createEntityFromState(target, Person.class);
final Person person = template.createEntityFromState(target, Person.class);
return new IterableWrapper<Node, Friendship>(person.getFriendships()) {
@Override
protected Node underlyingObjectToObject(Friendship friendship) {

View File

@@ -16,8 +16,9 @@
package org.springframework.data.neo4j.config;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
@@ -27,11 +28,11 @@ import javax.annotation.PostConstruct;
* Validates correct configuration of Neo4j and Spring, especially transaction-managers
*/
public class ConfigurationCheck {
GraphDatabaseContext graphDatabaseContext;
Neo4jTemplate template;
PlatformTransactionManager transactionManager;
public ConfigurationCheck(GraphDatabaseContext graphDatabaseContext, PlatformTransactionManager transactionManager) {
this.graphDatabaseContext = graphDatabaseContext;
public ConfigurationCheck(Neo4jTemplate template, PlatformTransactionManager transactionManager) {
this.template = template;
this.transactionManager = transactionManager;
}
@@ -43,7 +44,7 @@ public class ConfigurationCheck {
}
private void checkInjection() {
assert graphDatabaseContext.getGraphDatabaseService()!=null : "graphDatabaseService not correctly configured, please refer to the manual, setup section";
assert template.getGraphDatabaseService()!=null : "graphDatabaseService not correctly configured, please refer to the manual, setup section";
}
private void checkSpringTransactionManager() {
@@ -61,7 +62,7 @@ public class ConfigurationCheck {
private void checkNeo4jTransactionManager() {
Transaction tx = null;
try {
tx = graphDatabaseContext.beginTx();
tx = template.beginTx();
updateStartTime();
tx.success();
} catch (Exception e) {
@@ -78,6 +79,6 @@ public class ConfigurationCheck {
}
private void updateStartTime() {
graphDatabaseContext.getReferenceNode().setProperty("startTime", System.currentTimeMillis());
template.getReferenceNode(Node.class).setProperty("startTime", System.currentTimeMillis());
}
}

View File

@@ -47,15 +47,15 @@ public class DataGraphNamespaceHandler extends NamespaceHandlerSupport {
@Override
protected void postProcessBeanDefinition(DataGraphRepositoryConfiguration context, BeanDefinitionBuilder builder, BeanDefinitionRegistry registry, Object beanSource) {
builder.addPropertyReference("graphDatabaseContext", context.getGraphDatabaseContextRef());
builder.addPropertyReference("neo4jTemplate", context.getNeo4jTemplateRef());
}
public interface DataGraphRepositoryConfiguration extends SingleRepositoryConfigInformation<SimpleDataGraphRepositoryConfiguration> {
String GRAPH_DATABASE_CONTEXT_REF = "graph-database-context-ref";
String DEFAULT_GRAPH_DATABASE_CONTEXT_REF = "graphDatabaseContext";
String NEO4J_TEMPLATE_REF = "neo4j-template-ref";
String DEFAULT_NEO4J_TEMPLATE_REF = "neo4jTemplate";
String getGraphDatabaseContextRef();
String getNeo4jTemplateRef();
}
public static class SimpleDataGraphRepositoryConfiguration extends RepositoryConfig<DataGraphRepositoryConfiguration, SimpleDataGraphRepositoryConfiguration> {
@@ -84,10 +84,10 @@ public class DataGraphNamespaceHandler extends NamespaceHandlerSupport {
return CRUDRepository.class;
}
public String getGraphDatabaseContextRef() {
public String getNeo4jTemplateRef() {
String contextRef = getSource().getAttribute(DataGraphRepositoryConfiguration.GRAPH_DATABASE_CONTEXT_REF);
return StringUtils.hasText(contextRef) ? contextRef : DataGraphRepositoryConfiguration.DEFAULT_GRAPH_DATABASE_CONTEXT_REF;
String contextRef = getSource().getAttribute(DataGraphRepositoryConfiguration.NEO4J_TEMPLATE_REF);
return StringUtils.hasText(contextRef) ? contextRef : DataGraphRepositoryConfiguration.DEFAULT_NEO4J_TEMPLATE_REF;
}
private static class ManualDataGraphRepositoryConfiguration extends ManualRepositoryConfigInformation<SimpleDataGraphRepositoryConfiguration> implements DataGraphRepositoryConfiguration {
@@ -97,8 +97,8 @@ public class DataGraphNamespaceHandler extends NamespaceHandlerSupport {
}
@Override
public String getGraphDatabaseContextRef() {
return getAttribute(DataGraphRepositoryConfiguration.GRAPH_DATABASE_CONTEXT_REF);
public String getNeo4jTemplateRef() {
return getAttribute(DataGraphRepositoryConfiguration.NEO4J_TEMPLATE_REF);
}
}
@@ -109,8 +109,8 @@ public class DataGraphNamespaceHandler extends NamespaceHandlerSupport {
}
@Override
public String getGraphDatabaseContextRef() {
return getParent().getGraphDatabaseContextRef();
public String getNeo4jTemplateRef() {
return getParent().getNeo4jTemplateRef();
}
}
}

View File

@@ -40,7 +40,7 @@ import org.springframework.data.neo4j.mapping.*;
import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
import org.springframework.data.neo4j.support.EntityInstantiator;
import org.springframework.data.neo4j.support.EntityStateHandler;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.NodeEntityInstantiator;
import org.springframework.data.neo4j.support.node.NodeEntityStateFactory;
import org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator;
@@ -80,29 +80,29 @@ public abstract class Neo4jConfiguration {
}
@Bean
public GraphDatabaseContext graphDatabaseContext() throws Exception {
public Neo4jTemplate neo4jTemplate() throws Exception {
GraphDatabaseContext gdc = new GraphDatabaseContext();
gdc.setGraphDatabaseService(getGraphDatabaseService());
gdc.setConversionService(conversionService());
gdc.setMappingContext(mappingContext());
gdc.setEntityStateHandler(entityStateHandler());
Neo4jTemplate neo4jTemplate = new Neo4jTemplate();
neo4jTemplate.setGraphDatabaseService(getGraphDatabaseService());
neo4jTemplate.setConversionService(conversionService());
neo4jTemplate.setMappingContext(mappingContext());
neo4jTemplate.setEntityStateHandler(entityStateHandler());
gdc.setNodeEntityStateFactory(nodeEntityStateFactory());
gdc.setNodeTypeRepresentationStrategy(nodeTypeRepresentationStrategy());
gdc.setNodeEntityInstantiator(graphEntityInstantiator());
neo4jTemplate.setNodeEntityStateFactory(nodeEntityStateFactory());
neo4jTemplate.setNodeTypeRepresentationStrategy(nodeTypeRepresentationStrategy());
neo4jTemplate.setNodeEntityInstantiator(graphEntityInstantiator());
gdc.setRelationshipEntityStateFactory(relationshipEntityStateFactory());
gdc.setRelationshipTypeRepresentationStrategy(relationshipTypeRepresentationStrategy());
gdc.setRelationshipEntityInstantiator(graphRelationshipInstantiator());
neo4jTemplate.setRelationshipEntityStateFactory(relationshipEntityStateFactory());
neo4jTemplate.setRelationshipTypeRepresentationStrategy(relationshipTypeRepresentationStrategy());
neo4jTemplate.setRelationshipEntityInstantiator(graphRelationshipInstantiator());
gdc.setTransactionManager(neo4jTransactionManager());
gdc.setGraphDatabase(graphDatabase());
neo4jTemplate.setTransactionManager(neo4jTransactionManager());
neo4jTemplate.setGraphDatabase(graphDatabase());
if (validator!=null) {
gdc.setValidator(validator);
neo4jTemplate.setValidator(validator);
}
return gdc;
return neo4jTemplate;
}
@Bean
@@ -122,7 +122,7 @@ public abstract class Neo4jConfiguration {
@Bean
public EntityStateHandler entityStateHandler() {
return new EntityStateHandler(mappingContext(),graphDatabaseService);
return new EntityStateHandler(mappingContext(),graphDatabase());
}
@@ -181,12 +181,12 @@ public abstract class Neo4jConfiguration {
@PostConstruct
public void wireEntityStateFactories() throws Exception {
final NodeEntityStateFactory nodeEntityStateFactory = nodeEntityStateFactory();
nodeEntityStateFactory.setGraphDatabaseContext(graphDatabaseContext());
nodeEntityStateFactory.setTemplate(neo4jTemplate());
nodeEntityStateFactory.setMappingContext(mappingContext());
nodeEntityStateFactory.setNodeDelegatingFieldAccessorFactory(nodeDelegatingFieldAccessorFactory());
final RelationshipEntityStateFactory relationshipEntityStateFactory = relationshipEntityStateFactory();
relationshipEntityStateFactory.setGraphDatabaseContext(graphDatabaseContext());
relationshipEntityStateFactory.setTemplate(neo4jTemplate());
relationshipEntityStateFactory.setMappingContext(mappingContext());
relationshipEntityStateFactory.setRelationshipDelegatingFieldAccessorFactory(relationshipDelegatingFieldAccessorFactory());
@@ -194,12 +194,12 @@ public abstract class Neo4jConfiguration {
@Bean
public DelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory() throws Exception {
return new NodeDelegatingFieldAccessorFactory(graphDatabaseContext());
return new NodeDelegatingFieldAccessorFactory(neo4jTemplate());
}
@Bean
public DelegatingFieldAccessorFactory relationshipDelegatingFieldAccessorFactory() throws Exception {
return new RelationshipDelegatingFieldAccessorFactory(graphDatabaseContext());
return new RelationshipDelegatingFieldAccessorFactory(neo4jTemplate());
}
@Bean(name = {"neo4jTransactionManager","transactionManager"})
@@ -229,7 +229,7 @@ public abstract class Neo4jConfiguration {
@Bean
public ConfigurationCheck configurationCheck() throws Exception {
return new ConfigurationCheck(graphDatabaseContext(),neo4jTransactionManager());
return new ConfigurationCheck(neo4jTemplate(),neo4jTransactionManager());
}
@Bean

View File

@@ -21,7 +21,7 @@ import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.helpers.collection.IterableWrapper;
import org.springframework.data.neo4j.core.EntityPath;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.path.EntityPathPathIterableWrapper;
/**
@@ -30,9 +30,9 @@ import org.springframework.data.neo4j.support.path.EntityPathPathIterableWrapper
*/ // todo integrate in result conversion handling
public class TraverserConverter<T> {
private final GraphDatabaseContext ctx;
private final Neo4jTemplate ctx;
public TraverserConverter(GraphDatabaseContext ctx) {
public TraverserConverter(Neo4jTemplate ctx) {
this.ctx = ctx;
}

View File

@@ -105,4 +105,10 @@ public interface GraphDatabase {
void setConversionService(ConversionService conversionService);
<T> QueryEngine<T> queryEngineFor(QueryType type, ResultConverter resultConverter);
boolean transactionIsRunning();
void remove(Node node);
void remove(Relationship relationship);
}

View File

@@ -20,7 +20,7 @@ import org.neo4j.graphdb.*;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.util.Assert;
import java.util.HashSet;
@@ -35,11 +35,11 @@ public abstract class AbstractNodeRelationshipFieldAccessor<STATE extends Proper
protected final Neo4jPersistentProperty property;
protected final Direction direction;
protected final Class<?> relatedType;
protected final GraphDatabaseContext graphDatabaseContext;
protected final Neo4jTemplate template;
public AbstractNodeRelationshipFieldAccessor(Class<?> clazz, GraphDatabaseContext graphDatabaseContext, Direction direction, RelationshipType type, Neo4jPersistentProperty property) {
public AbstractNodeRelationshipFieldAccessor(Class<?> clazz, Neo4jTemplate template, Direction direction, RelationshipType type, Neo4jPersistentProperty property) {
this.relatedType = clazz;
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
this.direction = direction;
this.type = type;
this.property = property;
@@ -89,21 +89,21 @@ public abstract class AbstractNodeRelationshipFieldAccessor<STATE extends Proper
protected STATE getOrCreateState(Object value) {
final STATE state = getState(value);
if (state != null) return state;
final Object saved = graphDatabaseContext.save(value);
final Object saved = template.save(value);
final STATE newState = getState(saved);
Assert.notNull(newState);
return newState;
}
protected <T> ManagedFieldAccessorSet<T> createManagedSet(Object entity, Set<T> result) {
return new ManagedFieldAccessorSet<T>(entity, result, property,graphDatabaseContext,this);
return new ManagedFieldAccessorSet<T>(entity, result, property, template,this);
}
protected Set<Object> createEntitySetFromRelationshipEndNodes(Object entity) {
final Iterable<TSTATE> nodes = getStatesFromEntity(entity);
final Set<Object> result = new HashSet<Object>();
for (final TSTATE otherNode : nodes) {
Object target=graphDatabaseContext.createEntityFromState(otherNode, relatedType);
Object target= template.createEntityFromState(otherNode, relatedType);
result.add(target);
}
return result;

View File

@@ -20,7 +20,7 @@ import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
/**
* @author Michael Hunger
@@ -30,14 +30,14 @@ import org.springframework.data.neo4j.support.GraphDatabaseContext;
public class ConvertingNodePropertyFieldAccessorFactory implements FieldAccessorFactory {
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public ConvertingNodePropertyFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public ConvertingNodePropertyFieldAccessorFactory(Neo4jTemplate template) {
this.template = template;
}
private ConversionService getConversionService() {
return graphDatabaseContext.getConversionService();
return template.getConversionService();
}
@@ -49,13 +49,13 @@ public class ConvertingNodePropertyFieldAccessorFactory implements FieldAccessor
@Override
public FieldAccessor forField(final Neo4jPersistentProperty property) {
return new ConvertingNodePropertyFieldAccessor(property,graphDatabaseContext);
return new ConvertingNodePropertyFieldAccessor(property, template);
}
public static class ConvertingNodePropertyFieldAccessor extends PropertyFieldAccessorFactory.PropertyFieldAccessor {
public ConvertingNodePropertyFieldAccessor(Neo4jPersistentProperty property, GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext, property);
public ConvertingNodePropertyFieldAccessor(Neo4jPersistentProperty property, Neo4jTemplate template) {
super(template, property);
}
@Override
@@ -70,11 +70,11 @@ public class ConvertingNodePropertyFieldAccessorFactory implements FieldAccessor
}
private Object serializePropertyValue(final Object newVal) {
return graphDatabaseContext.getConversionService().convert(newVal, String.class);
return template.getConversionService().convert(newVal, String.class);
}
private Object deserializePropertyValue(final Object value) {
return graphDatabaseContext.getConversionService().convert(value, fieldType);
return template.getConversionService().convert(value, fieldType);
}
}

View File

@@ -23,7 +23,7 @@ import org.springframework.data.mapping.AssociationHandler;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.util.TypeInformation;
import java.util.*;
@@ -33,21 +33,21 @@ public abstract class DelegatingFieldAccessorFactory implements FieldAccessorFac
private final static Log log = LogFactory.getLog(DelegatingFieldAccessorFactory.class);
protected final GraphDatabaseContext graphDatabaseContext;
protected final Neo4jTemplate template;
protected abstract Collection<FieldAccessorListenerFactory> createListenerFactories();
protected abstract Collection<? extends FieldAccessorFactory> createAccessorFactories();
public DelegatingFieldAccessorFactory(final GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public DelegatingFieldAccessorFactory(final Neo4jTemplate template) {
this.template = template;
this.fieldAccessorFactories.addAll(createAccessorFactories());
this.fieldAccessorListenerFactories.addAll(createListenerFactories());
}
public GraphDatabaseContext getGraphDatabaseContext() {
return graphDatabaseContext;
public Neo4jTemplate getTemplate() {
return template;
}
@Override
@@ -106,7 +106,7 @@ public abstract class DelegatingFieldAccessorFactory implements FieldAccessorFac
final TypeInformation<?> typeInformation = type.getTypeInformation();
final FieldAccessorFactoryProviders<T> fieldAccessorFactoryProviders = accessorFactoryProviderCache.get(typeInformation);
if (fieldAccessorFactoryProviders != null) return fieldAccessorFactoryProviders;
final FieldAccessorFactoryProviders<T> newFieldAccessorFactories = new FieldAccessorFactoryProviders<T>(typeInformation,graphDatabaseContext);
final FieldAccessorFactoryProviders<T> newFieldAccessorFactories = new FieldAccessorFactoryProviders<T>(typeInformation, template);
type.doWithProperties(new PropertyHandler<Neo4jPersistentProperty>() {
@Override
public void doWithPersistentProperty(Neo4jPersistentProperty property) {

View File

@@ -22,7 +22,7 @@ import org.neo4j.graphdb.Transaction;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.util.ObjectUtils;
import java.lang.reflect.Field;
@@ -40,13 +40,13 @@ public class DetachedEntityState<STATE> implements EntityState<STATE> {
private final Map<Field, ExistingValue> dirty = new HashMap<Field, ExistingValue>();
protected final EntityState<STATE> delegate;
private final static Log log = LogFactory.getLog(DetachedEntityState.class);
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
private Neo4jPersistentEntity<?> persistentEntity;
public DetachedEntityState(final EntityState<STATE> delegate, GraphDatabaseContext graphDatabaseContext) {
public DetachedEntityState(final EntityState<STATE> delegate, Neo4jTemplate template) {
this.delegate = delegate;
this.persistentEntity = delegate.getPersistentEntity();
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
}
@Override
@@ -77,7 +77,7 @@ public class DetachedEntityState<STATE> implements EntityState<STATE> {
@Override
public Object getValue(final Field field) {
if (isDetached()) {
if (graphDatabaseContext.getPersistentState(getEntity())==null || isDirty(field)) {
if (template.getPersistentState(getEntity())==null || isDirty(field)) {
if (log.isDebugEnabled()) log.debug("Outside of transaction, GET value from field " + field);
Object entityValue = getValueFromEntity(field);
if (entityValue != null) {
@@ -108,7 +108,7 @@ public class DetachedEntityState<STATE> implements EntityState<STATE> {
}
protected boolean transactionIsRunning() {
return getGraphDatabaseContext().transactionIsRunning();
return getTemplate().transactionIsRunning();
}
static class ExistingValue {
@@ -170,7 +170,7 @@ public class DetachedEntityState<STATE> implements EntityState<STATE> {
@SuppressWarnings("deprecation")
@Override
public void createAndAssignState() {
if (graphDatabaseContext.transactionIsRunning()) {
if (template.transactionIsRunning()) {
delegate.createAndAssignState();
} else {
log.warn("New Nodebacked created outside of transaction " + delegate.getEntity().getClass());
@@ -263,15 +263,15 @@ public class DetachedEntityState<STATE> implements EntityState<STATE> {
}
public GraphDatabaseContext getGraphDatabaseContext() {
return graphDatabaseContext;
public Neo4jTemplate getTemplate() {
return template;
}
// todo always create an transaction for persist, atomic operation when no outside tx exists
@Override
public Object persist() {
if (!isDetached()) return getEntity();
Transaction tx = graphDatabaseContext.beginTx();
Transaction tx = template.beginTx();
try {
Object result = delegate.persist();

View File

@@ -20,11 +20,10 @@ 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.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.DoReturn;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
/**
* This accessor factory creates {@link DynamicPropertiesFieldAccessor}s for @NodeEntity properties of type
@@ -32,10 +31,10 @@ import org.springframework.data.neo4j.support.GraphDatabaseContext;
*/
public class DynamicPropertiesFieldAccessorFactory implements FieldAccessorFactory {
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public DynamicPropertiesFieldAccessorFactory(final GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public DynamicPropertiesFieldAccessorFactory(final Neo4jTemplate template) {
this.template = template;
}
@Override
@@ -45,24 +44,24 @@ public class DynamicPropertiesFieldAccessorFactory implements FieldAccessorFacto
@Override
public FieldAccessor forField(Neo4jPersistentProperty field) {
return new DynamicPropertiesFieldAccessor(graphDatabaseContext,
return new DynamicPropertiesFieldAccessor(template,
field.getNeo4jPropertyName(), field);
}
public static class DynamicPropertiesFieldAccessor implements FieldAccessor {
private final String propertyNamePrefix;
private final Neo4jPersistentProperty field;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public DynamicPropertiesFieldAccessor(GraphDatabaseContext graphDatabaseContext, String propertyName, Neo4jPersistentProperty field) {
this.graphDatabaseContext = graphDatabaseContext;
public DynamicPropertiesFieldAccessor(Neo4jTemplate template, String propertyName, Neo4jPersistentProperty field) {
this.template = template;
this.propertyNamePrefix = propertyName;
this.field = field;
}
@Override
public Object setValue(final Object entity, final Object newVal) {
final PropertyContainer propertyContainer = graphDatabaseContext.getPersistentState(entity);
final PropertyContainer propertyContainer = template.getPersistentState(entity);
PrefixedDynamicProperties dynamicProperties;
if (newVal instanceof ManagedPrefixedDynamicProperties) {
// newVal is already a managed container
@@ -108,8 +107,8 @@ public class DynamicPropertiesFieldAccessorFactory implements FieldAccessorFacto
@Override
public Object getValue(final Object entity) {
PropertyContainer element = graphDatabaseContext.getPersistentState(entity);
ManagedPrefixedDynamicProperties props = ManagedPrefixedDynamicProperties.create(propertyNamePrefix, field, entity,graphDatabaseContext,this);
PropertyContainer element = template.getPersistentState(entity);
ManagedPrefixedDynamicProperties props = ManagedPrefixedDynamicProperties.create(propertyNamePrefix, field, entity, template,this);
for (String key : element.getPropertyKeys()) {
props.setPropertyIfPrefixed(key, element.getProperty(key));
}

View File

@@ -17,7 +17,7 @@
package org.springframework.data.neo4j.fieldaccess;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.util.TypeInformation;
import java.util.ArrayList;
@@ -67,9 +67,9 @@ public class FieldAccessorFactoryProviders<T> {
private final IdFieldAccessorFactory idFieldAccessorFactory;
private Neo4jPersistentProperty idProperty;
FieldAccessorFactoryProviders(TypeInformation<?> type, GraphDatabaseContext graphDatabaseContext) {
FieldAccessorFactoryProviders(TypeInformation<?> type, Neo4jTemplate template) {
this.type = type;
idFieldAccessorFactory= new IdFieldAccessorFactory(graphDatabaseContext);
idFieldAccessorFactory= new IdFieldAccessorFactory(template);
}
public Map<Neo4jPersistentProperty, FieldAccessor> getFieldAccessors() {

View File

@@ -17,7 +17,7 @@ package org.springframework.data.neo4j.fieldaccess;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.helpers.collection.IterableWrapper;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
/**
* Simple wrapper to create an Iterable over @NodeEntities or @RelationshipEntities from an iterable over Nodes or Relationships.
@@ -25,21 +25,21 @@ import org.springframework.data.neo4j.support.GraphDatabaseContext;
*/
public class GraphBackedEntityIterableWrapper<STATE extends PropertyContainer, ENTITY> extends IterableWrapper<ENTITY, STATE> {
private final Class<ENTITY> targetType;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public GraphBackedEntityIterableWrapper(Iterable<STATE> iterable, Class<ENTITY> targetType, final GraphDatabaseContext graphDatabaseContext) {
public GraphBackedEntityIterableWrapper(Iterable<STATE> iterable, Class<ENTITY> targetType, final Neo4jTemplate template) {
super(iterable);
this.targetType = targetType;
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
}
@Override
protected ENTITY underlyingObjectToObject(STATE s) {
return graphDatabaseContext.createEntityFromState(s, targetType);
return template.createEntityFromState(s, targetType);
}
public static <S extends PropertyContainer, E> GraphBackedEntityIterableWrapper<S, E> create(
Iterable<S> iterable, Class<E> targetType, final GraphDatabaseContext graphDatabaseContext) {
return new GraphBackedEntityIterableWrapper<S, E>(iterable, targetType, graphDatabaseContext);
Iterable<S> iterable, Class<E> targetType, final Neo4jTemplate template) {
return new GraphBackedEntityIterableWrapper<S, E>(iterable, targetType, template);
}
}

View File

@@ -22,7 +22,7 @@ import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.Relationship;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import static org.springframework.data.neo4j.support.DoReturn.doReturn;
@@ -31,10 +31,10 @@ import static org.springframework.data.neo4j.support.DoReturn.doReturn;
* @since 12.09.2010
*/
public class IdFieldAccessorFactory implements FieldAccessorFactory {
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public IdFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public IdFieldAccessorFactory(Neo4jTemplate template) {
this.template = template;
}
@Override
@@ -44,16 +44,16 @@ public class IdFieldAccessorFactory implements FieldAccessorFactory {
@Override
public FieldAccessor forField(final Neo4jPersistentProperty property) {
return new IdFieldAccessor(property,graphDatabaseContext);
return new IdFieldAccessor(property, template);
}
public static class IdFieldAccessor implements FieldAccessor {
protected final Neo4jPersistentProperty property;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public IdFieldAccessor(final Neo4jPersistentProperty property, GraphDatabaseContext graphDatabaseContext) {
public IdFieldAccessor(final Neo4jPersistentProperty property, Neo4jTemplate template) {
this.property = property;
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
}
@Override
@@ -68,7 +68,7 @@ public class IdFieldAccessorFactory implements FieldAccessorFactory {
@Override
public Object getValue(final Object entity) {
final PropertyContainer state = graphDatabaseContext.getPersistentState(entity);
final PropertyContainer state = template.getPersistentState(entity);
if (state instanceof Node) {
return doReturn(((Node)state).getId());
}

View File

@@ -24,7 +24,7 @@ import org.neo4j.index.lucene.ValueContext;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.lang.reflect.AnnotatedElement;
@@ -34,11 +34,11 @@ public class IndexingPropertyFieldAccessorListenerFactory<S extends PropertyCont
private final PropertyFieldAccessorFactory propertyFieldAccessorFactory;
private final ConvertingNodePropertyFieldAccessorFactory convertingNodePropertyFieldAccessorFactory;
private final IndexProvider indexProvider;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public IndexingPropertyFieldAccessorListenerFactory(final GraphDatabaseContext graphDatabaseContext, final PropertyFieldAccessorFactory propertyFieldAccessorFactory, final ConvertingNodePropertyFieldAccessorFactory convertingNodePropertyFieldAccessorFactory) {
this.graphDatabaseContext = graphDatabaseContext;
indexProvider = new IndexProvider<S,T>(graphDatabaseContext);
public IndexingPropertyFieldAccessorListenerFactory(final Neo4jTemplate template, final PropertyFieldAccessorFactory propertyFieldAccessorFactory, final ConvertingNodePropertyFieldAccessorFactory convertingNodePropertyFieldAccessorFactory) {
this.template = template;
indexProvider = new IndexProvider<S,T>(template);
this.propertyFieldAccessorFactory = propertyFieldAccessorFactory;
this.convertingNodePropertyFieldAccessorFactory = convertingNodePropertyFieldAccessorFactory;
}
@@ -55,15 +55,15 @@ public class IndexingPropertyFieldAccessorListenerFactory<S extends PropertyCont
@Override
public FieldAccessListener forField(Neo4jPersistentProperty property) {
return new IndexingPropertyFieldAccessorListener(property, indexProvider,graphDatabaseContext);
return new IndexingPropertyFieldAccessorListener(property, indexProvider, template);
}
public static class IndexProvider<S extends PropertyContainer, T> {
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public IndexProvider(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public IndexProvider(Neo4jTemplate template) {
this.template = template;
}
private String getIndexKey(Neo4jPersistentProperty property) {
@@ -82,12 +82,12 @@ public class IndexingPropertyFieldAccessorListenerFactory<S extends PropertyCont
final String providedIndexName = indexedAnnotation.indexName().isEmpty() ? null : indexedAnnotation.indexName();
String indexName = Indexed.Name.get(indexedAnnotation.level(), type, providedIndexName, instance.getClass());
if (!property.getIndexInfo().isFulltext()) {
return graphDatabaseContext.getIndex(type, indexName, false);
return template.getIndex(type, indexName, false);
}
if (providedIndexName == null) throw new IllegalStateException("@Indexed(fullext=true) on "+property+" requires an providedIndexName too ");
String defaultIndexName = Indexed.Name.get(indexedAnnotation.level(), type, null, instance.getClass());
if (providedIndexName.equals(defaultIndexName)) throw new IllegalStateException("Full-index name for "+property+" must differ from the default name: "+defaultIndexName);
return graphDatabaseContext.getIndex(type, indexName, true);
return template.getIndex(type, indexName, true);
}
}
@@ -102,12 +102,12 @@ public class IndexingPropertyFieldAccessorListenerFactory<S extends PropertyCont
protected final String indexKey;
private final Neo4jPersistentProperty property;
private final IndexProvider indexProvider;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public IndexingPropertyFieldAccessorListener(final Neo4jPersistentProperty property, IndexProvider indexProvider, GraphDatabaseContext graphDatabaseContext) {
public IndexingPropertyFieldAccessorListener(final Neo4jPersistentProperty property, IndexProvider indexProvider, Neo4jTemplate template) {
this.property = property;
this.indexProvider = indexProvider;
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
indexKey = indexProvider.getIndexKey(property);
}
@@ -116,7 +116,7 @@ public class IndexingPropertyFieldAccessorListenerFactory<S extends PropertyCont
@SuppressWarnings("unchecked") Index<T> index = indexProvider.getIndex(property, entity);
if (newVal instanceof Number) newVal = ValueContext.numeric((Number) newVal);
final T state = graphDatabaseContext.getPersistentState(entity);
final T state = template.getPersistentState(entity);
index.remove(state, indexKey);
if (newVal != null) {
index.add(state, indexKey, newVal);

View File

@@ -19,7 +19,7 @@ package org.springframework.data.neo4j.fieldaccess;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.DoReturn;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.ManagedEntity;
import java.util.AbstractSet;
@@ -34,11 +34,11 @@ public class ManagedFieldAccessorSet<T> extends AbstractSet<T> {
private final Object entity;
final Set<T> delegate;
private final Neo4jPersistentProperty property;
private final GraphDatabaseContext ctx;
private final Neo4jTemplate ctx;
private final FieldAccessor fieldAccessor;
@SuppressWarnings("unchecked")
public ManagedFieldAccessorSet(final Object entity, final Object newVal, final Neo4jPersistentProperty property, GraphDatabaseContext ctx, FieldAccessor fieldAccessor) {
public ManagedFieldAccessorSet(final Object entity, final Object newVal, final Neo4jPersistentProperty property, Neo4jTemplate ctx, FieldAccessor fieldAccessor) {
this.entity = entity;
this.property = property;
this.ctx = ctx;

View File

@@ -18,7 +18,7 @@ package org.springframework.data.neo4j.fieldaccess;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.DoReturn;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.ManagedEntity;
import java.util.Map;
@@ -29,26 +29,26 @@ import java.util.Map;
*/
public class ManagedPrefixedDynamicProperties extends PrefixedDynamicProperties {
private final Object entity;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
private final FieldAccessor fieldAccessor;
private final Neo4jPersistentProperty property;
private boolean isNode;
public ManagedPrefixedDynamicProperties(String prefix, final Neo4jPersistentProperty property, final Object entity, GraphDatabaseContext graphDatabaseContext, FieldAccessor fieldAccessor) {
this(prefix,10,property,entity,graphDatabaseContext,fieldAccessor);
public ManagedPrefixedDynamicProperties(String prefix, final Neo4jPersistentProperty property, final Object entity, Neo4jTemplate template, FieldAccessor fieldAccessor) {
this(prefix,10,property,entity, template,fieldAccessor);
}
public ManagedPrefixedDynamicProperties(String prefix, int initialCapacity, final Neo4jPersistentProperty property, final Object entity, GraphDatabaseContext graphDatabaseContext, FieldAccessor fieldAccessor) {
public ManagedPrefixedDynamicProperties(String prefix, int initialCapacity, final Neo4jPersistentProperty property, final Object entity, Neo4jTemplate template, FieldAccessor fieldAccessor) {
super(prefix, initialCapacity);
this.property = property;
this.entity = entity;
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
this.fieldAccessor = fieldAccessor;
this.isNode = property.getOwner().isNodeEntity();
}
public static ManagedPrefixedDynamicProperties create(String prefix, final Neo4jPersistentProperty property, final Object entity, GraphDatabaseContext graphDatabaseContext, FieldAccessor fieldAccessor) {
return new ManagedPrefixedDynamicProperties(prefix, property, entity,graphDatabaseContext,fieldAccessor);
public static ManagedPrefixedDynamicProperties create(String prefix, final Neo4jPersistentProperty property, final Object entity, Neo4jTemplate template, FieldAccessor fieldAccessor) {
return new ManagedPrefixedDynamicProperties(prefix, property, entity, template,fieldAccessor);
}
@Override
@@ -72,7 +72,7 @@ public class ManagedPrefixedDynamicProperties extends PrefixedDynamicProperties
@Override
public DynamicProperties createFrom(Map<String, Object> map) {
DynamicProperties d = new ManagedPrefixedDynamicProperties(prefix, map.size(), property, entity,graphDatabaseContext,fieldAccessor);
DynamicProperties d = new ManagedPrefixedDynamicProperties(prefix, map.size(), property, entity, template,fieldAccessor);
d.setPropertiesFrom(map);
return d;
}
@@ -86,7 +86,7 @@ public class ManagedPrefixedDynamicProperties extends PrefixedDynamicProperties
}
private void update() {
if (graphDatabaseContext.isManaged(entity)) {
if (template.isManaged(entity)) {
updateValueWithState(((ManagedEntity)entity).getEntityState());
} else {
updateValue();

View File

@@ -17,7 +17,7 @@
package org.springframework.data.neo4j.fieldaccess;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.util.Arrays;
import java.util.Collection;
@@ -28,35 +28,35 @@ import java.util.Collection;
*/
public class NodeDelegatingFieldAccessorFactory extends DelegatingFieldAccessorFactory {
public NodeDelegatingFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext);
public NodeDelegatingFieldAccessorFactory(Neo4jTemplate template) {
super(template);
}
@Override
protected Collection<FieldAccessorListenerFactory> createListenerFactories() {
return Arrays.<FieldAccessorListenerFactory>asList(
new IndexingPropertyFieldAccessorListenerFactory(
graphDatabaseContext,
new PropertyFieldAccessorFactory(graphDatabaseContext),
new ConvertingNodePropertyFieldAccessorFactory(graphDatabaseContext)),
new ValidatingNodePropertyFieldAccessorListenerFactory(graphDatabaseContext)
template,
new PropertyFieldAccessorFactory(template),
new ConvertingNodePropertyFieldAccessorFactory(template)),
new ValidatingNodePropertyFieldAccessorListenerFactory(template)
);
}
@Override
protected Collection<? extends FieldAccessorFactory> createAccessorFactories() {
return Arrays.<FieldAccessorFactory>asList(
new IdFieldAccessorFactory(graphDatabaseContext),
new IdFieldAccessorFactory(template),
new TransientFieldAccessorFactory(),
new TraversalFieldAccessorFactory(graphDatabaseContext),
new QueryFieldAccessorFactory(graphDatabaseContext),
new PropertyFieldAccessorFactory(graphDatabaseContext),
new ConvertingNodePropertyFieldAccessorFactory(graphDatabaseContext),
new SingleRelationshipFieldAccessorFactory(graphDatabaseContext),
new OneToNRelationshipFieldAccessorFactory(graphDatabaseContext),
new ReadOnlyOneToNRelationshipFieldAccessorFactory(graphDatabaseContext),
new OneToNRelationshipEntityFieldAccessorFactory(graphDatabaseContext),
new DynamicPropertiesFieldAccessorFactory(graphDatabaseContext)
new TraversalFieldAccessorFactory(template),
new QueryFieldAccessorFactory(template),
new PropertyFieldAccessorFactory(template),
new ConvertingNodePropertyFieldAccessorFactory(template),
new SingleRelationshipFieldAccessorFactory(template),
new OneToNRelationshipFieldAccessorFactory(template),
new ReadOnlyOneToNRelationshipFieldAccessorFactory(template),
new OneToNRelationshipEntityFieldAccessorFactory(template),
new DynamicPropertiesFieldAccessorFactory(template)
);
}
}

View File

@@ -16,7 +16,7 @@
package org.springframework.data.neo4j.fieldaccess;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
/**
* @author Michael Hunger
@@ -24,10 +24,10 @@ import org.springframework.data.neo4j.support.GraphDatabaseContext;
*/
public abstract class NodeRelationshipFieldAccessorFactory implements FieldAccessorFactory {
protected GraphDatabaseContext graphDatabaseContext;
protected Neo4jTemplate template;
public NodeRelationshipFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public NodeRelationshipFieldAccessorFactory(Neo4jTemplate template) {
this.template = template;
}
}

View File

@@ -21,7 +21,7 @@ import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.util.HashSet;
import java.util.Set;
@@ -31,8 +31,8 @@ import java.util.Set;
* @since 12.09.2010
*/
public abstract class NodeToNodesRelationshipFieldAccessor extends AbstractNodeRelationshipFieldAccessor<Node, Node> {
public NodeToNodesRelationshipFieldAccessor(final Class<?> clazz, final GraphDatabaseContext graphDatabaseContext, final Direction direction, final RelationshipType type, Neo4jPersistentProperty property) {
super(clazz, graphDatabaseContext, direction, type,property);
public NodeToNodesRelationshipFieldAccessor(final Class<?> clazz, final Neo4jTemplate template, final Direction direction, final RelationshipType type, Neo4jPersistentProperty property) {
super(clazz, template, direction, type,property);
}
@Override
@@ -56,7 +56,7 @@ public abstract class NodeToNodesRelationshipFieldAccessor extends AbstractNodeR
@Override
protected Node getState(final Object entity) {
return graphDatabaseContext.getPersistentState(entity);
return template.getPersistentState(entity);
}
}

View File

@@ -23,18 +23,18 @@ import org.neo4j.graphdb.RelationshipType;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.mapping.RelationshipInfo;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import static org.springframework.data.neo4j.support.DoReturn.doReturn;
public class OneToNRelationshipEntityFieldAccessorFactory implements FieldAccessorFactory {
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
public OneToNRelationshipEntityFieldAccessorFactory(
GraphDatabaseContext graphDatabaseContext) {
Neo4jTemplate template) {
super();
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
}
@Override
@@ -45,12 +45,12 @@ public class OneToNRelationshipEntityFieldAccessorFactory implements FieldAccess
@Override
public FieldAccessor forField(final Neo4jPersistentProperty property) {
final RelationshipInfo relationshipInfo = property.getRelationshipInfo();
return new OneToNRelationshipEntityFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), (Class<?>) relationshipInfo.getTargetType().getType(), graphDatabaseContext,property);
return new OneToNRelationshipEntityFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), (Class<?>) relationshipInfo.getTargetType().getType(), template,property);
}
public static class OneToNRelationshipEntityFieldAccessor extends AbstractNodeRelationshipFieldAccessor<Node, Relationship> {
public OneToNRelationshipEntityFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> elementClass, final GraphDatabaseContext graphDatabaseContext, Neo4jPersistentProperty property) {
super(elementClass, graphDatabaseContext, direction, type, property);
public OneToNRelationshipEntityFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> elementClass, final Neo4jTemplate template, Neo4jPersistentProperty property) {
super(elementClass, template, direction, type, property);
}
@Override
@@ -70,7 +70,7 @@ public class OneToNRelationshipEntityFieldAccessorFactory implements FieldAccess
}
private GraphBackedEntityIterableWrapper<Relationship, ?> iterableFrom(final Object entity) {
return GraphBackedEntityIterableWrapper.create(getStatesFromEntity(entity), relatedType, graphDatabaseContext);
return GraphBackedEntityIterableWrapper.create(getStatesFromEntity(entity), relatedType, template);
}
@Override
@@ -86,7 +86,7 @@ public class OneToNRelationshipEntityFieldAccessorFactory implements FieldAccess
@Override
protected Node getState(final Object entity) {
return graphDatabaseContext.getPersistentState(entity);
return template.getPersistentState(entity);
}
}

View File

@@ -21,7 +21,7 @@ import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.RelationshipType;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.mapping.RelationshipInfo;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.util.HashSet;
import java.util.Set;
@@ -30,8 +30,8 @@ import static org.springframework.data.neo4j.support.DoReturn.doReturn;
public class OneToNRelationshipFieldAccessorFactory extends NodeRelationshipFieldAccessorFactory {
public OneToNRelationshipFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext);
public OneToNRelationshipFieldAccessorFactory(Neo4jTemplate template) {
super(template);
}
@Override
@@ -45,13 +45,13 @@ public class OneToNRelationshipFieldAccessorFactory extends NodeRelationshipFiel
public FieldAccessor forField(final Neo4jPersistentProperty property) {
final RelationshipInfo relationshipInfo = property.getRelationshipInfo();
final Class<?> targetType = relationshipInfo.getTargetType().getType();
return new OneToNRelationshipFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), targetType, graphDatabaseContext,property);
return new OneToNRelationshipFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), targetType, template,property);
}
public static class OneToNRelationshipFieldAccessor extends NodeToNodesRelationshipFieldAccessor {
public OneToNRelationshipFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> elementClass, final GraphDatabaseContext graphDatabaseContext, Neo4jPersistentProperty property) {
super(elementClass, graphDatabaseContext, direction, type,property);
public OneToNRelationshipFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> elementClass, final Neo4jTemplate template, Neo4jPersistentProperty property) {
super(elementClass, template, direction, type,property);
}
public Object setValue(final Object entity, final Object newVal) {

View File

@@ -18,9 +18,8 @@ package org.springframework.data.neo4j.fieldaccess;
import org.neo4j.graphdb.PropertyContainer;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import static org.springframework.data.neo4j.support.DoReturn.doReturn;
@@ -30,10 +29,10 @@ import static org.springframework.data.neo4j.support.DoReturn.doReturn;
*/
public class PropertyFieldAccessorFactory implements FieldAccessorFactory {
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public PropertyFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public PropertyFieldAccessorFactory(Neo4jTemplate template) {
this.template = template;
}
@Override
@@ -43,17 +42,17 @@ public class PropertyFieldAccessorFactory implements FieldAccessorFactory {
@Override
public FieldAccessor forField(final Neo4jPersistentProperty field) {
return new PropertyFieldAccessor(graphDatabaseContext, field);
return new PropertyFieldAccessor(template, field);
}
public static class PropertyFieldAccessor implements FieldAccessor {
protected final GraphDatabaseContext graphDatabaseContext;
protected final Neo4jTemplate template;
protected final Neo4jPersistentProperty property;
protected final String propertyName;
protected final Class<?> fieldType;
public PropertyFieldAccessor(GraphDatabaseContext graphDatabaseContext, Neo4jPersistentProperty property) {
this.graphDatabaseContext = graphDatabaseContext;
public PropertyFieldAccessor(Neo4jTemplate template, Neo4jPersistentProperty property) {
this.template = template;
this.property = property;
this.propertyName = property.getNeo4jPropertyName();
this.fieldType = property.getType() ;
@@ -66,7 +65,7 @@ public class PropertyFieldAccessorFactory implements FieldAccessorFactory {
@Override
public Object setValue(final Object entity, final Object newVal) {
final PropertyContainer propertyContainer = graphDatabaseContext.getPersistentState(entity);
final PropertyContainer propertyContainer = template.getPersistentState(entity);
if (newVal==null) {
propertyContainer.removeProperty(propertyName);
} else {
@@ -81,12 +80,12 @@ public class PropertyFieldAccessorFactory implements FieldAccessorFactory {
}
protected Object doGetValue(final Object entity) {
PropertyContainer element = graphDatabaseContext.getPersistentState(entity);
PropertyContainer element = template.getPersistentState(entity);
if (element.hasProperty(propertyName)) {
Object value = element.getProperty(propertyName);
if (value == null || fieldType.isInstance(value)) return value;
if (graphDatabaseContext.getConversionService() !=null) {
return graphDatabaseContext.getConversionService().convert(value, fieldType);
if (template.getConversionService() !=null) {
return template.getConversionService().convert(value, fieldType);
}
return value;
}

View File

@@ -21,7 +21,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.util.HashMap;
import java.util.Map;
@@ -29,10 +29,10 @@ import java.util.Map;
import static org.springframework.data.neo4j.support.DoReturn.doReturn;
public class QueryFieldAccessorFactory implements FieldAccessorFactory {
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public QueryFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public QueryFieldAccessorFactory(Neo4jTemplate template) {
this.template = template;
}
@Override
@@ -44,7 +44,7 @@ public class QueryFieldAccessorFactory implements FieldAccessorFactory {
@Override
public FieldAccessor forField(final Neo4jPersistentProperty property) {
return new QueryFieldAccessor(property,graphDatabaseContext);
return new QueryFieldAccessor(property, template);
}
/**
@@ -53,15 +53,15 @@ public class QueryFieldAccessorFactory implements FieldAccessorFactory {
*/
public static class QueryFieldAccessor implements FieldAccessor {
protected final Neo4jPersistentProperty property;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
private final String query;
private Class<?> target;
protected String[] annotationParams;
private boolean iterableResult;
public QueryFieldAccessor(final Neo4jPersistentProperty property, GraphDatabaseContext graphDatabaseContext) {
public QueryFieldAccessor(final Neo4jPersistentProperty property, Neo4jTemplate template) {
this.property = property;
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
final Query query = property.getAnnotation(Query.class);
this.annotationParams = query.params();
if ((this.annotationParams.length % 2) != 0) {
@@ -93,12 +93,12 @@ public class QueryFieldAccessorFactory implements FieldAccessorFactory {
}
private Object executeQuery(Object entity, String queryString, Map<String, Object> params) {
return graphDatabaseContext.query(queryString, params, property.getTypeInformation());
return template.query(queryString, params, property.getTypeInformation());
}
private Map<String, Object> createPlaceholderParams(Object entity) {
Map<String,Object> params=new HashMap<String, Object>();
final Node startNode = graphDatabaseContext.<Node>getPersistentState(entity);
final Node startNode = template.<Node>getPersistentState(entity);
params.put("self", startNode.getId());
if (annotationParams.length==0) return params;
for (int i = 0; i < annotationParams.length; i+=2) {

View File

@@ -22,12 +22,12 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.mapping.RelationshipInfo;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
public class ReadOnlyOneToNRelationshipFieldAccessorFactory extends NodeRelationshipFieldAccessorFactory {
public ReadOnlyOneToNRelationshipFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext);
public ReadOnlyOneToNRelationshipFieldAccessorFactory(Neo4jTemplate template) {
super(template);
}
@Override
@@ -40,13 +40,13 @@ public class ReadOnlyOneToNRelationshipFieldAccessorFactory extends NodeRelation
@Override
public FieldAccessor forField(final Neo4jPersistentProperty property) {
final RelationshipInfo relationshipInfo = property.getRelationshipInfo();
return new ReadOnlyOneToNRelationshipFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), (Class<?>) property.getRelationshipInfo().getTargetType().getType(), graphDatabaseContext,property);
return new ReadOnlyOneToNRelationshipFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), (Class<?>) property.getRelationshipInfo().getTargetType().getType(), template,property);
}
public static class ReadOnlyOneToNRelationshipFieldAccessor extends OneToNRelationshipFieldAccessorFactory.OneToNRelationshipFieldAccessor {
public ReadOnlyOneToNRelationshipFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> elementClass, final GraphDatabaseContext graphDatabaseContext, Neo4jPersistentProperty field) {
super(type,direction,elementClass, graphDatabaseContext, field);
public ReadOnlyOneToNRelationshipFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> elementClass, final Neo4jTemplate template, Neo4jPersistentProperty field) {
super(type,direction,elementClass, template, field);
}
@Override

View File

@@ -20,20 +20,20 @@ import java.util.Collection;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
public class RelationshipDelegatingFieldAccessorFactory extends DelegatingFieldAccessorFactory {
public RelationshipDelegatingFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext);
public RelationshipDelegatingFieldAccessorFactory(Neo4jTemplate template) {
super(template);
}
@Override
protected Collection<FieldAccessorListenerFactory> createListenerFactories() {
return Arrays.<FieldAccessorListenerFactory>asList(
new IndexingPropertyFieldAccessorListenerFactory(
graphDatabaseContext,
new PropertyFieldAccessorFactory(graphDatabaseContext),
new ConvertingNodePropertyFieldAccessorFactory(graphDatabaseContext)
template,
new PropertyFieldAccessorFactory(template),
new ConvertingNodePropertyFieldAccessorFactory(template)
));
}
@@ -41,11 +41,11 @@ public class RelationshipDelegatingFieldAccessorFactory extends DelegatingFieldA
protected Collection<? extends FieldAccessorFactory> createAccessorFactories() {
return Arrays.<FieldAccessorFactory>asList(
new TransientFieldAccessorFactory(),
new IdFieldAccessorFactory(graphDatabaseContext),
new RelationshipNodeFieldAccessorFactory(graphDatabaseContext),
new PropertyFieldAccessorFactory(graphDatabaseContext),
new ConvertingNodePropertyFieldAccessorFactory(graphDatabaseContext),
new DynamicPropertiesFieldAccessorFactory(graphDatabaseContext)
new IdFieldAccessorFactory(template),
new RelationshipNodeFieldAccessorFactory(template),
new PropertyFieldAccessorFactory(template),
new ConvertingNodePropertyFieldAccessorFactory(template),
new DynamicPropertiesFieldAccessorFactory(template)
);
}
}

View File

@@ -24,7 +24,7 @@ import org.springframework.data.neo4j.annotation.StartNode;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import static org.springframework.data.neo4j.support.DoReturn.doReturn;
@@ -34,11 +34,11 @@ import static org.springframework.data.neo4j.support.DoReturn.doReturn;
*/
public class RelationshipNodeFieldAccessorFactory implements FieldAccessorFactory {
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
public RelationshipNodeFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
public RelationshipNodeFieldAccessorFactory(Neo4jTemplate template) {
super();
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
}
@Override
@@ -57,7 +57,7 @@ public class RelationshipNodeFieldAccessorFactory implements FieldAccessorFactor
@Override
public FieldAccessor forField(final Neo4jPersistentProperty property) {
if (isStartNodeField(property)) {
return new RelationshipNodeFieldAccessor(property, graphDatabaseContext) {
return new RelationshipNodeFieldAccessor(property, template) {
@Override
protected Node getNode(final Relationship relationship) {
return relationship.getStartNode();
@@ -66,7 +66,7 @@ public class RelationshipNodeFieldAccessorFactory implements FieldAccessorFactor
}
if (isEndNodeField(property)) {
return new RelationshipNodeFieldAccessor(property, graphDatabaseContext) {
return new RelationshipNodeFieldAccessor(property, template) {
@Override
protected Node getNode(final Relationship relationship) {
return relationship.getEndNode();
@@ -79,11 +79,11 @@ public class RelationshipNodeFieldAccessorFactory implements FieldAccessorFactor
public static abstract class RelationshipNodeFieldAccessor implements FieldAccessor {
private final Neo4jPersistentProperty property;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public RelationshipNodeFieldAccessor(final Neo4jPersistentProperty property, final GraphDatabaseContext graphDatabaseContext) {
public RelationshipNodeFieldAccessor(final Neo4jPersistentProperty property, final Neo4jTemplate template) {
this.property = property;
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
}
@Override
@@ -93,12 +93,12 @@ public class RelationshipNodeFieldAccessorFactory implements FieldAccessorFactor
@Override
public Object getValue(final Object entity) {
final Relationship relationship = graphDatabaseContext.getPersistentState(entity);
final Relationship relationship = template.getPersistentState(entity);
final Node node = getNode(relationship);
if (node == null) {
return null;
}
final Object result = graphDatabaseContext.createEntityFromState(node, (Class<?>) property.getType());
final Object result = template.createEntityFromState(node, (Class<?>) property.getType());
return doReturn(result);
}

View File

@@ -22,7 +22,7 @@ import org.neo4j.graphdb.RelationshipType;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.mapping.RelationshipInfo;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.util.Collections;
import java.util.Set;
@@ -31,8 +31,8 @@ import static org.springframework.data.neo4j.support.DoReturn.doReturn;
public class SingleRelationshipFieldAccessorFactory extends NodeRelationshipFieldAccessorFactory {
public SingleRelationshipFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext);
public SingleRelationshipFieldAccessorFactory(Neo4jTemplate template) {
super(template);
}
@Override
@@ -43,12 +43,12 @@ public class SingleRelationshipFieldAccessorFactory extends NodeRelationshipFiel
@Override
public FieldAccessor forField(final Neo4jPersistentProperty property) {
final RelationshipInfo relationshipInfo = property.getRelationshipInfo();
return new SingleRelationshipFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), (Class<?>) relationshipInfo.getTargetType().getType(), graphDatabaseContext,property);
return new SingleRelationshipFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), (Class<?>) relationshipInfo.getTargetType().getType(), template,property);
}
public static class SingleRelationshipFieldAccessor extends NodeToNodesRelationshipFieldAccessor {
public SingleRelationshipFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> clazz, final GraphDatabaseContext graphDatabaseContext, Neo4jPersistentProperty property) {
super(clazz, graphDatabaseContext, direction, type, property);
public SingleRelationshipFieldAccessor(final RelationshipType type, final Direction direction, final Class<?> clazz, final Neo4jTemplate template, Neo4jPersistentProperty property) {
super(clazz, template, direction, type, property);
}
@Override

View File

@@ -26,17 +26,17 @@ import org.springframework.data.neo4j.core.FieldTraversalDescriptionBuilder;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.lang.reflect.Constructor;
import static org.springframework.data.neo4j.support.DoReturn.doReturn;
public class TraversalFieldAccessorFactory implements FieldAccessorFactory {
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public TraversalFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public TraversalFieldAccessorFactory(Neo4jTemplate template) {
this.template = template;
}
@Override
@@ -50,7 +50,7 @@ public class TraversalFieldAccessorFactory implements FieldAccessorFactory {
@Override
public FieldAccessor forField(final Neo4jPersistentProperty property) {
return new TraversalFieldAccessor(property,graphDatabaseContext);
return new TraversalFieldAccessor(property, template);
}
/**
@@ -59,14 +59,14 @@ public class TraversalFieldAccessorFactory implements FieldAccessorFactory {
*/
public static class TraversalFieldAccessor implements FieldAccessor {
protected final Neo4jPersistentProperty property;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
private final FieldTraversalDescriptionBuilder fieldTraversalDescriptionBuilder;
private Class<?> target;
protected String[] params;
public TraversalFieldAccessor(final Neo4jPersistentProperty property, GraphDatabaseContext graphDatabaseContext) {
public TraversalFieldAccessor(final Neo4jPersistentProperty property, Neo4jTemplate template) {
this.property = property;
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
final GraphTraversal graphEntityTraversal = property.getAnnotation(GraphTraversal.class);
this.target = resolveTarget(graphEntityTraversal,property);
this.params = graphEntityTraversal.params();
@@ -76,8 +76,8 @@ public class TraversalFieldAccessorFactory implements FieldAccessorFactory {
private Class<?> resolveTarget(GraphTraversal graphTraversal, Neo4jPersistentProperty property) {
if (!graphTraversal.elementClass().equals(Object.class)) return graphTraversal.elementClass();
final Class<?> result = property.getTypeInformation().getActualType().getType();
if (graphDatabaseContext.isNodeEntity(result)) return result;
if (graphDatabaseContext.isRelationshipEntity(result)) return result;
if (template.isNodeEntity(result)) return result;
if (template.isRelationshipEntity(result)) return result;
Class<?>[] allowedTypes={Node.class,Relationship.class, Path.class};
if (!checkTypes(result,allowedTypes)) throw new IllegalArgumentException("The target result type "+result+" of the traversal is no subclass of the allowed types: "+property+" "+allowedTypes);
return result;
@@ -104,7 +104,7 @@ public class TraversalFieldAccessorFactory implements FieldAccessorFactory {
@Override
public Object getValue(final Object entity) {
final TraversalDescription traversalDescription = fieldTraversalDescriptionBuilder.build(entity, property,params);
return doReturn(graphDatabaseContext.findAllByTraversal(entity,target, traversalDescription));
return doReturn(template.findAllByTraversal(entity,target, traversalDescription));
}

View File

@@ -22,7 +22,7 @@ import org.neo4j.graphdb.PropertyContainer;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import javax.validation.Constraint;
import javax.validation.ConstraintViolation;
@@ -34,10 +34,10 @@ import java.util.Set;
class ValidatingNodePropertyFieldAccessorListenerFactory implements FieldAccessorListenerFactory {
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
ValidatingNodePropertyFieldAccessorListenerFactory(final GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
ValidatingNodePropertyFieldAccessorListenerFactory(final Neo4jTemplate template) {
this.template = template;
}
@Override
@@ -54,7 +54,7 @@ class ValidatingNodePropertyFieldAccessorListenerFactory implements FieldAccesso
@Override
public FieldAccessListener forField(Neo4jPersistentProperty property) {
return new ValidatingNodePropertyFieldAccessorListener(property,graphDatabaseContext.getValidator());
return new ValidatingNodePropertyFieldAccessorListener(property, template.getValidator());
}

View File

@@ -144,12 +144,12 @@ public class Neo4jEntityConverterImpl<T,S extends PropertyContainer> implements
final Neo4jPersistentProperty idProperty = persistentEntity.getIdProperty();
final Long id = getProperty(wrapper, idProperty, Long.class, true);
if (id == null) {
final Node newNode = getGraphDatabaseContext().createNode();
final Node newNode = getTemplate().createNode();
setProperty(wrapper, idProperty, newNode.getId());
return newNode;
}
try {
return getGraphDatabaseContext().getNodeById(id);
return getTemplate().getNodeById(id);
} catch (NotFoundException nfe) {
throw new MappingException("Could not find node with id " + id);
}

View File

@@ -18,7 +18,6 @@ package org.springframework.data.neo4j.mapping;
import org.neo4j.graphdb.PropertyContainer;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
/**
* Interface for Neo4J specific {@link PersistentEntity}.

View File

@@ -26,7 +26,7 @@ import org.springframework.data.mapping.model.BeanWrapper;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.support.DoReturn;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.EntityStateFactory;
import java.lang.reflect.InvocationTargetException;
@@ -75,8 +75,8 @@ public class SourceStateTransmitter<S extends PropertyContainer> {
entityState.setValue(property, value);
}
private GraphDatabaseContext getGraphDatabaseContext() {
return entityStateFactory.getGraphDatabaseContext();
private Neo4jTemplate getGraphDatabaseContext() {
return entityStateFactory.getTemplate();
}
private <T> T getProperty(BeanWrapper<Neo4jPersistentEntity<Object>, Object> wrapper, Neo4jPersistentProperty property, Class<T> type, boolean fieldAccessOnly) {

View File

@@ -21,16 +21,17 @@ import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.index.IndexHits;
import org.neo4j.graphdb.index.ReadableIndex;
import org.neo4j.helpers.collection.ClosableIterable;
import org.neo4j.helpers.collection.IterableWrapper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.index.NoSuchIndexException;
import org.springframework.data.neo4j.support.index.NullReadableIndex;
import java.util.ArrayList;
import java.util.Collections;
@@ -60,10 +61,10 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
* Target graphbacked type
*/
protected final Class<T> clazz;
protected final GraphDatabaseContext graphDatabaseContext;
protected final Neo4jTemplate template;
public AbstractGraphRepository(final GraphDatabaseContext graphDatabaseContext, final Class<T> clazz) {
this.graphDatabaseContext = graphDatabaseContext;
public AbstractGraphRepository(final Neo4jTemplate template, final Class<T> clazz) {
this.template = template;
this.clazz = clazz;
}
@@ -72,7 +73,7 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
*/
@Override
public long count() {
return graphDatabaseContext.count(clazz);
return template.count(clazz);
}
/**
@@ -80,7 +81,7 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
*/
@Override
public ClosableIterable<T> findAll() {
return graphDatabaseContext.findAll(clazz);
return template.findAll(clazz);
}
/**
@@ -136,12 +137,16 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
return getIndex(indexName).get(property, value);
}
protected Index<S> getIndex(String indexName) {
return graphDatabaseContext.getIndex(clazz,indexName);
protected ReadableIndex<S> getIndex(String indexName) {
try {
return template.getIndex(clazz,indexName);
} catch(NoSuchIndexException nsie) {
return new NullReadableIndex<S>(nsie.getIndex());
}
}
protected T createEntity(S node) {
return graphDatabaseContext.createEntityFromState(node, clazz);
return template.createEntityFromState(node, clazz);
}
/**
@@ -155,7 +160,7 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
@Override
public ClosableIterable<T> findAllByPropertyValue(final String indexName, final String property, final Object value) {
return query(indexName, new Query<S>() {
public IndexHits<S> query(Index<S> index) {
public IndexHits<S> query(ReadableIndex<S> index) {
return getIndexHits(indexName, property, value);
}
});
@@ -191,14 +196,14 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
@Override
public ClosableIterable<T> findAllByQuery(final String indexName, final String key, final Object query) {
return query(indexName, new Query<S>() {
public IndexHits<S> query(Index<S> index) {
public IndexHits<S> query(ReadableIndex<S> index) {
return getIndex(indexName).query(key, query);
}
});
}
interface Query<S extends PropertyContainer> {
IndexHits<S> query(Index<S> index);
IndexHits<S> query(ReadableIndex<S> index);
}
private ClosableIterable<T> query(String indexName, Query<S> query) {
try {
@@ -222,7 +227,7 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
@Override
public ClosableIterable<T> findAllByRange(final String indexName, final String property, final Number from, final Number to) {
return query(indexName, new Query<S>() {
public IndexHits<S> query(Index<S> index) {
public IndexHits<S> query(ReadableIndex<S> index) {
return index.query(property, createInclusiveRangeQuery(property, from, to));
}
});
@@ -250,7 +255,7 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
@Override
public void delete(T entity) {
final PropertyContainer state = graphDatabaseContext.getPersistentState(entity);
final PropertyContainer state = template.getPersistentState(entity);
if (state instanceof Node) {
Node node = (Node) state;
node.delete();
@@ -336,4 +341,5 @@ public abstract class AbstractGraphRepository<S extends PropertyContainer, T> im
this.indexHits.close();
}
}
}

View File

@@ -29,19 +29,19 @@ import org.springframework.data.neo4j.annotation.RelationshipEntity;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.repository.core.support.AbstractEntityInformation;
public class GraphMetamodelEntityInformation<S extends PropertyContainer, T> extends AbstractEntityInformation<T,Long> implements GraphEntityInformation<S,T> {
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
private final RelationshipEntity relationshipEntity;
private final NodeEntity nodeEntity;
@SuppressWarnings("unchecked")
public GraphMetamodelEntityInformation(Class domainClass, GraphDatabaseContext graphDatabaseContext) {
public GraphMetamodelEntityInformation(Class domainClass, Neo4jTemplate template) {
super(domainClass);
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
nodeEntity = getJavaType().getAnnotation(NodeEntity.class);
relationshipEntity = getJavaType().getAnnotation(RelationshipEntity.class);
@@ -64,13 +64,13 @@ public class GraphMetamodelEntityInformation<S extends PropertyContainer, T> ext
@Override
public boolean isNew(T entity) {
return graphDatabaseContext.getPersistentState(entity)!=null;
return template.getPersistentState(entity)!=null;
}
@Override
public Long getId(T entity) {
final PropertyContainer state = graphDatabaseContext.getPersistentState(entity);
final PropertyContainer state = template.getPersistentState(entity);
if (isNodeEntity()) {
return ((Node)state).getId();
}

View File

@@ -29,7 +29,7 @@ import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.repository.query.DerivedCypherRepositoryQuery;
import org.springframework.data.neo4j.support.GenericTypeExtractor;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.conversion.EntityResultConverter;
import org.springframework.data.neo4j.support.query.CypherQueryExecutor;
import org.springframework.data.neo4j.support.query.GremlinQueryEngine;
@@ -53,22 +53,22 @@ import java.util.Map;
*/
public class GraphRepositoryFactory extends RepositoryFactorySupport {
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
private final MappingContext<? extends Neo4jPersistentEntity<?>, Neo4jPersistentProperty> mappingContext;
/**
* Creates a new {@link GraphRepositoryFactory} from the given {@link GraphDatabaseContext} and
* Creates a new {@link GraphRepositoryFactory} from the given {@link org.springframework.data.neo4j.support.Neo4jTemplate} and
* {@link MappingContext}.
*
* @param graphDatabaseContext must not be {@literal null}.
* @param template must not be {@literal null}.
* @param mappingContext must not be {@literal null}.
*/
public GraphRepositoryFactory(GraphDatabaseContext graphDatabaseContext, MappingContext<? extends Neo4jPersistentEntity<?>, Neo4jPersistentProperty> mappingContext) {
public GraphRepositoryFactory(Neo4jTemplate template, MappingContext<? extends Neo4jPersistentEntity<?>, Neo4jPersistentProperty> mappingContext) {
Assert.notNull(graphDatabaseContext);
Assert.notNull(template);
Assert.notNull(mappingContext);
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
this.mappingContext = mappingContext;
}
@@ -82,19 +82,19 @@ public class GraphRepositoryFactory extends RepositoryFactorySupport {
*/
@Override
protected Object getTargetRepository(RepositoryMetadata metadata) {
return getTargetRepository(metadata, graphDatabaseContext);
return getTargetRepository(metadata, template);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object getTargetRepository(RepositoryMetadata metadata, GraphDatabaseContext graphDatabaseContext) {
protected Object getTargetRepository(RepositoryMetadata metadata, Neo4jTemplate template) {
Class<?> type = metadata.getDomainClass();
GraphEntityInformation entityInformation = (GraphEntityInformation)getEntityInformation(type);
// todo entityInformation.isGraphBacked();
if (entityInformation.isNodeEntity()) {
return new NodeGraphRepository(type,graphDatabaseContext);
return new NodeGraphRepository(type, template);
} else {
return new RelationshipGraphRepository(type,graphDatabaseContext);
return new RelationshipGraphRepository(type, template);
}
}
@@ -116,7 +116,7 @@ public class GraphRepositoryFactory extends RepositoryFactorySupport {
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public <T, ID extends Serializable> EntityInformation<T, ID> getEntityInformation(Class<T> type) {
return new GraphMetamodelEntityInformation(type,graphDatabaseContext);
return new GraphMetamodelEntityInformation(type, template);
}
@@ -129,10 +129,10 @@ public class GraphRepositoryFactory extends RepositoryFactorySupport {
final GraphQueryMethod queryMethod = new GraphQueryMethod(method, repositoryMetadata,namedQueries);
if (!queryMethod.hasAnnotation() && !namedQueries.hasQuery(queryMethod.getNamedQueryName())) {
return new DerivedCypherRepositoryQuery(mappingContext, queryMethod, graphDatabaseContext);
return new DerivedCypherRepositoryQuery(mappingContext, queryMethod, template);
}
return queryMethod.createQuery(repositoryMetadata, GraphRepositoryFactory.this.graphDatabaseContext);
return queryMethod.createQuery(repositoryMetadata, GraphRepositoryFactory.this.template);
}
};
}
@@ -183,11 +183,11 @@ public class GraphRepositoryFactory extends RepositoryFactorySupport {
}
private Map<String, Object> resolveParams(Object[] parameters, GraphDatabaseContext graphDatabaseContext) {
private Map<String, Object> resolveParams(Object[] parameters, Neo4jTemplate template) {
Map<String,Object> params=new HashMap<String, Object>();
for (Parameter parameter : getParameters().getBindableParameters()) {
final Object value = parameters[parameter.getIndex()];
params.put(parameter.getName(),resolveParameter(value,graphDatabaseContext));
params.put(parameter.getName(),resolveParameter(value, template));
}
return params;
}
@@ -227,13 +227,13 @@ public class GraphRepositoryFactory extends RepositoryFactorySupport {
return result;
}
private Object resolveParameter(Object parameter, GraphDatabaseContext graphDatabaseContext) {
private Object resolveParameter(Object parameter, Neo4jTemplate template) {
final Class<?> type = parameter.getClass();
final PropertyContainer state = graphDatabaseContext.getPersistentState(parameter);
if (graphDatabaseContext.isNodeEntity(type)) {
final PropertyContainer state = template.getPersistentState(parameter);
if (template.isNodeEntity(type)) {
return ((Node) state).getId();
}
if (graphDatabaseContext.isRelationshipEntity(type)) {
if (template.isRelationshipEntity(type)) {
return ((Relationship)state).getId();
}
return parameter;
@@ -266,7 +266,7 @@ public class GraphRepositoryFactory extends RepositoryFactorySupport {
return Iterable.class.isAssignableFrom(getReturnType());
}
private RepositoryQuery createQuery(RepositoryMetadata repositoryMetadata, final GraphDatabaseContext context) {
private RepositoryQuery createQuery(RepositoryMetadata repositoryMetadata, final Neo4jTemplate context) {
if (!isValid()) {
return null;
}
@@ -289,9 +289,9 @@ public class GraphRepositoryFactory extends RepositoryFactorySupport {
private CypherQueryExecutor queryExecutor;
public CypherGraphRepositoryQuery(GraphQueryMethod queryMethod, RepositoryMetadata metadata, final GraphDatabaseContext graphDatabaseContext) {
super(queryMethod, metadata, graphDatabaseContext);
queryExecutor = new CypherQueryExecutor(graphDatabaseContext);
public CypherGraphRepositoryQuery(GraphQueryMethod queryMethod, RepositoryMetadata metadata, final Neo4jTemplate template) {
super(queryMethod, metadata, template);
queryExecutor = new CypherQueryExecutor(template);
}
@Override
@@ -319,9 +319,9 @@ public class GraphRepositoryFactory extends RepositoryFactorySupport {
private GremlinQueryEngine queryExecutor;
public GremlinGraphRepositoryQuery(GraphQueryMethod queryMethod, RepositoryMetadata metadata, final GraphDatabaseContext graphDatabaseContext) {
super(queryMethod, metadata, graphDatabaseContext);
queryExecutor = new GremlinQueryEngine(graphDatabaseContext.getGraphDatabaseService(), new EntityResultConverter<Object, Object>(graphDatabaseContext));
public GremlinGraphRepositoryQuery(GraphQueryMethod queryMethod, RepositoryMetadata metadata, final Neo4jTemplate template) {
super(queryMethod, metadata, template);
queryExecutor = new GremlinQueryEngine(template.getGraphDatabaseService(), new EntityResultConverter<Object, Object>(template));
}
@Override
@@ -345,16 +345,16 @@ public class GraphRepositoryFactory extends RepositoryFactorySupport {
private static abstract class GraphRepositoryQuery implements RepositoryQuery {
private final GraphQueryMethod queryMethod;
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public GraphRepositoryQuery(GraphQueryMethod queryMethod, RepositoryMetadata metadata, final GraphDatabaseContext graphDatabaseContext) {
public GraphRepositoryQuery(GraphQueryMethod queryMethod, RepositoryMetadata metadata, final Neo4jTemplate template) {
this.queryMethod = queryMethod;
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
}
@Override
public Object execute(Object[] parameters) {
Map<String, Object> params = queryMethod.resolveParams(parameters,graphDatabaseContext);
Map<String, Object> params = queryMethod.resolveParams(parameters, template);
final String queryString = queryMethod.prepareQuery(parameters);
return dispatchQuery(queryString,params,queryMethod.getPageable(parameters));
}

View File

@@ -21,7 +21,7 @@ import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.neo4j.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.data.repository.core.support.TransactionalRepositoryFactoryBeanSupport;
import org.springframework.util.Assert;
@@ -33,11 +33,11 @@ import org.springframework.util.Assert;
public class GraphRepositoryFactoryBean<S extends PropertyContainer, R extends CRUDRepository<T>, T> extends
TransactionalRepositoryFactoryBeanSupport<R, T, Long> {
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
private MappingContext<? extends Neo4jPersistentEntity<?>, Neo4jPersistentProperty> mappingContext;
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public void setNeo4jTemplate(Neo4jTemplate template) {
this.template = template;
}
/**
@@ -50,17 +50,17 @@ TransactionalRepositoryFactoryBeanSupport<R, T, Long> {
@Override
protected RepositoryFactorySupport doCreateRepositoryFactory() {
return createRepositoryFactory(graphDatabaseContext);
return createRepositoryFactory(template);
}
protected RepositoryFactorySupport createRepositoryFactory(GraphDatabaseContext graphDatabaseContext) {
protected RepositoryFactorySupport createRepositoryFactory(Neo4jTemplate template) {
return new GraphRepositoryFactory(graphDatabaseContext, mappingContext);
return new GraphRepositoryFactory(template, mappingContext);
}
@Override
public void afterPropertiesSet() {
Assert.notNull(graphDatabaseContext, "GraphDatabaseContext must not be null!");
Assert.notNull(template, "Neo4jTemplate must not be null!");
if (mappingContext == null) {
Neo4jMappingContext context = new Neo4jMappingContext();

View File

@@ -19,28 +19,28 @@ package org.springframework.data.neo4j.repository;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
public class NodeGraphRepository<T> extends AbstractGraphRepository<Node, T> implements GraphRepository<T> {
public NodeGraphRepository(final Class<T> clazz, final GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext, clazz);
public NodeGraphRepository(final Class<T> clazz, final Neo4jTemplate template) {
super(template, clazz);
}
@Override
protected Node getById(long id) {
return graphDatabaseContext.getNodeById(id);
return template.getNodeById(id);
}
@Override
public <N> Iterable<T> findAllByTraversal(final N start, final TraversalDescription traversalDescription) {
return graphDatabaseContext.findAllByTraversal(start, clazz, traversalDescription);
return template.findAllByTraversal(start, clazz, traversalDescription);
}
@SuppressWarnings("unchecked")
@Override
public T save(T entity) {
return (T)graphDatabaseContext.save(entity);
return (T) template.save(entity);
}
@SuppressWarnings("unchecked")

View File

@@ -20,17 +20,17 @@ import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
public class RelationshipGraphRepository<T> extends AbstractGraphRepository<Relationship, T> implements GraphRepository<T> {
public RelationshipGraphRepository(final Class<T> clazz, final GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext, clazz);
public RelationshipGraphRepository(final Class<T> clazz, final Neo4jTemplate template) {
super(template, clazz);
}
@Override
protected Relationship getById(long id) {
return graphDatabaseContext.getRelationshipById(id);
return template.getRelationshipById(id);
}
@Override

View File

@@ -24,7 +24,7 @@ import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.repository.GraphRepositoryFactory.GraphQueryMethod;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.query.CypherQueryExecutor;
import org.springframework.data.repository.core.EntityMetadata;
import org.springframework.data.repository.query.ParameterAccessor;
@@ -47,13 +47,13 @@ public class DerivedCypherRepositoryQuery implements RepositoryQuery {
/**
* Creates a new {@link DerivedCypherRepositoryQuery} from the given {@link MappingContext},
* {@link GraphQueryMethod} and {@link GraphDatabaseContext}.
* {@link GraphQueryMethod} and {@link org.springframework.data.neo4j.support.Neo4jTemplate}.
*
* @param context must not be {@literal null}.
* @param method must not be {@literal null}.
* @param database must not be {@literal null}.
*/
public DerivedCypherRepositoryQuery(MappingContext<? extends Neo4jPersistentEntity<?>, Neo4jPersistentProperty> context, GraphQueryMethod method, GraphDatabaseContext database) {
public DerivedCypherRepositoryQuery(MappingContext<? extends Neo4jPersistentEntity<?>, Neo4jPersistentProperty> context, GraphQueryMethod method, Neo4jTemplate database) {
Assert.notNull(context);
Assert.notNull(method);

View File

@@ -16,23 +16,31 @@
package org.springframework.data.neo4j.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.neo4j.graphdb.*;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.index.IndexManager;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.index.impl.lucene.LuceneIndexImplementation;
import org.neo4j.kernel.AbstractGraphDatabase;
import org.neo4j.kernel.Traversal;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.neo4j.annotation.QueryType;
import org.springframework.data.neo4j.conversion.Result;
import org.springframework.data.neo4j.conversion.ResultConverter;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.support.index.NoSuchIndexException;
import org.springframework.data.neo4j.support.query.ConversionServiceQueryResultConverter;
import org.springframework.data.neo4j.support.query.CypherQueryEngine;
import org.springframework.data.neo4j.support.query.GremlinQueryEngine;
import org.springframework.data.neo4j.support.query.QueryEngine;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import java.util.Map;
/**
@@ -44,6 +52,7 @@ public class DelegatingGraphDatabase implements GraphDatabase {
protected GraphDatabaseService delegate;
private ConversionService conversionService;
private ResultConverter resultConverter;
private static final Log log = LogFactory.getLog(DelegatingGraphDatabase.class);
public DelegatingGraphDatabase(final GraphDatabaseService delegate) {
this.delegate = delegate;
@@ -80,6 +89,20 @@ public class DelegatingGraphDatabase implements GraphDatabase {
return primitive;
}
private void removeFromIndexes(Node node) {
final IndexManager indexManager = delegate.index();
for (String indexName : indexManager.nodeIndexNames()) {
indexManager.forNodes(indexName).remove(node);
}
}
private void removeFromIndexes(Relationship relationship) {
final IndexManager indexManager = delegate.index();
for (String indexName : indexManager.relationshipIndexNames()) {
indexManager.forRelationships(indexName).remove(relationship);
}
}
@Override
public Relationship getRelationshipById(long id) {
return delegate.getRelationshipById(id);
@@ -96,7 +119,7 @@ public class DelegatingGraphDatabase implements GraphDatabase {
IndexManager indexManager = delegate.index();
if (indexManager.existsForNodes(indexName)) return (Index<T>) indexManager.forNodes(indexName);
if (indexManager.existsForRelationships(indexName)) return (Index<T>) indexManager.forRelationships(indexName);
throw new IllegalArgumentException("Index "+indexName+" does not exist.");
throw new NoSuchIndexException(indexName);
}
// TODO handle existing indexes
@@ -124,10 +147,13 @@ public class DelegatingGraphDatabase implements GraphDatabase {
private <T extends PropertyContainer> Index<T> checkAndGetExistingIndex(final String indexName, boolean fullText, final Index<T> index) {
Map<String, String> existingConfig = delegate.index().getConfiguration(index);
Map<String, String> config = indexConfigFor(fullText);
if (config.equals(existingConfig)) return index;
throw new IllegalArgumentException("Setup for index name '"+indexName+"' does not match "+(fullText ? "fulltext":"exact"));
if (configCheck(config, existingConfig, "provider") && configCheck(config, existingConfig, "type")) return index;
throw new IllegalArgumentException("Setup for index "+indexName+" does not match. Existing: "+existingConfig+" required "+config);
}
private boolean configCheck(Map<String, String> config, Map<String, String> existingConfig, String setting) {
return ObjectUtils.nullSafeEquals(config.get(setting), existingConfig.get(setting));
}
private Map<String, String> indexConfigFor(boolean fullText) {
return fullText ? LuceneIndexImplementation.FULLTEXT_CONFIG : LuceneIndexImplementation.EXACT_CONFIG;
}
@@ -161,6 +187,32 @@ public class DelegatingGraphDatabase implements GraphDatabase {
throw new IllegalArgumentException("Unknown Query Engine Type "+type);
}
@Override
public boolean transactionIsRunning() {
if (!(delegate instanceof AbstractGraphDatabase)) {
return true; // assume always running tx (e.g. for REST or other remotes)
}
try {
final TransactionManager txManager = ((AbstractGraphDatabase) delegate).getConfig().getTxModule().getTxManager();
return txManager.getStatus() != Status.STATUS_NO_TRANSACTION;
} catch (SystemException e) {
log.error("Error accessing TransactionManager", e);
return false;
}
}
@Override
public void remove(Node node) {
removeFromIndexes(node);
node.delete();
}
@Override
public void remove(Relationship relationship) {
removeFromIndexes(relationship);
relationship.delete();
}
private ResultConverter createResultConverter() {
if (resultConverter!=null) return resultConverter;
if (conversionService != null) {

View File

@@ -17,7 +17,7 @@ package org.springframework.data.neo4j.support;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.index.IndexManager;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.core.TypeRepresentationStrategy;
/**
@@ -29,13 +29,13 @@ public class EntityRemover {
private EntityStateHandler entityStateHandler;
private TypeRepresentationStrategy<Node> nodeTypeRepresentationStrategy;
private TypeRepresentationStrategy<Relationship> relationshipTypeRepresentationStrategy;
private IndexManager indexManager;
private final GraphDatabase graphDatabase;
public EntityRemover(EntityStateHandler entityStateHandler, TypeRepresentationStrategy<Node> nodeTypeRepresentationStrategy, TypeRepresentationStrategy<Relationship> relationshipTypeRepresentationStrategy, IndexManager indexManager) {
public EntityRemover(EntityStateHandler entityStateHandler, TypeRepresentationStrategy<Node> nodeTypeRepresentationStrategy, TypeRepresentationStrategy<Relationship> relationshipTypeRepresentationStrategy, GraphDatabase graphDatabase) {
this.entityStateHandler = entityStateHandler;
this.nodeTypeRepresentationStrategy = nodeTypeRepresentationStrategy;
this.relationshipTypeRepresentationStrategy = relationshipTypeRepresentationStrategy;
this.indexManager = indexManager;
this.graphDatabase = graphDatabase;
}
public void removeNodeEntity(Object entity) {
@@ -45,8 +45,7 @@ public class EntityRemover {
for (Relationship relationship : node.getRelationships()) {
removeRelationship(relationship);
}
removeFromIndexes(node);
node.delete();
graphDatabase.remove(node);
}
public void removeRelationshipEntity(Object entity) {
@@ -57,20 +56,7 @@ public class EntityRemover {
private void removeRelationship(Relationship relationship) {
relationshipTypeRepresentationStrategy.preEntityRemoval(relationship);
removeFromIndexes(relationship);
relationship.delete();
}
private void removeFromIndexes(Node node) {
for (String indexName : indexManager.nodeIndexNames()) {
indexManager.forNodes(indexName).remove(node);
}
}
private void removeFromIndexes(Relationship relationship) {
for (String indexName : indexManager.relationshipIndexNames()) {
indexManager.forRelationships(indexName).remove(relationship);
}
graphDatabase.remove(relationship);
}
public void removeRelationshipTo(Object start, Object target, String type) {

View File

@@ -16,6 +16,7 @@
package org.springframework.data.neo4j.support;
import org.neo4j.graphdb.*;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntityImpl;
import org.springframework.data.neo4j.mapping.RelationshipProperties;
@@ -27,11 +28,11 @@ import org.springframework.data.neo4j.mapping.RelationshipProperties;
public class EntityStateHandler {
private Neo4jMappingContext mappingContext;
private final GraphDatabaseService service;
private final GraphDatabase graphDatabase;
public EntityStateHandler(Neo4jMappingContext mappingContext, GraphDatabaseService service) {
public EntityStateHandler(Neo4jMappingContext mappingContext, GraphDatabase graphDatabase) {
this.mappingContext = mappingContext;
this.service = service;
this.graphDatabase = graphDatabase;
}
@SuppressWarnings("unchecked")
@@ -86,10 +87,10 @@ public class EntityStateHandler {
long graphId = id.longValue();
final Neo4jPersistentEntityImpl<?> persistentEntity = mappingContext.getPersistentEntity(entity.getClass());
if (persistentEntity.isNodeEntity()) {
return (S) service.getNodeById(graphId);
return (S) graphDatabase.getNodeById(graphId);
}
if (persistentEntity.isRelationshipEntity()) {
return (S) service.getRelationshipById(graphId);
return (S) graphDatabase.getRelationshipById(graphId);
}
throw new IllegalArgumentException("The entity " + persistentEntity.getEntityName() + " has to be either annotated with @NodeEntity or @RelationshipEntity");
}
@@ -110,7 +111,7 @@ public class EntityStateHandler {
final Class<?> type = entity.getClass();
final Neo4jPersistentEntityImpl<?> persistentEntity = mappingContext.getPersistentEntity(type);
if (persistentEntity.isNodeEntity()) {
return (S) service.createNode();
return (S) graphDatabase.createNode(null);
}
if (persistentEntity.isRelationshipEntity()) {
return createRelationship(entity, persistentEntity);

View File

@@ -20,12 +20,9 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.neo4j.graphdb.*;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.index.IndexManager;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.helpers.collection.ClosableIterable;
import org.neo4j.index.impl.lucene.LuceneIndexImplementation;
import org.neo4j.kernel.AbstractGraphDatabase;
import org.springframework.core.convert.ConversionService;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
@@ -63,12 +60,8 @@ import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.ObjectUtils;
import javax.annotation.PostConstruct;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import javax.validation.Validator;
import java.util.ArrayList;
import java.util.Collection;
@@ -83,9 +76,9 @@ import java.util.Map;
* @author Michael Hunger
* @since 13.09.2010
*/
public class GraphDatabaseContext implements Neo4jOperations {
public class Neo4jTemplate implements Neo4jOperations {
private static final Log log = LogFactory.getLog(GraphDatabaseContext.class);
private static final Log log = LogFactory.getLog(Neo4jTemplate.class);
private GraphDatabaseService graphDatabaseService;
private ConversionService conversionService;
@@ -113,20 +106,20 @@ public class GraphDatabaseContext implements Neo4jOperations {
/**
* default constructor for dependency injection, TODO provide dependencies at creation time
*/
public GraphDatabaseContext() {
public Neo4jTemplate() {
}
/**
* @param graphDatabase the neo4j graph database
* @param transactionManager if passed in, will be used to create implicit transactions whenever needed
*/
public GraphDatabaseContext(final GraphDatabase graphDatabase, PlatformTransactionManager transactionManager) {
public Neo4jTemplate(final GraphDatabase graphDatabase, PlatformTransactionManager transactionManager) {
notNull(graphDatabase, "graphDatabase");
this.transactionManager = transactionManager;
this.graphDatabase = graphDatabase;
}
public GraphDatabaseContext(final GraphDatabase graphDatabase) {
public Neo4jTemplate(final GraphDatabase graphDatabase) {
notNull(graphDatabase, "graphDatabase");
transactionManager = null;
this.graphDatabase = graphDatabase;
@@ -145,12 +138,12 @@ public class GraphDatabaseContext implements Neo4jOperations {
}
static class IndexProvider {
private IndexManager indexManager;
private Neo4jMappingContext mappingContext;
private final GraphDatabase graphDatabase;
IndexProvider(IndexManager indexManager, Neo4jMappingContext mappingContext) {
this.indexManager = indexManager;
IndexProvider(Neo4jMappingContext mappingContext, GraphDatabase graphDatabase) {
this.mappingContext = mappingContext;
this.graphDatabase = graphDatabase;
}
public <S extends PropertyContainer, T> Index<S> getIndex(Class<T> type) {
@@ -173,8 +166,8 @@ public class GraphDatabaseContext implements Neo4jOperations {
final boolean useExistingIndex = fullText == null;
if (useExistingIndex) {
if (persistentEntity.isNodeEntity()) return (Index<S>) getIndexManager().forNodes(indexName);
if (persistentEntity.isRelationshipEntity()) return (Index<S>) getIndexManager().forRelationships(indexName);
if (persistentEntity.isNodeEntity()) return (Index<S>) graphDatabase.getIndex(indexName);
if (persistentEntity.isRelationshipEntity()) return (Index<S>) graphDatabase.getIndex(indexName);
throw new IllegalArgumentException("Wrong index type supplied: " + type + " expected Node- or Relationship-Entity");
}
@@ -183,15 +176,9 @@ public class GraphDatabaseContext implements Neo4jOperations {
throw new IllegalArgumentException("Wrong index type supplied: " + type + " expected Node- or Relationship-Entity");
}
public IndexManager getIndexManager() {
return indexManager;
}
@SuppressWarnings("unchecked")
public <T extends PropertyContainer> Index<T> getIndex(String indexName) {
if (indexManager.existsForNodes(indexName)) return (Index<T>) indexManager.forNodes(indexName);
if (indexManager.existsForRelationships(indexName)) return (Index<T>) indexManager.forRelationships(indexName);
throw new IllegalArgumentException("Index "+indexName+" does not exist.");
return graphDatabase.getIndex(indexName);
}
public boolean isNode(Class<? extends PropertyContainer> type) {
@@ -203,32 +190,8 @@ public class GraphDatabaseContext implements Neo4jOperations {
// TODO handle existing indexes
@SuppressWarnings("unchecked")
public <T extends PropertyContainer> Index<T> createIndex(Class<T> type, String indexName, boolean fullText) {
if (isNode(type)) {
if (indexManager.existsForNodes(indexName))
return (Index<T>) checkAndGetExistingIndex(indexName, fullText, indexManager.forNodes(indexName));
return (Index<T>) indexManager.forNodes(indexName, indexConfigFor(fullText));
} else {
if (indexManager.existsForRelationships(indexName))
return (Index<T>) checkAndGetExistingIndex(indexName, fullText, indexManager.forRelationships(indexName));
return (Index<T>) indexManager.forRelationships(indexName, indexConfigFor(fullText));
}
return graphDatabase.createIndex(type,indexName,fullText);
}
private <T extends PropertyContainer> Index<T> checkAndGetExistingIndex(final String indexName, boolean fullText, final Index<T> index) {
Map<String, String> existingConfig = indexManager.getConfiguration(index);
Map<String, String> config = indexConfigFor(fullText);
if (configCheck(config, existingConfig, "provider") && configCheck(config, existingConfig, "type")) return index;
throw new IllegalArgumentException("Setup for index "+indexName+" does not match. Existing: "+existingConfig+" required "+config);
}
private boolean configCheck(Map<String, String> config, Map<String, String> existingConfig, String setting) {
return ObjectUtils.nullSafeEquals(config.get(setting), existingConfig.get(setting));
}
private Map<String, String> indexConfigFor(boolean fullText) {
return fullText ? LuceneIndexImplementation.FULLTEXT_CONFIG : LuceneIndexImplementation.EXACT_CONFIG;
}
}
public <S extends PropertyContainer, T> Index<S> getIndex(Class<T> type) {
@@ -251,16 +214,7 @@ public class GraphDatabaseContext implements Neo4jOperations {
* @return true if a transaction manager is available and a transaction is currently running
*/
public boolean transactionIsRunning() {
if (!(graphDatabaseService instanceof AbstractGraphDatabase)) {
return true; // assume always running tx (e.g. for REST or other remotes)
}
try {
final TransactionManager txManager = ((AbstractGraphDatabase) graphDatabaseService).getConfig().getTxModule().getTxManager();
return txManager.getStatus() != Status.STATUS_NO_TRANSACTION;
} catch (SystemException e) {
log.error("Error accessing TransactionManager", e);
return false;
}
return graphDatabase.transactionIsRunning();
}
@@ -334,7 +288,7 @@ public class GraphDatabaseContext implements Neo4jOperations {
*/
@Override
public Node createNode() {
return graphDatabaseService.createNode();
return graphDatabase.createNode(null);
}
@Override
@@ -375,20 +329,13 @@ public class GraphDatabaseContext implements Neo4jOperations {
* Delegates to {@link GraphDatabaseService}
*/
public Node getNodeById(final long nodeId) {
return graphDatabaseService.getNodeById(nodeId);
return graphDatabase.getNodeById(nodeId);
}
/**
* Delegates to {@link GraphDatabaseService}
*/
public Result<Node> getAllNodes() {
return convert(graphDatabaseService.getAllNodes());
}
/**
* Delegates to {@link GraphDatabaseService}
*/
public Transaction beginTx() {
public Transaction beginTx() { // todo remove !
return graphDatabaseService.beginTx();
}
@@ -396,18 +343,18 @@ public class GraphDatabaseContext implements Neo4jOperations {
* Delegates to {@link GraphDatabaseService}
*/
public Relationship getRelationshipById(final long id) {
return graphDatabaseService.getRelationshipById(id);
return graphDatabase.getRelationshipById(id);
}
@PostConstruct
public void postConstruct() {
public Neo4jTemplate postConstruct() {
this.resultConverter = new EntityResultConverter<Object, Object>(this);
if (this.graphDatabase==null) {
this.graphDatabase=new DelegatingGraphDatabase(graphDatabaseService,resultConverter);
}
this.typeRepresentationStrategies = new TypeRepresentationStrategies(mappingContext, nodeTypeRepresentationStrategy, relationshipTypeRepresentationStrategy);
this.cypherQueryExecutor = new CypherQueryExecutor(this);
final EntityStateHandler entityStateHandler = new EntityStateHandler(mappingContext, graphDatabaseService);
final EntityStateHandler entityStateHandler = new EntityStateHandler(mappingContext, graphDatabase);
if (nodeEntityInstantiator==null) {
nodeEntityInstantiator = new NodeEntityInstantiator(entityStateHandler);
}
@@ -417,8 +364,9 @@ public class GraphDatabaseContext implements Neo4jOperations {
}
EntityTools<Relationship> relationshipEntityTools = new EntityTools<Relationship>(relationshipTypeRepresentationStrategy, relationshipEntityStateFactory, relationshipEntityInstantiator);
this.entityPersister = new Neo4jEntityPersister(conversionService, nodeEntityTools, relationshipEntityTools,mappingContext, entityStateHandler);
this.entityRemover = new EntityRemover(this.entityStateHandler, nodeTypeRepresentationStrategy, relationshipTypeRepresentationStrategy, graphDatabaseService.index());
this.indexProvider = new IndexProvider(graphDatabaseService.index(), mappingContext);
this.entityRemover = new EntityRemover(this.entityStateHandler, nodeTypeRepresentationStrategy, relationshipTypeRepresentationStrategy, graphDatabase);
this.indexProvider = new IndexProvider(mappingContext,graphDatabase);
return this;
}
@@ -542,9 +490,9 @@ public class GraphDatabaseContext implements Neo4jOperations {
}
@Override
public Node getReferenceNode() {
public <T> T getReferenceNode(Class<T> target) {
try {
return graphDatabase.getReferenceNode();
return convert(graphDatabase.getReferenceNode(), target);
} catch (RuntimeException e) {
throw translateExceptionIfPossible(e);
}

View File

@@ -19,7 +19,7 @@ package org.springframework.data.neo4j.support.conversion;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.neo4j.conversion.DefaultConverter;
import org.springframework.data.neo4j.core.EntityPath;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.path.ConvertingEntityPath;
/**
@@ -27,10 +27,10 @@ import org.springframework.data.neo4j.support.path.ConvertingEntityPath;
* @since 28.06.11
*/
public class EntityResultConverter<T,R> extends DefaultConverter<T,R> {
private final GraphDatabaseContext ctx;
private final Neo4jTemplate ctx;
private final ConversionService conversionService;
public EntityResultConverter(GraphDatabaseContext ctx) {
public EntityResultConverter(Neo4jTemplate ctx) {
this.ctx = ctx;
conversionService = this.ctx.getConversionService();
}
@@ -39,10 +39,10 @@ public class EntityResultConverter<T,R> extends DefaultConverter<T,R> {
@Override
protected Object doConvert(Object value, Class<?> sourceType, Class targetType) {
if (ctx.isNodeEntity(targetType)) {
return ctx.projectTo(toNode(value,sourceType),targetType);
return ctx.projectTo(toNode(value, sourceType), targetType);
}
if (ctx.isRelationshipEntity(targetType)) {
return ctx.projectTo(toRelationship(value,sourceType),targetType);
return ctx.projectTo(toRelationship(value, sourceType), targetType);
}
if (EntityPath.class.isAssignableFrom(targetType)) {
return new ConvertingEntityPath(ctx,toPath(value,sourceType));

View File

@@ -0,0 +1,67 @@
/**
* 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.support.index;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.index.IndexHits;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* @author mh
* @since 16.10.11
*/
public class EmptyIndexHits<S extends PropertyContainer> implements IndexHits<S> {
@Override
public int size() {
return 0;
}
@Override
public void close() {
}
@Override
public S getSingle() {
return null;
}
@Override
public float currentScore() {
return 0;
}
@Override
public Iterator<S> iterator() {
return this;
}
@Override
public boolean hasNext() {
return false;
}
@Override
public S next() {
throw new NoSuchElementException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,36 @@
/**
* 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.support.index;
import org.springframework.dao.DataRetrievalFailureException;
/**
* @author mh
* @since 16.10.11
*/
public class NoSuchIndexException extends DataRetrievalFailureException {
private final String index;
public NoSuchIndexException(String index) {
super("No such index: "+index);
this.index = index;
}
public String getIndex() {
return index;
}
}

View File

@@ -0,0 +1,63 @@
/**
* 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.support.index;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.index.IndexHits;
import org.neo4j.graphdb.index.ReadableIndex;
/**
* @author mh
* @since 16.10.11
*/
public class NullReadableIndex<S extends PropertyContainer> implements ReadableIndex<S> {
private final String indexName;
public NullReadableIndex(String indexName) {
this.indexName = indexName;
}
@Override
public String getName() {
return indexName;
}
@Override
public Class<S> getEntityType() {
return null;
}
@Override
public IndexHits<S> get(String key, Object value) {
return new EmptyIndexHits<S>();
}
@Override
public IndexHits<S> query(String key, Object queryOrQueryObject) {
return new EmptyIndexHits<S>();
}
@Override
public IndexHits<S> query(Object queryOrQueryObject) {
return new EmptyIndexHits<S>();
}
@Override
public boolean isWriteable() {
return false;
}
}

View File

@@ -15,10 +15,9 @@
*/
package org.springframework.data.neo4j.support.node;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.PropertyContainer;
import org.springframework.data.neo4j.core.EntityState;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
/**
* @author mh
@@ -27,5 +26,5 @@ import org.springframework.data.neo4j.support.GraphDatabaseContext;
public interface EntityStateFactory<S extends PropertyContainer> {
EntityState<S> getEntityState(final Object entity, boolean detachable);
GraphDatabaseContext getGraphDatabaseContext();
Neo4jTemplate getTemplate();
}

View File

@@ -18,12 +18,12 @@ package org.springframework.data.neo4j.support.node;
import org.neo4j.graphdb.*;
import org.neo4j.graphdb.index.IndexManager;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
public abstract class Neo4jHelper {
public static void cleanDb(GraphDatabaseContext graphDatabaseContext) {
cleanDb(graphDatabaseContext.getGraphDatabaseService());
public static void cleanDb(Neo4jTemplate template) {
cleanDb(template.getGraphDatabaseService());
}
public static void cleanDb(GraphDatabaseService graphDatabaseService) {

View File

@@ -23,7 +23,7 @@ import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.data.neo4j.fieldaccess.DefaultEntityState;
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.ManagedEntity;
/**
@@ -32,11 +32,11 @@ import org.springframework.data.neo4j.support.ManagedEntity;
*/
public class NodeEntityState extends DefaultEntityState<Node> {
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
public NodeEntityState(final Node underlyingState, final Object entity, final Class<? extends Object> type, final GraphDatabaseContext graphDatabaseContext, final DelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory, Neo4jPersistentEntity<Object> persistentEntity) {
public NodeEntityState(final Node underlyingState, final Object entity, final Class<? extends Object> type, final Neo4jTemplate template, final DelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory, Neo4jPersistentEntity<Object> persistentEntity) {
super(underlyingState, entity, type, nodeDelegatingFieldAccessorFactory,persistentEntity);
this.graphDatabaseContext = graphDatabaseContext;
this.template = template;
}
@Override
@@ -48,17 +48,17 @@ public class NodeEntityState extends DefaultEntityState<Node> {
try {
final Object id = getIdFromEntity();
if (id instanceof Number) {
final Node node = graphDatabaseContext.getNodeById(((Number) id).longValue());
final Node node = template.getNodeById(((Number) id).longValue());
setPersistentState(node);
if (log.isInfoEnabled())
log.info("Entity reattached " + entity.getClass() + "; used Node [" + getPersistentState() + "];");
return;
}
final Node node = graphDatabaseContext.createNode();
final Node node = template.createNode();
setPersistentState(node);
if (log.isInfoEnabled()) log.info("User-defined constructor called on class " + entity.getClass() + "; created Node [" + getPersistentState() + "]; Updating metamodel");
graphDatabaseContext.postEntityCreation(node, type);
template.postEntityCreation(node, type);
} catch (NotInTransactionException e) {
throw new InvalidDataAccessResourceUsageException("Not in a Neo4j transaction.", e);
}
@@ -67,7 +67,7 @@ public class NodeEntityState extends DefaultEntityState<Node> {
@Override
public void setPersistentState(Node node) {
if (!(entity instanceof ManagedEntity)) {
graphDatabaseContext.setPersistentState(entity, node);
template.setPersistentState(entity, node);
}
super.setPersistentState(node);
}

View File

@@ -23,11 +23,11 @@ import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory
import org.springframework.data.neo4j.fieldaccess.DetachedEntityState;
import org.springframework.data.neo4j.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
public class NodeEntityStateFactory implements EntityStateFactory<Node> {
protected GraphDatabaseContext graphDatabaseContext;
protected Neo4jTemplate template;
protected DelegatingFieldAccessorFactory nodeDelegatingFieldAccessorFactory;
@@ -37,12 +37,12 @@ public class NodeEntityStateFactory implements EntityStateFactory<Node> {
final Class<?> entityType = entity.getClass();
@SuppressWarnings("unchecked") final Neo4jPersistentEntity<Object> persistentEntity =
(Neo4jPersistentEntity<Object>) mappingContext.getPersistentEntity(entityType);
NodeEntityState nodeEntityState = new NodeEntityState(null, entity, entityType, graphDatabaseContext,
NodeEntityState nodeEntityState = new NodeEntityState(null, entity, entityType, template,
nodeDelegatingFieldAccessorFactory, persistentEntity);
if (!detachable) {
return nodeEntityState;
}
return new DetachedEntityState<Node>(nodeEntityState, graphDatabaseContext);
return new DetachedEntityState<Node>(nodeEntityState, template);
}
public void setNodeDelegatingFieldAccessorFactory(
@@ -50,8 +50,8 @@ public class NodeEntityStateFactory implements EntityStateFactory<Node> {
this.nodeDelegatingFieldAccessorFactory = nodeDelegatingFieldAccessorFactory;
}
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
public void setTemplate(Neo4jTemplate template) {
this.template = template;
}
public Neo4jMappingContext getMappingContext() {
@@ -62,8 +62,8 @@ public class NodeEntityStateFactory implements EntityStateFactory<Node> {
this.mappingContext = mappingContext;
}
public GraphDatabaseContext getGraphDatabaseContext() {
return graphDatabaseContext;
public Neo4jTemplate getTemplate() {
return template;
}
}

View File

@@ -25,7 +25,7 @@ import org.springframework.data.neo4j.core.EntityPath;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import java.util.Iterator;
@@ -43,8 +43,8 @@ public class ConvertingEntityPath<S,E> implements EntityPath<S,E> {
private <T> T projectEntityToFirstParameterOrCreateFromStoredType(Node node, Class<T>... types) {
if (node==null) return null;
if (types==null || types.length==0) return graphDatabaseContext.createEntityFromStoredType(node);
return graphDatabaseContext.projectTo(node, types[0]);
if (types==null || types.length==0) return template.createEntityFromStoredType(node);
return template.projectTo(node, types[0]);
}
@Override
@@ -55,7 +55,7 @@ public class ConvertingEntityPath<S,E> implements EntityPath<S,E> {
public <T> T lastRelationshipEntity(Class<T>... types) {
Relationship relationship = lastRelationship();
if (relationship==null) return null;
return graphDatabaseContext.projectTo(relationship, getFirstOrDefault((Class<T>) DefaultRelationshipBacked.class, types));
return template.projectTo(relationship, getFirstOrDefault((Class<T>) DefaultRelationshipBacked.class, types));
}
private static <T> T getFirstOrDefault(final T defaultValue, T... values) {
@@ -68,7 +68,7 @@ public class ConvertingEntityPath<S,E> implements EntityPath<S,E> {
return new IterableWrapper<T,Node>(nodes()) {
@Override
protected T underlyingObjectToObject(Node node) {
return graphDatabaseContext.createEntityFromStoredType(node);
return template.createEntityFromStoredType(node);
}
};
}
@@ -78,7 +78,7 @@ public class ConvertingEntityPath<S,E> implements EntityPath<S,E> {
return new IterableWrapper<T,Relationship>(relationships()) {
@Override
protected T underlyingObjectToObject(Relationship relationship) {
return graphDatabaseContext.projectTo(relationship, getFirstOrDefault((Class<T>) DefaultRelationshipBacked.class, relationships));
return template.projectTo(relationship, getFirstOrDefault((Class<T>) DefaultRelationshipBacked.class, relationships));
}
};
}
@@ -88,18 +88,18 @@ public class ConvertingEntityPath<S,E> implements EntityPath<S,E> {
return new IterableWrapper<T,PropertyContainer>(delegate) {
@Override
protected T underlyingObjectToObject(PropertyContainer element) {
return graphDatabaseContext.projectTo(element, getFirstOrDefault((Class<T>) DefaultRelationshipBacked.class, relationships));
return template.projectTo(element, getFirstOrDefault((Class<T>) DefaultRelationshipBacked.class, relationships));
}
};
}
public ConvertingEntityPath(GraphDatabaseContext graphDatabaseContext, Path delegate) {
this.graphDatabaseContext = graphDatabaseContext;
public ConvertingEntityPath(Neo4jTemplate template, Path delegate) {
this.template = template;
this.delegate = delegate;
}
private final GraphDatabaseContext graphDatabaseContext;
private final Neo4jTemplate template;
private final Path delegate;
@Override

View File

@@ -21,18 +21,18 @@ import org.neo4j.graphdb.traversal.Evaluation;
import org.neo4j.graphdb.traversal.Evaluator;
import org.springframework.data.neo4j.core.EntityPath;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
/**
* @author mh
* @since 26.02.11
*/
public abstract class EntityEvaluator<S, E> implements Evaluator {
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
@Override
public Evaluation evaluate(Path path) {
return evaluate(new ConvertingEntityPath<S,E>(graphDatabaseContext, path));
return evaluate(new ConvertingEntityPath<S,E>(template, path));
}
public abstract Evaluation evaluate(EntityPath<S,E> path);

View File

@@ -19,29 +19,29 @@ package org.springframework.data.neo4j.support.path;
import org.neo4j.graphdb.Path;
import org.springframework.data.neo4j.core.EntityPath;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.data.neo4j.support.Neo4jTemplate;
/**
* @author mh
* @since 26.02.11
*/
public abstract class EntityMapper<S, E, T> implements PathMapper<T> {
private GraphDatabaseContext graphDatabaseContext;
private Neo4jTemplate template;
protected EntityMapper(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
protected EntityMapper(Neo4jTemplate template) {
this.template = template;
}
public abstract T mapPath(EntityPath<S,E> entityPath);
@Override
public T mapPath(Path path) {
return mapPath(new ConvertingEntityPath<S,E>(graphDatabaseContext, path));
return mapPath(new ConvertingEntityPath<S,E>(template, path));
}
public abstract static class WithoutResult<S,E> extends EntityMapper<S,E,Void> {
protected WithoutResult(GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext);
protected WithoutResult(Neo4jTemplate template) {
super(template);
}
@Override

Some files were not shown because too many files have changed in this diff Show More