diff --git a/.gitignore b/.gitignore index 32858aa..f2d840b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +/target/ \ No newline at end of file diff --git a/pom.xml b/pom.xml index 34428e4..96339a7 100644 --- a/pom.xml +++ b/pom.xml @@ -50,9 +50,9 @@ - org.neo4j - neo4j - 3.1.0-M10 + org.neo4j.driver + neo4j-java-driver + 1.0.6 diff --git a/src/main/java/com/camillepradel/movierecommender/controller/Neo4jConnector.java b/src/main/java/com/camillepradel/movierecommender/controller/Neo4jConnector.java new file mode 100644 index 0000000..b36b010 --- /dev/null +++ b/src/main/java/com/camillepradel/movierecommender/controller/Neo4jConnector.java @@ -0,0 +1,62 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.camillepradel.movierecommender.controller; +import java.net.ConnectException; +import org.neo4j.driver.v1.*; +import org.neo4j.driver.v1.exceptions.Neo4jException; + +/** + * + * @author renando + */ +public class Neo4jConnector { + + + private static Neo4jConnector INSTANCE = null; + private static Session session = null; + private static Driver driver = null; + + private Neo4jConnector() { + + } + + public static synchronized Neo4jConnector getInstance() + { + if (INSTANCE == null) + { + INSTANCE = new Neo4jConnector(); + driver = GraphDatabase.driver( "bolt://localhost", AuthTokens.basic( "neo4j", "root1234" ) ); + session = driver.session(); + } + return INSTANCE; + } + + public Session getConnection() throws ConnectException { + if (session == null || driver == null){ + Neo4jConnector.getInstance(); + } + return this.session; + } + + public boolean close() throws ConnectException { + boolean etat = false; + if (session != null) { + try { + session.close(); + driver.close(); + etat = true; + } catch (Neo4jException e) { + etat = false; + } + } else { + throw new ConnectException(); + + } + + return etat; + } + +} \ No newline at end of file