connector
This commit is contained in:
parent
dec18968b9
commit
866f0255a1
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@
|
|||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
|
/target/
|
6
pom.xml
6
pom.xml
@ -50,9 +50,9 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.neo4j/neo4j -->
|
<!-- https://mvnrepository.com/artifact/org.neo4j/neo4j -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.neo4j</groupId>
|
<groupId>org.neo4j.driver</groupId>
|
||||||
<artifactId>neo4j</artifactId>
|
<artifactId>neo4j-java-driver</artifactId>
|
||||||
<version>3.1.0-M10</version>
|
<version>1.0.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
|
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user