Giter VIP home page Giter VIP logo

neo4j-movies-java-bolt's Introduction

Neo4j Movies Example Application

movie application

This example application demonstrates how easy it is to get started with Neo4j in Java.

It is a very simple web application that uses our Movie graph dataset to provide a search with listing, a detail view and a graph visualization.

THe front-end is just jQuery and d3 and the backend is implemented in Java using spark-java a lightweight web framework.

Using Neo4j from Java is as easy as using any other database that offers a textual query language. With our binary protocol driver for the binary protocol, you get a clean API to manage your Session, Transaction and Statement and iterate over each Value of a StatementResult with a rich conversion DSL.

The Stack

These are the components of our min- Web Application:

  • Application Type: Java-Web Application

  • Web framework: Spark-Java (Micro-Webframework)

  • Neo4j Database Connector: Neo4j-Java-Driver for Cypher Docs

  • Database: Neo4j-Server

  • Frontend: jquery, bootstrap, d3.js

Endpoints:

Get Movie

// JSON object for single movie with cast
curl http://localhost:8080/movie/The%20Matrix

// list of JSON objects for movie search results
curl http://localhost:8080/search?q=matrix

// JSON object for whole graph viz (nodes, links - arrays)
curl http://localhost:8080/graph

Setup

Spark is a micro-webframework to easily define routes for endpoints and provide their implementation. In our case the implementation calls the MovieService which has one method per endpoint that returns Java collections which are turned into JSON using the Google Gson library.

The MovieService uses the Neo4j-Java driver to execute queries via Neo4j binary protocol "Bolt". You add the dependency to the Neo4j-Java-Driver driver in your pom.xml:

<dependency>
    <groupId>org.neo4j.driver</groupId>
    <artifactId>neo4j-java-driver</artifactId>
    <version>1.0.0-RC2</version>
</dependency>

To use the driver, you provide a connection URL, e.g. bolt://user:password@localhost, get a Driver instance, from which you get a Session. The session allows you to execute Cypher statements directly and iterate over the StatementResults to access the resulting `Value`s. Please edit example.movies.util.Util.java to add your connection settings, for instance "bolt://neo4j:neo4j@localhost"

With your statement you can provide parameters as a Java map.

Driver driver = GraphDatabase.driver("bolt://localhost");
String query = "MATCH (:Movie {title:{title}})<-[:ACTED_IN]-(a:Person) RETURN a.name as actor";

try (Session session = driver.session()) {

    StatementResult result = session.run(query, singletonMap("title", "The Matrix"));
    while (result.hasNext()) {
        System.out.println(result.next().get("actor"));
    }
}

Run locally:

Start your local Neo4j Server (Download & Install), open the Neo4j Browser. After logging in, install the Movies graph data set by entering the :play movies command, click the CREATE-statement, and hit the triangular "Run" button.

Start this application with:

mvn compile exec:java

You can search for movies by title or and click on any entry.

neo4j-movies-java-bolt's People

Contributors

jexp avatar netrebel avatar flefevre avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.