Removed hello-worlds-aspects project, implemented 2 profiles for hello-worlds: aspects and plain. The code doesn't work as expected. Commiting just for back-up
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -156,7 +156,6 @@
|
||||
<id>examples</id>
|
||||
<modules>
|
||||
<module>spring-data-neo4j-examples/hello-worlds</module>
|
||||
<module>spring-data-neo4j-examples/hello-worlds-aspects</module>
|
||||
<module>spring-data-neo4j-examples/imdb</module>
|
||||
<module>spring-data-neo4j-examples/cineasts</module>
|
||||
<module>spring-data-neo4j-examples/cineasts-aspects</module>
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
lib
|
||||
.ivy
|
||||
.gradle
|
||||
target
|
||||
*.ipr
|
||||
*.iml
|
||||
*.iws
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
Hello Worlds
|
||||
============
|
||||
|
||||
A simple Spring Data Neo4j example with just enough code to
|
||||
do something that works.
|
||||
|
||||
This version of the project takes advantage of the niceties
|
||||
provided by spring-data-neo4j-aspects, which enhances the
|
||||
Plain Old Java Objects into Deluxe Aspect Java Objects.
|
||||
|
||||
Build and Run
|
||||
-------------
|
||||
|
||||
`mvn clean package exec:java`
|
||||
@@ -1,27 +0,0 @@
|
||||
sourceCompatibility = 1.6
|
||||
targetCompatibility = 1.6
|
||||
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
|
||||
springVersion = "3.0.7.RELEASE"
|
||||
springDataNeo4jVersion = "2.0.0.RELEASE"
|
||||
aspectjVersion = "1.6.12"
|
||||
|
||||
apply from:'https://github.com/SpringSource/spring-data-neo4j/raw/master/build/gradle/springdataneo4j.gradle'
|
||||
|
||||
configurations {
|
||||
runtime
|
||||
testCompile
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
mavenRepo urls: "http://maven.springframework.org/release"
|
||||
}
|
||||
|
||||
|
||||
dependencies{
|
||||
testCompile group:"junit", name: "junit", version: "4.8"
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<project name="spring-data-neo4j-example" default="test" xmlns:ivy="antlib:org.apache.ivy.ant" basedir=".">
|
||||
<property name="settings.dir" location="settings" />
|
||||
<property name="lib.dir" location="lib" />
|
||||
|
||||
<import file="${settings.dir}/path.xml" />
|
||||
|
||||
<import file="${settings.dir}/install-ivy.xml" />
|
||||
<import file="${settings.dir}/path.xml" />
|
||||
|
||||
<taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties" classpath="${lib.dir}/aspectjtools.jar"/>
|
||||
|
||||
<target name="lib.retrieve" depends="install-ivy">
|
||||
<mkdir dir="${lib.dir}" />
|
||||
<ivy:settings file="${settings.dir}/ivysettings.xml" />
|
||||
<ivy:resolve file="${settings.dir}/ivy.xml" />
|
||||
<ivy:retrieve type="jar" pattern="${lib.dir}/[artifact].[ext]" changing="true"/>
|
||||
<ivy:retrieve type="bundle" pattern="${lib.dir}/[artifact].[ext]" changing="true"/>
|
||||
</target>
|
||||
|
||||
<target name="lib.clean">
|
||||
<delete dir="${lib.dir}" />
|
||||
</target>
|
||||
|
||||
<target name="clean" description="Removes the build directory, but not any cached ivy dependencies">
|
||||
<delete dir="target" />
|
||||
<delete dir="build" />
|
||||
</target>
|
||||
|
||||
<target name="compile" description="Compile production classes" depends="lib.retrieve">
|
||||
<mkdir dir="${main.target}" />
|
||||
|
||||
<iajc sourceroots="${main.src}" destDir="${main.target}" classpathref="path.libs" source="1.6">
|
||||
<aspectpath>
|
||||
<pathelement location="${lib.dir}/spring-aspects.jar"/>
|
||||
</aspectpath>
|
||||
<aspectpath>
|
||||
<pathelement location="${lib.dir}/spring-data-neo4j.jar"/>
|
||||
</aspectpath>
|
||||
</iajc>
|
||||
</target>
|
||||
|
||||
<target name="compile-tests" description="Compile unit test classes" depends="compile">
|
||||
<mkdir dir="${test.target}" />
|
||||
<copy todir="${main.target}" failonerror="false">
|
||||
<fileset dir="${main.resources}"/>
|
||||
</copy>
|
||||
<iajc sourceroots="${test.src}" destDir="${test.target}" classpathref="path.testing" source="1.6">
|
||||
<aspectpath>
|
||||
<pathelement location="${lib.dir}/spring-aspects.jar"/>
|
||||
</aspectpath>
|
||||
<aspectpath>
|
||||
<pathelement location="${lib.dir}/spring-data-neo4j.jar"/>
|
||||
</aspectpath>
|
||||
</iajc>
|
||||
</target>
|
||||
|
||||
<target name="test" depends="clean, compile, compile-tests">
|
||||
<mkdir dir="${test.reports}"/>
|
||||
<copy todir="${test.target}" failonerror="false">
|
||||
<fileset dir="${test.resources}" includes="**/*"/>
|
||||
</copy>
|
||||
|
||||
<fileset id="unittest.source.files" dir="${test.src}">
|
||||
<include name="**/*Test.java" />
|
||||
</fileset>
|
||||
|
||||
<junit printsummary="yes" showoutput="true" dir="." outputtoformatters="false">
|
||||
<classpath refid="path.testing"/>
|
||||
<formatter type="plain" />
|
||||
<batchtest fork="no" todir="${test.reports}">
|
||||
<fileset refid="unittest.source.files"/>
|
||||
</batchtest>
|
||||
</junit>
|
||||
</target>
|
||||
</project>
|
||||
@@ -1,210 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.springframework.data.examples</groupId>
|
||||
<artifactId>spring-data-neo4j-hello-worlds-aspects</artifactId>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Spring Data Neo4j hello-worlds Aspects</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.version>3.0.7.RELEASE</spring.version>
|
||||
<aspectj.version>1.6.12</aspectj.version>
|
||||
<slf4j.version>1.6.1</slf4j.version>
|
||||
<spring-data-neo4j.version>${project.version}</spring-data-neo4j.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-maven-release</id>
|
||||
<name>Spring Maven Release Repository</name>
|
||||
<url>http://maven.springframework.org/release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-maven-snapshot</id>
|
||||
<name>Spring Maven Snapshot Repository</name>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>http://maven.springframework.org/snapshot</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-maven-milestone</id>
|
||||
<name>Spring Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>neo4j-release-repository</id>
|
||||
<name>Neo4j Maven 2 release repository</name>
|
||||
<url>http://m2.neo4j.org/releases</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>neo4j-snapshot-repository</id>
|
||||
<name>Neo4j Maven 2 snapshot repository</name>
|
||||
<url>http://m2.neo4j.org/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-maven-release</id>
|
||||
<name>Spring Maven Release Repository</name>
|
||||
<url>http://maven.springframework.org/release</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-maven-milestone</id>
|
||||
<name>Spring Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j-aspects</artifactId>
|
||||
<version>${spring-data-neo4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib-nodep</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!-- Must use java 1.5 or higher for annotations -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<!-- required to resolve aspectj-enhanced class features -->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<configuration>
|
||||
<outxml>true</outxml>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjtools</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
<!-- the eclipse plugin interacts with the aspectj-maven-plugin
|
||||
BUT ONLY if the ajdtVersion config value is set (remove it and it won't) -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
<configuration>
|
||||
<!-- The ajdtVersion configuration parameter is optional. The valid values are none, 1.4, and 1.5. none indicates that AJDT should not be enabled even though Aspectj is enabled in maven. 1.4 generates the org.eclipse.ajdt.ui.prefs file in the .settings directory. 1.5 (or later) includes the configuration into the .classpath file and is the default value. -->
|
||||
<ajdtVersion>1.5</ajdtVersion>
|
||||
<additionalProjectnatures>
|
||||
<projectnature>org.eclipse.ajdt.ui.ajnature</projectnature>
|
||||
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
|
||||
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
|
||||
</additionalProjectnatures>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<!-- IntelliJ Idea Support -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-idea-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<downloadSources>true</downloadSources>
|
||||
<dependenciesAsLibraries>true</dependenciesAsLibraries>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<!-- Execute the main class -->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<mainClass>org.springframework.data.neo4j.examples.hellograph.App</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,29 +0,0 @@
|
||||
<project xmlns:ivy="antlib:org.apache.ivy.ant" basedir="..">
|
||||
|
||||
<property name="ivy.install.version" value="2.2.0" />
|
||||
<property name="ivy.jar.dir" location="${basedir}/.ivy" />
|
||||
<property name="ivy.jar.file" location="${ivy.jar.dir}/ivy.jar" />
|
||||
<property name="ivy.cache.dir" location="${basedir}/.ivy/cache" />
|
||||
|
||||
<target name="download-ivy" unless="skip.download">
|
||||
<mkdir dir="${ivy.jar.dir}"/>
|
||||
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
|
||||
dest="${ivy.jar.file}" usetimestamp="true"/>
|
||||
</target>
|
||||
|
||||
<target name="install-ivy" depends="download-ivy">
|
||||
<path id="ivy.lib.path">
|
||||
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
|
||||
</path>
|
||||
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
|
||||
</target>
|
||||
|
||||
<target name="clean-ivy">
|
||||
<delete dir="${ivy.jar.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="clean-ivy-cache" depends="install-ivy">
|
||||
<ivy:cleancache />
|
||||
</target>
|
||||
|
||||
</project>
|
||||
@@ -1,14 +0,0 @@
|
||||
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
|
||||
<info organisation="org.springframework.data.neo4j.examples" module="hello-worlds"/>
|
||||
<dependencies>
|
||||
<dependency org="org.springframework.data" name="spring-data-neo4j" rev="2.0.0.RELEASE">
|
||||
<exclude module="jms"/>
|
||||
<exclude module="jmxtools"/>
|
||||
<exclude module="jmxri"/>
|
||||
</dependency>
|
||||
<dependency org="org.aspectj" name="aspectjrt" rev="1.6.12"/>
|
||||
<dependency org="org.aspectj" name="aspectjtools" rev="1.6.12"/>
|
||||
<dependency org="org.neo4j" name="neo4j-community" rev="1.6"/>
|
||||
<dependency org="junit" name="junit" rev="4.8.1"/>
|
||||
</dependencies>
|
||||
</ivy-module>
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<ivysettings>
|
||||
<settings defaultResolver="chained"/>
|
||||
<property name="local-maven2-pattern"
|
||||
value="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]"
|
||||
override="false" />
|
||||
|
||||
<resolvers>
|
||||
<chain name="chained" returnFirst="false">
|
||||
<filesystem name="local-maven2" m2compatible="true" >
|
||||
<ivy pattern="${local-maven2-pattern}"/>
|
||||
<artifact pattern="${local-maven2-pattern}"/>
|
||||
</filesystem>
|
||||
<ibiblio name="neo4j" root="http://m2.neo4j.org/releases" m2compatible="true"/>
|
||||
<ibiblio name="maven_central" root="http://repo2.maven.org/maven2/" m2compatible="true"/>
|
||||
<ibiblio name="jboss" root="http://repository.jboss.org/nexus/content/groups/public/" m2compatible="true"/>
|
||||
<ibiblio name="springframework" root="http://maven.springframework.org/release" m2compatible="true"/>
|
||||
</chain>
|
||||
</resolvers>
|
||||
<caches>
|
||||
<cache name="default-cache" basedir="${ivy.cache.dir}" />
|
||||
</caches>
|
||||
</ivysettings>
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" ?>
|
||||
|
||||
<project name="path" default="donothingToMakeAValidAntFile"
|
||||
basedir=".">
|
||||
|
||||
<property name="main.src" location="src/main/java" />
|
||||
<property name="main.resources" location="src/main/resources" />
|
||||
<property name="main.target" location="target/main/classes" />
|
||||
|
||||
<property name="test.src" location="src/test/java" />
|
||||
<property name="test.target" location="target/test/classes" />
|
||||
<property name="test.reports" location="target/test/reports" />
|
||||
<property name="test.resources" location="src/test/resources" />
|
||||
|
||||
<target name="donothingToMakeAValidAntFile" />
|
||||
|
||||
<path id="path.libs">
|
||||
<fileset dir="lib" />
|
||||
</path>
|
||||
|
||||
<path id="path.compile">
|
||||
<path refid="path.libs" />
|
||||
<dirset dir="${main.target}" />
|
||||
</path>
|
||||
|
||||
<path id="path.testing">
|
||||
<path refid="path.compile" />
|
||||
<dirset dir="${test.target}"/>
|
||||
</path>
|
||||
</project>
|
||||
@@ -1,30 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("/spring/helloWorldContext.xml");
|
||||
|
||||
MyWorldRepository galaxy = applicationContext.getBean(WorldRepositoryImpl.class);
|
||||
galaxy.makeSureGalaxyIsNotEmpty();
|
||||
|
||||
System.out.println("Trying to find the Earth by its name:");
|
||||
World earth = galaxy.findWorldNamed("Earth");
|
||||
System.out.printf("Found Earth: %s\n", earth);
|
||||
|
||||
System.out.println("Retrieveing the list of worlds that can be reached from the Earth:");
|
||||
for(World world : earth.getReachableWorlds()) {
|
||||
System.out.printf("Can travel between %s and %s\n", earth, world);
|
||||
}
|
||||
|
||||
System.out.println("Here's the list of all worlds in the galaxy:");
|
||||
for(World world : galaxy.findAllWorlds()) {
|
||||
System.out.printf("There's a world: %s\n", world);
|
||||
}
|
||||
|
||||
applicationContext.close();
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class GalaxyMapper {
|
||||
public WorldDto worldDtoFromWorld(World world) {
|
||||
if(world == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new WorldDto(world.getId(), world.getName(), world.getMoons());
|
||||
}
|
||||
|
||||
public List<WorldDto> worldDtosFromWorlds(Iterable<World> worlds) {
|
||||
List<WorldDto> worldDtos = new ArrayList<WorldDto>();
|
||||
for(World world : worlds) {
|
||||
WorldDto worldDto = worldDtoFromWorld(world);
|
||||
worldDtos.add(worldDto);
|
||||
}
|
||||
|
||||
return worldDtos;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class GalaxyService {
|
||||
@Autowired
|
||||
private WorldRepository worldRepository;
|
||||
|
||||
@Autowired
|
||||
private GalaxyMapper mapper;
|
||||
|
||||
@Transactional
|
||||
public void makeSureGalaxyIsNotEmpty() {
|
||||
// Solar worlds
|
||||
resolveWorld("Mercury", 0);
|
||||
resolveWorld("Venus", 0);
|
||||
|
||||
World earth = resolveWorld("Earth", 1);
|
||||
World mars = resolveWorld("Mars", 2);
|
||||
mars.addRocketRouteTo(earth);
|
||||
|
||||
resolveWorld("Jupiter", 63);
|
||||
resolveWorld("Saturn", 62);
|
||||
resolveWorld("Uranus", 27);
|
||||
resolveWorld("Neptune", 13);
|
||||
|
||||
// Norse worlds
|
||||
resolveWorld("Alfheimr", 0);
|
||||
resolveWorld("Midgard", 1);
|
||||
resolveWorld("Muspellheim", 2);
|
||||
resolveWorld("Asgard", 63);
|
||||
resolveWorld("Hel", 62);
|
||||
}
|
||||
|
||||
private World resolveWorld(String name, int moons) {
|
||||
World createdWorld = worldRepository.findByPropertyValue("name", name);
|
||||
if (createdWorld == null) {
|
||||
createdWorld = new World(name, moons);
|
||||
createdWorld = worldRepository.save(createdWorld);
|
||||
}
|
||||
return createdWorld;
|
||||
}
|
||||
|
||||
public WorldDto findWorldNamed(String name) {
|
||||
World world = worldRepository.findByPropertyValue("name", name);
|
||||
return mapper.worldDtoFromWorld(world);
|
||||
}
|
||||
|
||||
public List<WorldDto> findReachableWorlds(Long worldId) {
|
||||
World world = worldRepository.findOne(worldId);
|
||||
return mapper.worldDtosFromWorlds(world.getReachableWorlds());
|
||||
}
|
||||
|
||||
public List<WorldDto> findAllWorlds() {
|
||||
Iterable<World> worlds = worldRepository.findAll();
|
||||
return mapper.worldDtosFromWorlds(worlds);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public interface MyWorldRepository {
|
||||
@Transactional
|
||||
void makeSureGalaxyIsNotEmpty();
|
||||
|
||||
World findWorldNamed(String name);
|
||||
|
||||
Iterable<World> findAllWorlds();
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
public abstract class RelationshipTypes {
|
||||
public static final String REACHABLE_BY_ROCKET = "REACHABLE_BY_ROCKET";
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
|
||||
import org.neo4j.graphdb.Direction;
|
||||
import org.springframework.data.neo4j.annotation.Indexed;
|
||||
import org.springframework.data.neo4j.annotation.NodeEntity;
|
||||
import org.springframework.data.neo4j.annotation.RelatedTo;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@NodeEntity
|
||||
public class World {
|
||||
@Indexed
|
||||
private String name;
|
||||
|
||||
private int moons;
|
||||
|
||||
@RelatedTo(type = RelationshipTypes.REACHABLE_BY_ROCKET, elementClass = World.class, direction = Direction.BOTH)
|
||||
private Set<World> reachableByRocket;
|
||||
|
||||
public World(String name, int moons) {
|
||||
this.name = name;
|
||||
this.moons = moons;
|
||||
}
|
||||
|
||||
public World() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getMoons() {
|
||||
return moons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("World{name='%s', moons=%d}", name, moons);
|
||||
}
|
||||
|
||||
public void addRocketRouteTo(World otherWorld) {
|
||||
relateTo(otherWorld, RelationshipTypes.REACHABLE_BY_ROCKET);
|
||||
}
|
||||
|
||||
public Iterable<World> getReachableWorlds() {
|
||||
return reachableByRocket;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
public class WorldDto {
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final int moons;
|
||||
|
||||
public WorldDto(Long id, String name, int moons) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.moons = moons;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getMoons() {
|
||||
return moons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("WorldDto{id=%d, name='%s', moons=%d}", id, name, moons);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
import org.springframework.data.neo4j.repository.GraphRepository;
|
||||
|
||||
/**
|
||||
* @author mh
|
||||
* @since 01.04.11
|
||||
*/
|
||||
public interface WorldRepository extends MyWorldRepository, GraphRepository<World> {
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Spring Data Neo4j backed application context for Worlds.
|
||||
*/
|
||||
public class WorldRepositoryImpl implements MyWorldRepository {
|
||||
|
||||
@Autowired
|
||||
private WorldRepository worldRepository;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void makeSureGalaxyIsNotEmpty() {
|
||||
// Solar worlds
|
||||
resolveWorld("Mercury", 0);
|
||||
resolveWorld("Venus", 0);
|
||||
|
||||
World earth = resolveWorld("Earth", 1);
|
||||
World mars = resolveWorld("Mars", 2);
|
||||
mars.addRocketRouteTo(earth);
|
||||
|
||||
resolveWorld("Jupiter", 63);
|
||||
resolveWorld("Saturn", 62);
|
||||
resolveWorld("Uranus", 27);
|
||||
resolveWorld("Neptune", 13);
|
||||
|
||||
// Norse worlds
|
||||
resolveWorld("Alfheimr", 0);
|
||||
resolveWorld("Midgard", 1);
|
||||
resolveWorld("Muspellheim", 2);
|
||||
resolveWorld("Asgard", 63);
|
||||
resolveWorld("Hel", 62);
|
||||
}
|
||||
|
||||
private World resolveWorld(String name, int moons) {
|
||||
World createdWorld = findWorldNamed(name);
|
||||
if (createdWorld == null) {
|
||||
createdWorld = new World(name, moons).persist();
|
||||
}
|
||||
return createdWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World findWorldNamed(String name) {
|
||||
return worldRepository.findByPropertyValue("name", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<World> findAllWorlds() {
|
||||
return worldRepository.findAll();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
|
||||
# Print the date in ISO 8601 format
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
|
||||
|
||||
log4j.rootLogger=ERROR, stdout
|
||||
@@ -1,58 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
|
||||
@ContextConfiguration(locations = "classpath:/spring/helloWorldContext.xml")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class GalaxyServiceTest {
|
||||
|
||||
@Autowired
|
||||
private GalaxyService galaxyService;
|
||||
|
||||
@Autowired
|
||||
private Neo4jTemplate template;
|
||||
|
||||
@Before
|
||||
public void cleanUpGraph() {
|
||||
Neo4jHelper.cleanDb(template);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void galaxyShouldBeEmptyUntilExplicitlyPopulated() {
|
||||
assertTrue(galaxyService.findAllWorlds().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void populatedGalaxyShouldHaveEarth() {
|
||||
galaxyService.makeSureGalaxyIsNotEmpty();
|
||||
WorldDto earth = galaxyService.findWorldNamed("Earth");
|
||||
assertNotNull(earth);
|
||||
assertEquals("Earth", earth.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void earthShouldHaveOnlyOneReachableWorld() {
|
||||
galaxyService.makeSureGalaxyIsNotEmpty();
|
||||
WorldDto earth = galaxyService.findWorldNamed("Earth");
|
||||
List<WorldDto> reachableWorlds = galaxyService.findReachableWorlds(earth.getId());
|
||||
assertEquals(1, reachableWorlds.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void populatedGalaxyShouldNotHaveKrypton() {
|
||||
galaxyService.makeSureGalaxyIsNotEmpty();
|
||||
WorldDto planetPopsicle = galaxyService.findWorldNamed("Krypton");
|
||||
assertNull(planetPopsicle);
|
||||
}
|
||||
}
|
||||
@@ -1,178 +1,300 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.springframework.data.examples</groupId>
|
||||
<artifactId>spring-data-neo4j-hello-worlds</artifactId>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<groupId>org.springframework.data.examples</groupId>
|
||||
<artifactId>spring-data-neo4j-hello-worlds</artifactId>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Spring Data Neo4j hello-worlds</name>
|
||||
<name>Spring Data Neo4j hello-worlds</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.version>3.0.7.RELEASE</spring.version>
|
||||
<aspectj.version>1.6.12</aspectj.version>
|
||||
<slf4j.version>1.6.1</slf4j.version>
|
||||
<spring-data-neo4j.version>${project.version}</spring-data-neo4j.version>
|
||||
</properties>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.version>3.0.7.RELEASE</spring.version>
|
||||
<aspectj.version>1.6.12</aspectj.version>
|
||||
<slf4j.version>1.6.1</slf4j.version>
|
||||
<spring-data-neo4j.version>${project.version}</spring-data-neo4j.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-maven-release</id>
|
||||
<name>Spring Maven Release Repository</name>
|
||||
<url>http://maven.springframework.org/release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-maven-snapshot</id>
|
||||
<name>Spring Maven Snapshot Repository</name>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>http://maven.springframework.org/snapshot</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-maven-milestone</id>
|
||||
<name>Spring Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>neo4j-release-repository</id>
|
||||
<name>Neo4j Maven 2 release repository</name>
|
||||
<url>http://m2.neo4j.org/releases</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>neo4j-snapshot-repository</id>
|
||||
<name>Neo4j Maven 2 snapshot repository</name>
|
||||
<url>http://m2.neo4j.org/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-maven-release</id>
|
||||
<name>Spring Maven Release Repository</name>
|
||||
<url>http://maven.springframework.org/release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-maven-snapshot</id>
|
||||
<name>Spring Maven Snapshot Repository</name>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>http://maven.springframework.org/snapshot</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-maven-milestone</id>
|
||||
<name>Spring Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>neo4j-release-repository</id>
|
||||
<name>Neo4j Maven 2 release repository</name>
|
||||
<url>http://m2.neo4j.org/releases</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>neo4j-snapshot-repository</id>
|
||||
<name>Neo4j Maven 2 snapshot repository</name>
|
||||
<url>http://m2.neo4j.org/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-maven-release</id>
|
||||
<name>Spring Maven Release Repository</name>
|
||||
<url>http://maven.springframework.org/release</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-maven-milestone</id>
|
||||
<name>Spring Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-maven-release</id>
|
||||
<name>Spring Maven Release Repository</name>
|
||||
<url>http://maven.springframework.org/release</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-maven-milestone</id>
|
||||
<name>Spring Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j</artifactId>
|
||||
<version>${spring-data-neo4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib-nodep</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib-nodep</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!-- Must use java 1.5 or higher for annotations -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!-- Must use java 1.5 or higher for annotations -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<!-- IntelliJ Idea Support -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-idea-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<downloadSources>true</downloadSources>
|
||||
<dependenciesAsLibraries>true</dependenciesAsLibraries>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- IntelliJ Idea Support -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-idea-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<downloadSources>true</downloadSources>
|
||||
<dependenciesAsLibraries>true</dependenciesAsLibraries>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<!-- Execute the main class -->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<mainClass>org.springframework.data.neo4j.examples.hellograph.App</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- Execute the main class -->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<mainClass>org.springframework.data.neo4j.examples.hellograph.App</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<finalName>hello-worlds-${project.version}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<attach>false</attach>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.springframework.data.neo4j.examples.hellograph.App</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<finalName>hello-worlds-${project.version}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<attach>false</attach>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.springframework.data.neo4j.examples.hellograph.App</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>resources</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>plain</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j</artifactId>
|
||||
<version>${spring-data-neo4j.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/resources/spring/plain</directory>
|
||||
<targetPath>${project.build.directory}/classes/spring</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>helloWorldContext.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>aspects</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j-aspects</artifactId>
|
||||
<version>${spring-data-neo4j.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!-- required to resolve aspectj-enhanced class features -->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<configuration>
|
||||
<outxml>true</outxml>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
<aspectLibrary>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j-aspects</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjtools</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
<!-- the eclipse plugin interacts with the aspectj-maven-plugin BUT
|
||||
ONLY if the ajdtVersion config value is set (remove it and it won't) -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
<configuration>
|
||||
<!-- The ajdtVersion configuration parameter is optional. The valid
|
||||
values are none, 1.4, and 1.5. none indicates that AJDT should not be enabled
|
||||
even though Aspectj is enabled in maven. 1.4 generates the org.eclipse.ajdt.ui.prefs
|
||||
file in the .settings directory. 1.5 (or later) includes the configuration
|
||||
into the .classpath file and is the default value. -->
|
||||
<ajdtVersion>1.5</ajdtVersion>
|
||||
<additionalProjectnatures>
|
||||
<projectnature>org.eclipse.ajdt.ui.ajnature</projectnature>
|
||||
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
|
||||
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
|
||||
</additionalProjectnatures>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/resources/spring/aspects</directory>
|
||||
<targetPath>${project.build.directory}/classes/spring</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>helloWorldContext.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
||||
@@ -8,20 +8,20 @@ public class App {
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("/spring/helloWorldContext.xml");
|
||||
|
||||
MyWorldRepository galaxy = applicationContext.getBean(WorldRepositoryImpl.class);
|
||||
galaxy.makeSureGalaxyIsNotEmpty();
|
||||
GalaxyService galaxyService = applicationContext.getBean(GalaxyService.class);
|
||||
galaxyService.makeSureGalaxyIsNotEmpty();
|
||||
|
||||
System.out.println("Trying to find the Earth by its name:");
|
||||
World earth = galaxy.findWorldNamed("Earth");
|
||||
WorldDto earth = galaxyService.findWorldNamed("Earth");
|
||||
System.out.printf("Found Earth: %s\n", earth);
|
||||
|
||||
System.out.println("Retrieveing the list of worlds that can be reached from the Earth:");
|
||||
for(World world : earth.getReachableWorlds()) {
|
||||
for(WorldDto world : galaxyService.findReachableWorlds(earth.getId())) {
|
||||
System.out.printf("Can travel between %s and %s\n", earth, world);
|
||||
}
|
||||
|
||||
System.out.println("Here's the list of all worlds in the galaxy:");
|
||||
for(World world : galaxy.findAllWorlds()) {
|
||||
for(WorldDto world : galaxyService.findAllWorlds()) {
|
||||
System.out.printf("There's a world: %s\n", world);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -25,6 +24,7 @@ public class GalaxyService {
|
||||
World mars = resolveWorld("Mars", 2);
|
||||
mars.addRocketRouteTo(earth);
|
||||
worldRepository.save(mars);
|
||||
/*worldRepository.save(earth);*/
|
||||
|
||||
resolveWorld("Jupiter", 63);
|
||||
resolveWorld("Saturn", 62);
|
||||
@@ -45,11 +45,12 @@ public class GalaxyService {
|
||||
createdWorld = new World(name, moons);
|
||||
createdWorld = worldRepository.save(createdWorld);
|
||||
}
|
||||
|
||||
return createdWorld;
|
||||
}
|
||||
|
||||
public WorldDto findWorldNamed(String name) {
|
||||
World world = worldRepository.findByPropertyValue("name", name);
|
||||
World world = worldRepository.findByPropertyValue("name", name);
|
||||
return mapper.worldDtoFromWorld(world);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public interface MyWorldRepository {
|
||||
@Transactional
|
||||
void makeSureGalaxyIsNotEmpty();
|
||||
|
||||
World findWorldNamed(String name);
|
||||
|
||||
Iterable<World> findAllWorlds();
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import java.util.Set;
|
||||
@NodeEntity
|
||||
public class World {
|
||||
@GraphId
|
||||
Long id;
|
||||
private Long id;
|
||||
|
||||
@Indexed
|
||||
private String name;
|
||||
@@ -21,7 +21,7 @@ public class World {
|
||||
|
||||
@Fetch
|
||||
@RelatedTo(type = RelationshipTypes.REACHABLE_BY_ROCKET, direction = Direction.BOTH)
|
||||
Set<World> reachableByRocket = new HashSet<World>();
|
||||
private Set<World> reachableByRocket = new HashSet<World>();
|
||||
|
||||
public World(String name, int moons) {
|
||||
this.name = name;
|
||||
@@ -31,6 +31,10 @@ public class World {
|
||||
public World() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -41,7 +45,7 @@ public class World {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("World{name='%s, moons=%d}", name, moons);
|
||||
return String.format("World{name='%s', moons=%d}", name, moons);
|
||||
}
|
||||
|
||||
public void addRocketRouteTo(World otherWorld) {
|
||||
|
||||
@@ -6,5 +6,5 @@ import org.springframework.data.neo4j.repository.GraphRepository;
|
||||
* @author mh
|
||||
* @since 01.04.11
|
||||
*/
|
||||
public interface WorldRepository extends MyWorldRepository, GraphRepository<World> {
|
||||
public interface WorldRepository extends GraphRepository<World> {
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package org.springframework.data.neo4j.examples.hellograph;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Spring Data Neo4j backed application context for Worlds.
|
||||
*/
|
||||
public class WorldRepositoryImpl implements MyWorldRepository {
|
||||
|
||||
@Autowired
|
||||
private WorldRepository worldRepository;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void makeSureGalaxyIsNotEmpty() {
|
||||
// Solar worlds
|
||||
resolveWorld("Mercury", 0);
|
||||
resolveWorld("Venus", 0);
|
||||
|
||||
World earth = resolveWorld("Earth", 1);
|
||||
World mars = resolveWorld("Mars", 2);
|
||||
mars.addRocketRouteTo(earth);
|
||||
|
||||
resolveWorld("Jupiter", 63);
|
||||
resolveWorld("Saturn", 62);
|
||||
resolveWorld("Uranus", 27);
|
||||
resolveWorld("Neptune", 13);
|
||||
|
||||
// Norse worlds
|
||||
resolveWorld("Alfheimr", 0);
|
||||
resolveWorld("Midgard", 1);
|
||||
resolveWorld("Muspellheim", 2);
|
||||
resolveWorld("Asgard", 63);
|
||||
resolveWorld("Hel", 62);
|
||||
}
|
||||
|
||||
private World resolveWorld(String name, int moons) {
|
||||
World createdWorld = findWorldNamed(name);
|
||||
if (createdWorld == null) {
|
||||
createdWorld = new World(name, moons);
|
||||
worldRepository.save(createdWorld);
|
||||
}
|
||||
return createdWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World findWorldNamed(String name) {
|
||||
return worldRepository.findByPropertyValue("name", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<World> findAllWorlds() {
|
||||
return worldRepository.findAll();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
|
||||
<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">
|
||||
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:spring-configured/>
|
||||
<context:annotation-config/>
|
||||
<context:component-scan base-package="org.springframework.data.neo4j.examples.hellograph" />
|
||||
|
||||
<neo4j:config storeDirectory="target/neo4j-db"/>
|
||||
<neo4j:repositories base-package="org.springframework.data.neo4j.examples.hellograph"/>
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
|
||||
<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:spring-configured/>
|
||||
<context:annotation-config/>
|
||||
|
||||
<neo4j:config storeDirectory="target/neo4j-db"/>
|
||||
<neo4j:repositories base-package="org.springframework.data.neo4j.examples.hellograph"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<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:spring-configured/>
|
||||
<context:annotation-config/>
|
||||
<context:component-scan base-package="org.springframework.data.neo4j.examples.hellograph" />
|
||||
|
||||
<neo4j:config storeDirectory="target/neo4j-db"/>
|
||||
<neo4j:repositories base-package="org.springframework.data.neo4j.examples.hellograph"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -34,7 +34,7 @@ public class GalaxyServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void populatedGalaxyShouldHaveEarth() {
|
||||
public void populatedGalaxyShouldHaveEarth() {
|
||||
galaxyService.makeSureGalaxyIsNotEmpty();
|
||||
WorldDto earth = galaxyService.findWorldNamed("Earth");
|
||||
assertNotNull(earth);
|
||||
@@ -55,4 +55,5 @@ public class GalaxyServiceTest {
|
||||
WorldDto planetPopsicle = galaxyService.findWorldNamed("Krypton");
|
||||
assertNull(planetPopsicle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user