Source:
static void shutdownGraphDatabaseService(GraphDatabaseService neo4jDb) { GraphDatabaseAPI sq = (GraphDatabaseAPI) neo4jDb; String key = sq.getStoreDir().getAbsolutePath(); if ( GRAPH_DATABASE_SERVICE_MAP.containsKey( key ) ) { synchronized (GRAPH_DATABASE_SERVICE_MAP) { FactoryHolder factoryHolder = GRAPH_DATABASE_SERVICE_MAP.get( key ); factoryHolder.setCounter( factoryHolder.getCounter() - 1 ); LOG.debugf( " Counter : %s for path %s", factoryHolder.getCounter(), key ); GraphDatabaseFacade graphDatabaseFacade = factoryHolder.getGraphDatabaseFacade(); try { GraphDatabaseFacade.SPI spi = null; Object obj = getPrivateField( GraphDatabaseFacade.class.getDeclaredField( "spi" ), graphDatabaseFacade ); spi = (GraphDatabaseFacade.SPI) obj; LOG.debugf( " isInOpenTransaction: %s", spi.isInOpenTransaction() ); if ( spi.isInOpenTransaction() ) { LOG.warnf( "currentTransaction: %s", spi.currentTransaction() ); LOG.warnf( "transaction started %s", spi.currentTransaction().startTime() ); LOG.warn( "hang transactions will commited and closed .." ); spi.currentTransaction().success(); spi.currentTransaction().closeTransaction(); } } catch ( IllegalAccessException | NoSuchFieldException e) { throw new HibernateException( "Can't get value of private variable by reflection!",e ); } catch (TransactionFailureException e) { throw new HibernateException( "Can't close transaction!",e ); } if ( factoryHolder.getCounter() == 0 ) { LOG.debugf( " Shutdown db for path : %s", key ); factoryHolder.getGraphDatabaseFacade().shutdown(); GRAPH_DATABASE_SERVICE_MAP.remove( key ); } } } else { throw LOG.unknownDatabasePathException( key ); } }

Target:
static void shutdownGraphDatabaseService(GraphDatabaseService neo4jDb) { GraphDatabaseAPI sq = (GraphDatabaseAPI) neo4jDb; String key = sq.getStoreDir().getAbsolutePath(); if ( GRAPH_DATABASE_SERVICE_MAP.containsKey( key ) ) { synchronized (GRAPH_DATABASE_SERVICE_MAP) { FactoryHolder factoryHolder = GRAPH_DATABASE_SERVICE_MAP.get( key ); factoryHolder.setCounter( factoryHolder.getCounter() - 1 ); LOG.debugf( " Counter : %s for path %s", factoryHolder.getCounter(), key ); GraphDatabaseFacade graphDatabaseFacade = factoryHolder.getGraphDatabaseFacade(); try { GraphDatabaseFacade.SPI spi = null; Object obj = getPrivateField( GraphDatabaseFacade.class.getDeclaredField( "spi" ), graphDatabaseFacade ); spi = (GraphDatabaseFacade.SPI) obj; LOG.debugf( " isInOpenTransaction: %s", spi.isInOpenTransaction() ); if ( spi.isInOpenTransaction() ) { LOG.warnf( "currentTransaction: %s", spi.currentTransaction() ); LOG.warnf( "transaction started %s", spi.currentTransaction().startTime() ); spi.currentTransaction().failure(); spi.currentTransaction().closeTransaction(); throw LOG.existsOpenTransactionsFornDatabasePathException( key ); } } catch ( IllegalAccessException | NoSuchFieldException e) { throw new HibernateException( "Can't get value of private variable by reflection!",e ); } catch (TransactionFailureException e) { throw new HibernateException( "Can't close transction!",e ); } if ( factoryHolder.getCounter() == 0 ) { LOG.debugf( " Shutdown db for path : %s", key ); factoryHolder.getGraphDatabaseFacade().shutdown(); GRAPH_DATABASE_SERVICE_MAP.remove( key ); } } } else { throw LOG.unknownDatabasePathException( key ); } }