added configuration for cross-store submodule, fixed aspect related changed

This commit is contained in:
Michael Hunger
2011-10-02 19:23:30 +02:00
parent bdf51f21dd
commit 479e72c8f7
15 changed files with 254 additions and 52 deletions

View File

@@ -41,6 +41,12 @@
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<!-- Logging -->
<dependency>
@@ -87,6 +93,35 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-cypher</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>server-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-core</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-neo4j-graph</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.tinkerpop</groupId>
<artifactId>gremlin</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
@@ -206,10 +241,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
<aspectLibrary>
<!--aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-data-neo4j-aspects</artifactId>
</aspectLibrary>
</aspectLibrary-->
</aspectLibraries>
<source>1.6</source>
<target>1.6</target>

View File

@@ -1,3 +1,18 @@
/**
* 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.config;
import org.springframework.context.annotation.Bean;

View File

@@ -26,7 +26,7 @@ import org.springframework.data.neo4j.support.ManagedEntity;
* @author Michael Hunger
* @since 21.09.2010
*/
public interface GraphBacked<STATE> extends ManagedEntity<STATE> {
public interface GraphBacked<STATE,ENTITY extends GraphBacked<STATE,ENTITY>> extends ManagedEntity<STATE,ENTITY> {
/**
* internal setter used for initializing the graph-db state on existing or newly created entities
*

View File

@@ -19,8 +19,6 @@ package org.springframework.data.neo4j.core;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.springframework.data.neo4j.support.node.Neo4jNodeBacking;
import org.springframework.data.neo4j.support.query.CypherQueryExecutor;
import java.util.Map;
@@ -30,7 +28,7 @@ import java.util.Map;
*
* @author Rod Johnson
*/
public interface NodeBacked extends GraphBacked<Node> {
public interface NodeBacked extends GraphBacked<Node,NodeBacked> {
/**
* Attach the entity inside a running transaction. Creating or changing an entity outside of a transaction

View File

@@ -22,7 +22,7 @@ import org.neo4j.graphdb.Relationship;
* concrete interface introduced onto Relationship entities by the {@link org.springframework.data.neo4j.support.relationship.Neo4jRelationshipBacking}
* aspect, encapsulates a neo4j relationship as backing state
*/
public interface RelationshipBacked extends GraphBacked<Relationship>{
public interface RelationshipBacked extends GraphBacked<Relationship,RelationshipBacked>{
/**
* @return the id of the underlying relationship or null if there is none

View File

@@ -22,7 +22,6 @@ import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.FieldSignature;
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.Path;
import org.neo4j.helpers.collection.IterableWrapper;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.traversal.TraversalDescription;
@@ -39,6 +38,7 @@ import org.springframework.data.neo4j.annotation.GraphTraversal;
import org.springframework.data.neo4j.core.NodeBacked;
import org.springframework.data.neo4j.core.RelationshipBacked;
import org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper;
import org.springframework.data.neo4j.support.DoReturn;
import org.springframework.data.neo4j.core.EntityPath;
import org.springframework.data.neo4j.core.EntityState;
@@ -196,20 +196,10 @@ public privileged aspect Neo4jNodeBacking { // extends AbstractTypeAnnotatingMix
private Iterable<?> convertToGraphEntity(Traverser traverser, final Class<?> targetType) {
final GraphDatabaseContext ctx = Neo4jNodeBacking.aspectOf().graphDatabaseContext;
if (NodeBacked.class.isAssignableFrom(targetType)) {
return new IterableWrapper<Object,Node>(traverser.nodes()) {
@Override
protected Object underlyingObjectToObject(Node node) {
return ctx.createEntityFromState(node,(Class<? extends NodeBacked>)targetType);
}
};
return GraphBackedEntityIterableWrapper.create(traverser.nodes(), (Class<? extends NodeBacked>) targetType, ctx);
}
if (RelationshipBacked.class.isAssignableFrom(targetType)) {
return new IterableWrapper<Object,Relationship>(traverser.relationships()) {
@Override
protected Object underlyingObjectToObject(Relationship relationship) {
return ctx.createEntityFromState(relationship,(Class<? extends RelationshipBacked>)targetType);
}
};
return GraphBackedEntityIterableWrapper.create(traverser.relationships(), (Class<? extends RelationshipBacked>) targetType, ctx);
}
throw new IllegalStateException("Can't determine valid type for traversal target "+targetType);

View File

@@ -22,6 +22,7 @@ import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.FieldSignature;
import org.neo4j.graphdb.Relationship;
import org.springframework.data.neo4j.annotation.RelationshipEntity;
import org.springframework.data.neo4j.core.NodeBacked;
import org.springframework.data.neo4j.core.RelationshipBacked;
import org.springframework.data.neo4j.support.DoReturn;
import org.springframework.data.neo4j.core.EntityState;
@@ -118,6 +119,10 @@ public aspect Neo4jRelationshipBacking {
return getPersistentState().hashCode();
}
public <T extends RelationshipBacked> T RelationshipBacked.persist() {
return (T)this.entityState.persist();
}
public void RelationshipBacked.remove() {
Neo4jRelationshipBacking.aspectOf().graphDatabaseContext.removeRelationshipEntity(this);
}

View File

@@ -164,21 +164,23 @@ public class ModificationOutsideOfTransactionTest
assertEquals( 35, nodeFor( p ).getProperty("age") );
}
@Ignore
@Test
public void shouldWorkWithUninitializedCollectionFieldWithoutUnderlyingState()
{
@Test
public void shouldWorkWithUninitializedCollectionFieldWithoutUnderlyingState() {
Group group = new Group();
Collection<Person> people = group.getPersons();
assertNotNull(people);
Collection<Person> people = group.getPersons();
assertNotNull(people);
Person p = new Person( "David", 27 );
people.add(p);
Person p = new Person("David", 27);
people.add(p);
assertEquals( Collections.singleton(p), group.getPersons() );
assertEquals(Collections.singleton(p), group.getPersons());
group.persist();
assertThat(group.getPersistentState(), hasRelationship("persons", p.getPersistentState()));
assertThat(p.getPersistentState(), hasRelationship("persons", group.getPersistentState()));
}
@Test
@Test
public void shouldWorkWithInitializedCollectionFieldWithoutUnderlyingState()
{
Group group = new Group();
@@ -190,6 +192,11 @@ public class ModificationOutsideOfTransactionTest
people.add(p);
assertEquals( Collections.singleton(p), group.getPersons() );
group.persist();
assertThat(group.getPersistentState(), hasRelationship("persons", p.getPersistentState()));
assertThat(p.getPersistentState(), hasRelationship("persons", group.getPersistentState()));
}
@Test

View File

@@ -86,18 +86,27 @@
<bean id="graphDatabaseContext" class="org.springframework.data.neo4j.support.GraphDatabaseContext">
<property name="graphDatabaseService" ref="graphDatabaseService"/>
<property name="conversionService" ref="conversionService"/>
<property name="entityStateHandler" ref="entityStateHandler"/>
<property name="nodeTypeRepresentationStrategy" ref="nodeTypeRepresentationStrategy"/>
<property name="relationshipTypeRepresentationStrategy" ref="relationshipTypeRepresentationStrategy"/>
<property name="validator">
<bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
</property>
<property name="mappingContext" ref="mappingContext"/>
</bean>
<bean id="relationshipEntityInstantiator"
class="org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator"/>
<bean id="graphEntityInstantiator"
class="org.springframework.data.neo4j.support.node.NodeEntityInstantiator"/>
<bean id="entityStateHandler" class="org.springframework.data.neo4j.support.EntityStateHandler">
<constructor-arg ref="mappingContext"/>
<constructor-arg ref="graphDatabaseService"/>
</bean>
<bean id="relationshipEntityInstantiator" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator">
<constructor-arg ref="entityStateHandler"/>
</bean>
<bean id="graphEntityInstantiator" class="org.springframework.data.neo4j.support.node.NodeEntityInstantiator">
<constructor-arg ref="entityStateHandler"/>
</bean>
<bean id="typeRepresentationStrategyFactory" class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory">
<constructor-arg ref="graphDatabaseService"/>
@@ -118,6 +127,10 @@
<property name="mappingContext" ref="mappingContext"/>
</bean>
<!--bean id="neo4jNodeConverter" class="org.springframework.data.neo4j.mapping.Neo4jNodeConverterImpl">
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
</bean-->
<bean id="mappingContext" class="org.springframework.data.neo4j.mapping.Neo4jMappingContext"/>
<bean id="relationshipEntityStateFactory" class="org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory">

View File

@@ -14,6 +14,10 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="noopNodeStrategy" class="org.springframework.data.neo4j.support.typerepresentation.NoopNodeTypeRepresentationStrategy" />
<bean id="noopRelationshipStrategy" class="org.springframework.data.neo4j.support.typerepresentation.NoopRelationshipTypeRepresentationStrategy" />
<bean id="noopNodeStrategy" class="org.springframework.data.neo4j.support.typerepresentation.NoopNodeTypeRepresentationStrategy">
<constructor-arg ref="graphEntityInstantiator"/>
</bean>
<bean id="noopRelationshipStrategy" class="org.springframework.data.neo4j.support.typerepresentation.NoopRelationshipTypeRepresentationStrategy">
<constructor-arg ref="relationshipEntityInstantiator"/>
</bean>
</beans>

View File

@@ -16,6 +16,7 @@
<bean id="graphEntityInstantiator"
class="org.springframework.data.neo4j.support.node.NodeEntityInstantiator">
<constructor-arg ref="entityStateHandler"/>
<property name="instantiators">
<map>
<entry key="org.springframework.data.neo4j.Person">

View File

@@ -0,0 +1,39 @@
Bundle-SymbolicName: org.springframework.data.neo4j.aspects
Bundle-Name: Spring Data Neo4j Aspects
Bundle-Vendor: SpringSource
Bundle-ManifestVersion: 2
Import-Package:
sun.reflect;version="0";resolution:=optional
Import-Template:
org.springframework.beans.*;version="[3.0.0, 4.0.0)",
org.springframework.context.*;version="[3.0.0, 4.0.0)",
org.springframework.core.*;version="[3.0.0, 4.0.0)",
org.springframework.dao.*;version="[3.0.0, 4.0.0)",
org.springframework.jdbc.*;version="[3.0.0, 4.0.0)",
org.springframework.stereotype.*;version="[3.0.0, 4.0.0)",
org.springframework.orm.*;version="[3.0.0, 4.0.0)",
org.springframework.transaction.*;version="[3.0.0, 4.0.0)",
org.springframework.util.*;version="[3.0.0, 4.0.0)",
org.springframework.data.*;version="[1.0.0, 2.0.0)",
org.springframework.persistence.*;version="[1.0.0, 3.0.0)",
org.springframework.data.neo4j.*;version="[1.0.0, 3.0.0)",
org.neo4j.*;version="0",
org.neo4j.cypher.*;version="0";resolution:=optional,
org.w3c.dom.*;version="0",
org.aspectj.*;version="[1.6.5, 2.0.0)",
org.apache.commons.logging.*;version="[1.1.1, 2.0.0)",
org.apache.commons.configuration.*;version="0",
org.objectweb.jotm.*;version="0",
org.apache.lucene.*;version="0",
javax.validation.*;version="0";resolution:=optional,
javax.annotation.*;version="0";resolution:=optional,
javax.naming.*;version="0";resolution:=optional,
javax.script.*;version="0";resolution:=optional,
javax.persistence.*;version="[1.0.0, 3.0.0)";resolution:=optional,
javax.persistence.spi.*;version="[1.0.0, 3.0.0)";resolution:=optional,
javax.transaction.*;version="[1.0.1, 2.0.0)";resolution:=optional
Import-Package:
net.sf.cglib.proxy;version="[2.2.0,3.0.0)",
net.sf.cglib.core;version="[2.2.0,3.0.0)",
net.sf.cglib.reflect;version="[2.2.0,3.0.0)"
DynamicImport-Package: *

View File

@@ -0,0 +1,66 @@
/**
* 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.config;
import org.junit.Assert;
import org.junit.Test;
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.repository.DirectGraphRepositoryFactory;
import org.springframework.data.neo4j.support.GraphDatabaseContext;
import org.springframework.transaction.PlatformTransactionManager;
/**
* @author mh
* @since 31.01.11
*/
public class DataGraphNamespaceHandlerCrossStoreTest {
static class Config {
@Autowired
GraphDatabaseService graphDatabaseService;
@Autowired
DirectGraphRepositoryFactory graphRepositoryFactory;
@Autowired
GraphDatabaseContext graphDatabaseContext;
@Autowired
PlatformTransactionManager transactionManager;
}
@Test
public void injectionForCrossStore() {
assertInjected("-cross-store");
}
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();
Assert.assertEquals("store-dir", "target/config-test", graphDatabaseService.getStoreDir());
Assert.assertNotNull("graphRepositoryFactory", config.graphRepositoryFactory);
Assert.assertNotNull("graphDatabaseService", config.graphDatabaseService);
Assert.assertNotNull("transactionManager", config.transactionManager);
config.graphDatabaseService.shutdown();
return config;
}
}

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<neo4j:config storeDirectory="target/config-test" entityManagerFactory="entityManagerFactory"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
</bean>
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:test"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean id="config" class="org.springframework.data.neo4j.config.DataGraphNamespaceHandlerTest$Config"/>
</beans>

View File

@@ -125,7 +125,7 @@
<org.slf4j.version>1.6.1</org.slf4j.version>
<org.springframework.version>3.0.6.RELEASE</org.springframework.version>
<data.commons.version>1.2.0.BUILD-SNAPSHOT</data.commons.version>
<neo4j.version>1.4.1</neo4j.version>
<neo4j.version>1.5-SNAPSHOT</neo4j.version>
<aspectj.version>1.6.12.M1</aspectj.version>
<blueprints.version>0.8</blueprints.version>
<gremlin.version>1.1</gremlin.version>
@@ -593,20 +593,20 @@
</mapping>
</configuration>
</plugin>
<plugin>
<!--
configures the springsource bundlor plugin, which generates
OSGI-compatible MANIFEST.MF files during the 'compile' phase of
the maven build. this plugin is declared within the
pluginManagement section because not every module that inherits
from this pom needs bundlor's services, e.g.:
spring-integration-samples and all its children. for this reason,
all modules that wish to use bundlor must declare it explicitly.
it is not necessary to specify the <version> or <configuration>
sections, but groupId and artifactId are required. see
http://static.springsource.org/s2-bundlor/1.0.x/user-guide/html/ch04s03.html
for more info
-->
<!--
configures the springsource bundlor plugin, which generates
OSGI-compatible MANIFEST.MF files during the 'compile' phase of
the maven build. this plugin is declared within the
pluginManagement section because not every module that inherits
from this pom needs bundlor's services, e.g.:
spring-integration-samples and all its children. for this reason,
all modules that wish to use bundlor must declare it explicitly.
it is not necessary to specify the <version> or <configuration>
sections, but groupId and artifactId are required. see
http://static.springsource.org/s2-bundlor/1.0.x/user-guide/html/ch04s03.html
for more info
-->
<!--plugin>
<groupId>com.springsource.bundlor</groupId>
<artifactId>com.springsource.bundlor.maven</artifactId>
<version>1.0.0.RELEASE</version>
@@ -621,7 +621,7 @@
</goals>
</execution>
</executions>
</plugin>
</plugin-->
</plugins>
</build>
<pluginRepositories>