Created
June 29, 2013 10:03
-
-
Save igor-vovk/5890608 to your computer and use it in GitHub Desktop.
Singleton to instantiate Neo4j
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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