Move dbCloser to MockNode, the only thing that uses it. (#1512)

This commit is contained in:
Andrzej Cichocki 2017-10-02 15:59:55 +01:00 committed by GitHub
parent 383eb2bef8
commit 12982b3034
2 changed files with 7 additions and 5 deletions

View File

@ -146,7 +146,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
protected lateinit var network: MessagingService
protected val runOnStop = ArrayList<() -> Any?>()
protected lateinit var database: CordaPersistence
protected var dbCloser: (() -> Any?)? = null
lateinit var cordappProvider: CordappProviderImpl
protected val cordappLoader by lazy { makeCordappLoader() }
@ -476,10 +475,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
database.transaction {
log.info("Connected to ${database.dataSource.connection.metaData.databaseProductName} database.")
}
this.database::close.let {
dbCloser = it
runOnStop += it
}
runOnStop += database::close
return database.transaction {
insideTransaction()
}

View File

@ -241,6 +241,12 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
// It is used from the network visualiser tool.
@Suppress("unused") val place: WorldMapLocation get() = findMyLocation()!!
private var dbCloser: (() -> Any?)? = null
override fun <T> initialiseDatabasePersistence(insideTransaction: () -> T) = super.initialiseDatabasePersistence {
dbCloser = database::close
insideTransaction()
}
fun disableDBCloseOnStop() {
runOnStop.remove(dbCloser)
}