DATAGRAPH-765 - Documentation updates- readme.
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
# spring-data-neo4j
|
||||
Spring Data Neo4j 4
|
||||
|
||||
This branch must not be merged with master yet.
|
||||
219
README.textile
Normal file
219
README.textile
Normal file
@@ -0,0 +1,219 @@
|
||||
h1. Spring Data Neo4j - Quick start
|
||||
|
||||
<pre>
|
||||
@NodeEntity
|
||||
class Person {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
@Relationship(type = "FRIEND", direction = "UNDIRECTED")
|
||||
private Set<Person> friends;
|
||||
|
||||
public Person() {}
|
||||
public Person(String name) { this.name = name; }
|
||||
|
||||
private void knows(Person friend) { friends.add(friend); }
|
||||
}
|
||||
|
||||
public interface PersonRepository extends GraphRepository<Person> {
|
||||
}
|
||||
|
||||
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
|
||||
jon = personRepository.findOne(id, 2);
|
||||
for (Person friend : jon.getFriends()) {
|
||||
System.out.println("Jon's friends to depth 2: " + friend);
|
||||
}
|
||||
|
||||
</pre>
|
||||
|
||||
h2. About
|
||||
|
||||
The primary goal of the "Spring Data":http://www.springsource.org/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. As the name implies, the **Graph** project provides integration with graph value stores. The only supported Graph Database now is "Neo4j":http://neo4j.org/.
|
||||
|
||||
The Spring Data Neo4j project provides a simplified POJO based programming model that reduces that amount of boilerplate code needed to create neo4j applications. It also provides a cross-store persistence solution that can extend existing JPA data models with new parts (properties, entities, relationships) that are stored exclusively in the graph while being transparently integrated with the JPA entities. This enables for easy and seamless addition of new features that were not available before to JPA-based applications.
|
||||
|
||||
h2. Maven configuration
|
||||
|
||||
* Add the maven repository and dependency:
|
||||
|
||||
<pre>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j</artifactId>
|
||||
<version>4.1.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-maven-snapshot</id>
|
||||
<snapshots><enabled>true</enabled></snapshots>
|
||||
<name>Springframework Maven MILESTONE Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</pre>
|
||||
|
||||
|
||||
h2. Spring configuration
|
||||
|
||||
* Configure Spring Data Neo4j 4.1 in your application using Java-based bean configuration
|
||||
|
||||
<pre>
|
||||
@Configuration
|
||||
@EnableNeo4jRepositories(basePackages = "org.neo4j.example.repository")
|
||||
@EnableTransactionManagement
|
||||
public class MyConfiguration extends Neo4jConfiguration {
|
||||
|
||||
@Bean
|
||||
public SessionFactory getSessionFactory() {
|
||||
// with domain entity base package(s)
|
||||
return new SessionFactory("org.neo4j.example.domain");
|
||||
}
|
||||
|
||||
// needed for session in view in web-applications
|
||||
@Bean
|
||||
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public Session getSession() throws Exception {
|
||||
return super.getSession();
|
||||
}
|
||||
|
||||
}
|
||||
</pre>
|
||||
|
||||
Spring Data Neo4j 4.1 provides support for connecting to Neo4j using different drivers. HTTP and Embedded drivers are available.
|
||||
Spring Data Neo4j will attempt to auto-configure itself using a file called ogm.properties, which it expects to find on the classpath.
|
||||
|
||||
<pre>
|
||||
driver=org.neo4j.ogm.drivers.http.driver.HttpDriver
|
||||
URI=http://user:password@localhost:7474
|
||||
</pre>
|
||||
|
||||
The application can be configured programmatically as well, please read the reference guide for more information.
|
||||
|
||||
h2. Graph entities
|
||||
|
||||
* Annotate your entity class. In this case it is a 'World' class that has a relationship to other worlds that are reachable by rocket travel:
|
||||
|
||||
<pre>
|
||||
@NodeEntity
|
||||
public class World {
|
||||
|
||||
//Required, Neo4j ID field
|
||||
@GraphId private Long id;
|
||||
private String name;
|
||||
private int moons;
|
||||
|
||||
@Relationship( type = "REACHABLE_BY_ROCKET", direction = Relationship.UNDIRECTED)
|
||||
private Set<World> reachableByRocket;
|
||||
|
||||
public World() {}
|
||||
public World(String name, int moons) {
|
||||
this.name = name;
|
||||
this.moons = moons;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
|
||||
public int getMoons() { return moons; }
|
||||
|
||||
public void addRocketRouteTo( World otherWorld ) {
|
||||
reachableByRocket.add( otherWorld );
|
||||
}
|
||||
|
||||
public boolean canBeReachedFrom( World otherWorld ) {
|
||||
return reachableByRocket.contains( otherWorld );
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
h2. Transactional services
|
||||
|
||||
* Create a repository or service to perform typical operations on your entities. The complete functionality is covered in the "reference manual":http://static.springsource.org/spring-data/data-neo4j/docs/current/reference/html/#programming-model.
|
||||
|
||||
<pre>
|
||||
public interface WorldRepository extends GraphRepository<World> {}
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class GalaxyService {
|
||||
|
||||
@Autowired
|
||||
private WorldRepository worldRepository;
|
||||
|
||||
public long getNumberOfWorlds() {
|
||||
return worldRepository.count();
|
||||
}
|
||||
|
||||
public World createWorld(String name, int moons) {
|
||||
return worldRepository.save(new World(name, moons));
|
||||
}
|
||||
|
||||
public Iterable<World> getAllWorlds() {
|
||||
return worldRepository.findAll();
|
||||
}
|
||||
|
||||
public World findWorldById(Long id) {
|
||||
return worldRepository.findOne(id);
|
||||
}
|
||||
|
||||
public Collection<World> makeSomeWorlds() {
|
||||
Collection<World> worlds = new ArrayList<World>();
|
||||
|
||||
// Solar worlds
|
||||
worlds.add(createWorld("Mercury", 0));
|
||||
worlds.add(createWorld("Venus", 0));
|
||||
|
||||
World earth = createWorld("Earth", 1);
|
||||
World mars = createWorld("Mars", 2);
|
||||
mars.addRocketRouteTo(earth);
|
||||
worldRepository.save(mars);
|
||||
worlds.add(earth);
|
||||
worlds.add(mars);
|
||||
|
||||
// ... Create more worlds
|
||||
|
||||
return worlds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</pre>
|
||||
|
||||
|
||||
Please see the "SDN University sample project":https://github.com/neo4j-examples/sdn4-university/tree/4.1 for more information.
|
||||
|
||||
|
||||
h2. Getting Help
|
||||
|
||||
This README and the "User Guide":http://static.springsource.org/spring-data/data-neo4j/docs/current/reference/html/ are the best places to start learning about Spring Data Neo4j.
|
||||
|
||||
The main project "website":http://www.springsource.org/spring-data contains links to basic project information such as source code, JavaDocs, Issue tracking, etc.
|
||||
|
||||
For more detailed questions, use the "forum":http://forum.springsource.org/forumdisplay.php?f=80. If you are new to Spring as well as to Spring Data, look for information about "Spring projects":http://www.springsource.org/projects.
|
||||
|
||||
|
||||
h2. Contributing to Spring Data
|
||||
|
||||
Here are some ways for you to get involved in the community:
|
||||
|
||||
* Get involved with the Spring community on the Spring Community Forums. Please help out on the "forum":http://forum.springsource.org/forumdisplay.php?f=80 by responding to questions and joining the debate.
|
||||
* Create "JIRA":https://jira.springframework.org/browse/DATAGRAPH 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 "forks of this repository":http://help.github.com/forking/. If you want to contribute code this way, please reference a JIRA ticket as well covering the specific issue you are addressing.
|
||||
* Watch for upcoming articles on Spring by "subscribing":http://www.springsource.org/node/feed to springframework.org
|
||||
|
||||
Before we accept a non-trivial patch or pull request we will need you to sign the "contributor's agreement":https://support.springsource.com/spring_committer_signup. Signing the contributor's agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. Active contributors might be asked to join the core team, and given the ability to merge pull requests.
|
||||
Reference in New Issue
Block a user