4.2.x
image:https://spring.io/badges/spring-data-neo4j/ga.svg[title=Spring Data Neo4j,link=http://projects.spring.io/spring-data-neo4j#quick-start]
image:https://spring.io/badges/spring-data-neo4j/snapshot.svg[title=Spring Data Neo4j,link=http://projects.spring.io/spring-data-neo4j#quick-start]
image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-neo4j%2Fmaster&subject=Moore%20(master)[link=https://jenkins.spring.io/view/SpringData/job/spring-data-neo4j/]
image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-neo4j%2F5.1.x&subject=Lovelace%20(5.1.x)[link=https://jenkins.spring.io/view/SpringData/job/spring-data-neo4j/]
image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-neo4j%2F4.2.x&subject=Ingalls%20(4.2.x)[link=https://jenkins.spring.io/view/SpringData/job/spring-data-neo4j/]
= Spring Data Neo4j
The primary goal of the http://projects.spring.io/spring-data[Spring Data] project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services.
The Spring Data Neo4j project aims to provide a familiar and consistent Spring-based programming model for integrating with the http://neo4j.com/[Neo4j] Graph Database.
=== Features
* Automatic mapping of annotated domain entities for nodes and relationships;
* Powerful CRUD based repositories with provided, derived, and annotated finder methods;
* Integration with Spring's comprehensive Transaction management;
* Agnostic communication with Neo4j through a variety of transport mechanisms (embedded, http, https://neo4j.com/developer/language-guides/#bolt-drivers[bolt]);
* Integration into Spring Data REST;
* Seamless integration with Spring Boot.
== Documentation & Getting Help
This README is the best place to start learning about the features of Spring Data Neo4j.
To learn more refer to:
* the http://docs.spring.io/spring-data/neo4j/docs/4.2.x/reference/html/[Reference Manual];
* the https://github.com/neo4j-examples/sdn4-university/tree/4.2[sample project: SDN Univeristy]. More example projects for Spring Data Neo4j 4 are available in the https://github.com/neo4j-examples?query=sdn4[Neo4j-Examples] repository
* The main http://projects.spring.io/spring-data-neo4j[SpringSource project site] contains links to basic project information such as source code, JavaDocs, Issue tracking, etc.
* the http://docs.spring.io/spring-data/neo4j/docs/4.2.x/api/[Javadocs];
* for more detailed questions, use http://stackoverflow.com/questions/tagged/spring-data-neo4j-4[Spring Data Neo4j 4 on StackOverflow]
If you are new to Spring as well as to Spring Data, look for information about http://www.springsource.org/projects[Spring projects].
== Quick start
Add the Maven dependency:
[source,xml]
----
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>4.2.0.M1</version>
</dependency>
<repository>
<id>spring-maven-milestone</id>
<name>Springframework Maven Milestone Repository</name>
<url>http://repo.spring.io/libs-milestone</url>
</repository>
----
If you'd rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare the appropriate dependency version.
[source,xml]
----
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>4.2.0.BUILD-SNAPSHOT</version>
</dependency>
<!-- used for nightly builds -->
<repository>
<id>spring-maven-snapshot</id>
<snapshots><enabled>true</enabled></snapshots>
<name>Springframework Maven SNAPSHOT Repository</name>
<url>http://repo.spring.io/libs-release</url>
</repository>
----
TIP: You can check out how to get setup with Gradle in the the http://static.springsource.org/spring-data/data-neo4j/docs/current/reference/html/[Reference Manual].
Configure Spring Data Neo4j in your application using JavaConfig bean configuration
[source,java]
----
@Configuration
@ComponentScan(basePackages = "org.example.person.services",...)
@EnableNeo4jRepositories(basePackages = "com.example.person.repository",...)
@EnableTransactionManagement
public class MyConfiguration {
@Bean
public SessionFactory sessionFactory() {
// with domain entity base package(s)
return new SessionFactory("com.example.person.domain",...);
}
@Bean
public Neo4jTransactionManager transactionManager() {
return new Neo4jTransactionManager(sessionFactory());
}
}
----
Spring Data Neo4j provides support for connecting to all of Neo4j's java drivers:
* Bolt
* HTTP
* Embedded
Spring Data Neo4j will attempt to auto-configure itself using a file called `ogm.properties`, which it expects to find on root of the classpath. Here we will configure the HTTP Driver.
[source,java]
----
driver=org.neo4j.ogm.drivers.http.driver.HttpDriver
URI=http://user:password@localhost:7474
----
The application can be configured programmatically as well, please consult http://docs.spring.io/spring-data/neo4j/docs/4.2.x/reference/html/#reference.getting_started.spring-configuration[the reference guide] for more information.
Annotate an entity:
[source,java]
----
@NodeEntity
public class Person {
private Long id;
private String name;
@Relationship(type = "FRIEND", direction = "OUTGOING")
private Set<Person> friends;
public Person() {}
public Person(String name) { this.name = name; }
private void knows(Person friend) { friends.add(friend); }
}
----
To simplify the creation of data repositories Spring Data Neo4j provides a generic repository programming model. It will automatically create a repository proxy for you that adds implementations of finder methods you specify on an interface.
For example, given the Person class above, a PersonRepository interface that can query for Person by name and when the name matches a like expression is shown below:
[source,java]
----
@Repository
public interface PersonRepository extends Neo4jRepository<Person> {
List<Person> findByName(String name);
List<Person> findByNameLike(String name);
}
----
The queries issued on execution will be derived from the method name.
Typically you will want to call your domain objects and repositories from services. In this Service we find the repository interface and register a proxy object in the container:
[source,java]
----
@Service
public class MyService {
@Autowired
private final PersonRepository repository;
@Transactional
public void doWork() {
Person jon = new Person("Jon");
Person emil = new Person("Emil");
Person rod = new Person("Rod");
emil.knows(jon);
emil.knows(rod);
// Persist entities and relationships to graph database
personRepository.save(emil);
for (Person friend : emil.getFriends()) {
System.out.println("Friend: " + friend);
}
// Control loading depth
Person thatSamejon = personRepository.findOne(id, 2);
for (Person friend : jon.getFriends()) {
System.out.println("Jon's friends to depth 2: " + friend);
}
}
}
----
== Contributing to Spring Data Neo4j
There are dedicated, mandatory https://github.com/spring-projects/spring-data-build/blob/master/CONTRIBUTING.adoc[contribution guidelines] for all Spring Data projects.
Here are some ways for you to get involved in the community:
* Get involved with Spring Data Neo4j community on the http://groups.google.com/group/neo4j[Neo4j Google Group] and by helping on http://stackoverflow.com/questions/tagged/spring-data-neo4j[StackOverflow].
* Create https://jira.spring.io/browse/DATAGRAPH[JIRA] tickets for bugs and new features and comment and vote on the ones that you are interested in.
* Github is for social coding: if you want to write code, we encourage contributions through *pull requests* from a fork of this repository.
If you want to contribute code this way, please read the https://github.com/spring-projects/spring-data-build/blob/master/CONTRIBUTING.adoc[contribution guidelines] for details.
= Running CI tasks locally
Since this pipeline is purely Docker-based, it's easy to:
* Debug what went wrong on your local machine.
* Test out a a tweak to your `test.sh` script before sending it out.
* Experiment against a new image before submitting your pull request.
All of these use cases are great reasons to essentially run what the CI server does on your local machine.
IMPORTANT: To do this you must have Docker installed on your machine.
1. `docker run -it --mount type=bind,source="$(pwd)",target=/spring-data-neo4j-github adoptopenjdk/openjdk8:latest /bin/bash`
+
This will launch the Docker image and mount your source code at `spring-data-neo4j-github`.
+
2. `cd spring-data-neo4j-github`
+
Next, run your tests from inside the container:
+
3. `./mvnw clean dependency:list test -Dsort` (or whatever profile you need to test out)
Since the container is binding to your source, you can make edits from your IDE and continue to run build jobs.
If you test building the artifact, do this:
1. `docker run -it --mount type=bind,source="$(pwd)",target=/spring-data-neo4j-github adoptopenjdk/openjdk8:latest /bin/bash`
+
This will launch the Docker image and mount your source code at `spring-data-neo4j-github`.
+
2. `cd spring-data-neo4j-github`
+
Next, try to package everything up from inside the container:
+
3. `./mvnw -Pci,snapshot -Dmaven.test.skip=true clean package`
NOTE: Docker containers can eat up disk space fast! From time to time, run `docker system prune` to clean out old images.
Description
Languages
Java
96.4%
CSS
2.2%
AspectJ
0.8%
HTML
0.4%