Skip to content

Commit

Permalink
Move dbCloser to MockNode, the only thing that uses it. (corda#1512)
Browse files Browse the repository at this point in the history
  • Loading branch information
andr3ej authored Oct 2, 2017
1 parent 383eb2b commit 12982b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 1 addition & 5 deletions node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() }

Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 12982b3

Please sign in to comment.