-
Notifications
You must be signed in to change notification settings - Fork 49
driver factsheet (WIP)
This is work in progress, the goal is to have one fact sheet template that is used across all drivers and the fact-sheet.md is part of each drivers repository and can be read and inlined from neo4j.org
(one sentence)
(powerful but simple)
Neo4j is a transactional, open-source graph database. A graph consists of labeled nodes connected by directed, typed relationships. Both can have arbitrary key-value properties. Graphs are explored by finding patterns starting at some initial set of nodes. A graph query language like Cypher helps expressing complex operations in a readable way. Neo4j makes it easy to store and query complex, connected domains and support use-cases that require non-obvious answers. Of course it also runs your typical graph algorithms.
(user)-[rating:RATED]->(movie)<-[role:ACTED_IN]-(actor)
- more examples
- documentation
- source-code
- how-to-contribute
- Authors personal page
- http://neo4j.org
- http://neo4j.org/tracks/cypher
- http://neo4j.org/drivers
- http://neo4j.org/q_and_a
The Java-Rest-Binding offers a Java-API to access the REST-API of the Neo4j-Server and provides also a drop-in replacement for the GraphDatabaseService interface for simple use-cases that are not performance critical. Both Cypher queries as well as traversals are executed on the server side.
RestGraphDatabase gdb = new RestGraphDatabase(rest);
RestNode node = gdb.createNode(map("title","The Matrix"),"Movie");
Result<Node> matrix = gdb.query("match m:Movie where m.title={title} return m",map("title","The Matrix")).to(Node.class).getSingle();
- Version 1.9.RC1 is compatible with Neo4j 1.9.GA
- Version 2.0.M02 is compatible with Neo4j 2.0.M02
It is available on GitHub and in the Neo4j Maven Repository.
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>java-rest-binding</artifactId>
<version>1.9.RC1</version>
</dependency>
String url="http://localhost:PORT/db/data";
RestApi rest = new RestApiFacade(url,[user],[pass]);
QueryExecutor executor = new RestCypherQueryExecutor(rest);
executor.query("start n=node:node_auto_index(title={title}) return n",map("title","Forrest Gump"));
GraphDatabaseService rdb = new RestGraphDatabase(rest);
RestNode node = rdb.findNodeById(100);
Neo4j is a transactional, open-source graph database. A graph consists of labeled nodes connected by directed, typed relationships. Both can have arbitrary key-value properties. Graphs are explored by finding patterns starting at some initial set of nodes. A graph query language like Cypher helps expressing complex operations in a readable way. Neo4j makes it easy to store and query complex, connected domains and support use-cases that require non-obvious answers. Of course it also runs your typical graph algorithms.
As the Neo4j server hosts the database that is connected to, the lifecycle lies in starting and stoppign the server bin/neo4j start|stop
.
Each http request to the server runs in its own transaction. The only exception is the batch-REST-Api which can run several operations in one single transaction
QueryExecutor executor = new RestCypherQueryExecutor(rest); Iterator titles = executor.query("start n=node:node_auto_index(title={title}) return n.title",map("title","Forrest Gump")).to(String.class);
(user)-[rating:RATED]->(movie)<-[role:ACTED_IN]-(actor)
Node keanu = rdb.createNode(map("name","Keanu Reeves"),"Actor");
Node matrix = rdb.createNode(map("title","The Matrix"),"Movie");
keanu.createRelationshipTo(matrix, "ACTED_IN", map("role","Neo"));
only possible with Cypher, client-side iteration is not sensible
Node matrix=executor.query("start n=node(*) where n.title! = {title} return n;",map("title","The Matrix")).to(Node.class).getSingle();
rdb.index().forNodes("Movie").add(matrix,"title",matrix.getProperty("title"));
Node foundMovie=rdb.index().forNodes("Movie").get("title","The Matrix").getSingle();
for (Relationship role : matrix.getRelationships(Types.ACTED_IN,Direction.INCOMING)) {
String roleName = (String)role.getProperty("role");
Node actor = role.getStartNode();
String actorName = (String)actor.getProperty("name");
}
actor.setProperty("name","Tom Hanks");
role.setProperty("difficulty","easy");
for (Relationship r : actor.getRelationships()) {
r.delete();
}
actor.delete();
You can test with an embedded Neo4j Server by using the WrappingNeoServer
around a database of your choice, preferably an ImpermanentGraphDatabase
.
Then you connect your RestApiFacade
to http://localhost:PORT/db/data
private WebServer startWebServer(GraphDatabaseAPI gdb, int port, boolean auth) {
final ServerConfigurator config = new ServerConfigurator(gdb);
config.configuration().setProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY,port);
final WrappingNeoServer wrappingNeoServer = new WrappingNeoServer(gdb, config);
final WebServer webServer = wrappingNeoServer.getWebServer();
if (auth) webServer.addFilter(new TestAuthenticationFilter(), "/*");
wrappingNeoServer.start();
return webServer;
}
- more examples // Gensen, Community Graph, Spring Data Neo4j
- documentation // github
- source-code // github
- how-to-contribute // github
- Authors personal page
- neo4j.org
- neo4j.org/tracks/cypher
- neo4j.org/drivers
- neo4j.org/q_and_a
Spring Data Neo4j enables simpel object-graph mapping using annotated entities. As part of the Spring Data project it leverages the powerful template, mapping and repository abstractions.
@NodeEntity
class Movie {
@GraphId Long id;
@Indexed String title;
@RelatedToVia Set<Role> cast;
}
Iterable<Movie> movies = movieRepository.findByCastActorName("Keanu Reeves");
- 2.2.1.RELASE is compatible with Neo4j 1.8.x and Neo4j 1.9.x
- 3.0.RELEASE will be compatible with Neo4j 2.0
It is available on Maven Central and the SpringSource Maven repositories as well as a download from springsource.org. Depending on the used modules, use different artifact-id's.
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j[-aspects|-rest|-cross-store]</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
Neo4j is a transactional, open-source graph database. A graph consists of labeled nodes connected by directed, typed relationships. Both can have arbitrary key-value properties. Graphs are explored by finding patterns starting at some initial set of nodes. A graph query language like Cypher helps expressing complex operations in a readable way. Neo4j makes it easy to store and query complex, connected domains and support use-cases that require non-obvious answers. Of course it also runs your typical graph algorithms.
If you run embedded, you declare either the path to the graph database in your spring config or provide a bean reference to a GraphDatabaseService
bean.
Running against Neo4j server requires a bean reference to SpringRestGraphdatabase
with the appropriate URL configured. There are other options for HA or
running as Server Extension, please refer to the documentation for this.
The graph database lifecycle will be handled by the spring container, a appCtx.close()
shuts the database down.
With the Spring Framework you usually use declarative transaction management with annotations, make sure that your config enables the transaction managment and
the annotation scanning for @Transactional
. There is also @Neo4jTransactional
for co-existence with a relational transaction manager.
(user)-[rating:RATED]->(movie)<-[role:ACTED_IN]-(actor)
- more examples http://spring.neo4j.org/examples
- documentation http://spring.neo4j.org/docs
- source-code http://spring.neo4j.org/source
- how-to-contribute GitHub Pull Requests, Neo4j CLA, Springframework CLA
- Authors: Michael Hunger, Lasse West-Nielsen, Oliver Gierke, David Montag
- neo4j.org
- neo4j.org/tracks/cypher
- neo4j.org/drivers
- neo4j.org/q_and_a
A .NET client for Neo4j. Supports basic CRUD operations, Cypher and Gremlin queries via fluent interfaces, and some indexing operations.
var booksQuery = client
.Cypher
.Start(new { root = client.RootNode })
.Match("root-[:HAS_BOOK]->book")
.Where((Book bk) => bk.Pages > 5)
.Return<Node<Book>>("book");
Versions are released very frequently via NuGet: http://nuget.org/packages/Neo4jClient/
Neo4jClient is compatible with Neo4j 1.8.x and Neo4j 1.9.x. As of Neo4jClient 1.0.0.589, it works with Neo4j 2.0, but 2.0 specific features are not yet supported. (For example, labels.)
Neo4jClient ships exclusively as a NuGet package.
To install it:
- Open the package manager console in Visual Studio: Tools | Library Package Manager | Package Manager Console
- Run Install-Package Neo4jClient
This only installs the client. To install a Neo4j database on a Windows server, visit http://www.neo4j.org/download/windows
Neo4j is a transactional, open-source graph database. A graph consists of labeled nodes connected by directed, typed relationships. Both can have arbitrary key-value properties. Graphs are explored by finding patterns starting at some initial set of nodes. A graph query language like Cypher helps expressing complex operations in a readable way. Neo4j makes it easy to store and query complex, connected domains and support use-cases that require non-obvious answers. Of course it also runs your typical graph algorithms.
Not applicable
Each http request to the server runs in its own transaction.
Support for batching multiple requests in the one transaction (via REST batch) is not yet included.
Neo4jClient's fluent Cypher interface leverages Cypher parameters automatically.
For example, a fluent query like this:
var booksQuery = client
.Cypher
.Start(new { root = client.RootNode })
.Match("root-[:HAS_BOOK]->book")
.Where((Book bk) => bk.Pages > 5)
.Return<Node<Book>>("book");
Results in a JSON payload like this:
{
"query": "START root=node({p0}) MATCH root-[:HAS_BOOK]->book WHERE bk.Pages > {p1} RETURN book",
"parameters": {
"p0": 0,
"p1": 5
}
}
(user)-[rating:RATED]->(movie)<-[role:ACTED_IN]-(actor)
// Create relationship with root node, so we can access the movie.
// Create movie and relationship in one go, so there is only one access to the database
var movie = client.Create(new Movie { Title = "The Matrix" }, new HasMovie(client.RootNode));
var actor = client.Create(new Actor { Name = "Keanu Reeves" }, new ActedIn(movie, new ActedInProperties { Role = "Neo" }));
// ---------------
// Declarations
public class Movie
{
public string Title { get; set; }
}
public class Actor
{
public string Name { get; set; }
}
public class ActedIn : Relationship, IRelationshipAllowingSourceNode<Actor>, IRelationshipAllowingTargetNode<Movie>
{
public ActedIn(NodeReference<Movie> targetNode, ActedInProperties actedInProperties) : base(targetNode, actedInProperties) { }
public override string RelationshipTypeKey { get { return "ACTED_IN"; } }
}
public class ActedInProperties
{
public string Role { get; set; }
}
public class HasMovie : Relationship, IRelationshipAllowingSourceNode<RootNode>, IRelationshipAllowingTargetNode<Movie>
{
public HasMovie(NodeReference<Movie> targetNode): base(targetNode) {}
public HasMovie(NodeReference<RootNode> rootNode) : base(rootNode) { }
public override string RelationshipTypeKey { get { return "HAS_MOVIE"; } }
}
var movies = client
.Cypher
.Start(new { root = client.RootNode })
.Match("root-[:HAS_MOVIE]->movie")
.Where((Movie movie) => movie.Title == "The Matrix")
.Return<Node<Movie>>("movie")
.Results;
// index a movie by title
var theMatrix = new Movie { Title = "The Matrix" };
client.Create(
theMatrix,
new IRelationshipAllowingParticipantNode<Movie>[0],
new[]
{
new IndexEntry("Movie")
{
{ "Title", theMatrix.Title }
}
});
// use the index for search
IEnumerable<Node<Movie>> movies = client
.Cypher
.Start(new { movie = Node.ByIndexLookup("Movie", "Title", "The Matrix" )})
.Return<Node<Movie>>("movie")
.Results;
// Find all actors playing in the movie The Matrix, and their roles
var actorsAndRoles = client
.Cypher
.Start(new { theMatrix = theMatrix })
.Match("actor-[r:ACTED_IN]->theMatrix")
.Return((actor, r) => new
{
Actor = actor.As<Node<Actor>>(),
// ActedInProperties contains all properties of the relationship, such as Role
ActedInProperties = r.As<Node<ActedInProperties>>()
})
.Results;
client.Update(actor, node => { node.Name = "Hugo Weaving"; });
client.Update(movie, node => { node.Title = "The Matrix Reloaded"; });
client.Delete(actor, DeleteMode.NodeAndRelationships);
// Find all movies that Keano Reeves played in, and his co-actors in each movie
// Cypher pattern:
// keanoReeves-[:ACTED_IN]->movie<-[?:ACTED_IN]-coActor
var moviesAndCoactors = client
.Cypher
.Start(new { keanoReeves = keanoReeves })
.Match("keanoReeves-[:ACTED_IN]->movie<-[?:ACTED_IN]-coActor")
.Where((Actor coActor) => coActor.Name != "Keanu Reeves")
.Return((movie, coActor) => new
{
Movie = movie.As<Node<Movie>>(),
CoActor = coActor.As<Node<Actor>>()
})
.Results;
Not applicable