Skip to content

Instantly share code, notes, and snippets.

@igor-vovk
Created June 29, 2013 10:03
Show Gist options
  • Save igor-vovk/5890608 to your computer and use it in GitHub Desktop.
Save igor-vovk/5890608 to your computer and use it in GitHub Desktop.
Singleton to instantiate Neo4j
object Database extends Logging {
private var _instance: GraphDatabaseService = null
def instance: GraphDatabaseService = {
if (null == _instance) {
synchronized {
if (null == _instance) {
_instance = initDatabase()
}
}
}
_instance
}
protected def initDatabase: GraphDatabaseService = {
logger.info("Starting neo4j init procedure")
val inst = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder(ProjectProperties.get("neo.db_path"))
.newGraphDatabase()
sys.addShutdownHook(inst.shutdown())
inst
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment