@ Override protected Object createPoolOrConnection ( ) { if ( log . isInfoEnabled ( ) ) log . info ( "Initializing Neo4J database connection..." ) ; PersistenceUnitMetadata puMetadata = kunderaMetadata . getApplicationMetadata ( ) . getPersistenceUnitMetadata ( getPersistenceUnit ( ) ) ; Properties props = puMetadata . getProperties ( ) ; String datastoreFilePath = null ; if ( externalProperties != null ) { datastoreFilePath = ( String ) externalProperties . get ( PersistenceProperties . KUNDERA_DATASTORE_FILE_PATH ) ; } if ( StringUtils . isBlank ( datastoreFilePath ) ) { datastoreFilePath = ( String ) props . get ( PersistenceProperties . KUNDERA_DATASTORE_FILE_PATH ) ; } if ( StringUtils . isBlank ( datastoreFilePath ) ) { throw new PersistenceUnitConfigurationException ( "For Neo4J, it's mandatory to specify kundera.datastore.file.path property in persistence.xml" ) ; } Neo4JSchemaMetadata nsmd = Neo4JPropertyReader . nsmd ; ClientProperties cp = nsmd != null ? nsmd . getClientProperties ( ) : null ; GraphDatabaseService graphDb = ( GraphDatabaseService ) getConnectionPoolOrConnection ( ) ; if ( cp != null && graphDb == null ) { DataStore dataStore = nsmd != null ? nsmd . getDataStore ( ) : null ; Properties properties = dataStore != null && dataStore . getConnection ( ) != null ? dataStore . getConnection ( ) . getProperties ( ) : null ; if ( properties != null ) { Map < String , String > config = new HashMap < String , String > ( ( Map ) properties ) ; GraphDatabaseBuilder builder = new GraphDatabaseFactory ( ) . newEmbeddedDatabaseBuilder ( datastoreFilePath ) ; builder . setConfig ( config ) ; graphDb = builder . newGraphDatabase ( ) ; // registerShutdownHook(graphDb); } } if ( graphDb == null ) { graphDb = new GraphDatabaseFactory ( ) . newEmbeddedDatabase ( datastoreFilePath ) ; // registerShutdownHook(graphDb); } return graphDb ; }
Create Neo4J Embedded Graph DB instance that acts as a Neo4J connection repository for Neo4J If a Neo4j specfic client properties file is specified in persistence . xml it initializes DB instance with those properties . Other DB instance is initialized with default properties .