mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
PersistentNetworkMapCache close database connection (#1398)
This commit is contained in:
committed by
Rick Parker
parent
39e44382be
commit
e1363c91cc
@ -248,21 +248,22 @@ open class PersistentNetworkMapCache(private val serviceHub: ServiceHubInternal)
|
|||||||
private fun updateInfoDB(nodeInfo: NodeInfo) {
|
private fun updateInfoDB(nodeInfo: NodeInfo) {
|
||||||
// TODO Temporary workaround to force isolated transaction (otherwise it causes race conditions when processing
|
// TODO Temporary workaround to force isolated transaction (otherwise it causes race conditions when processing
|
||||||
// network map registration on network map node)
|
// network map registration on network map node)
|
||||||
val session = serviceHub.database.entityManagerFactory.withOptions().connection(serviceHub.database.dataSource.connection
|
serviceHub.database.dataSource.connection.use {
|
||||||
.apply {
|
val session = serviceHub.database.entityManagerFactory.withOptions().connection(it.apply {
|
||||||
transactionIsolation = 1
|
transactionIsolation = 1
|
||||||
}).openSession()
|
}).openSession()
|
||||||
|
session.use {
|
||||||
val tx = session.beginTransaction()
|
val tx = session.beginTransaction()
|
||||||
// TODO For now the main legal identity is left in NodeInfo, this should be set comparision/come up with index for NodeInfo?
|
// TODO For now the main legal identity is left in NodeInfo, this should be set comparision/come up with index for NodeInfo?
|
||||||
val info = findByIdentityKey(session, nodeInfo.legalIdentity.owningKey)
|
val info = findByIdentityKey(session, nodeInfo.legalIdentity.owningKey)
|
||||||
val nodeInfoEntry = generateMappedObject(nodeInfo)
|
val nodeInfoEntry = generateMappedObject(nodeInfo)
|
||||||
if (info.isNotEmpty()) {
|
if (info.isNotEmpty()) {
|
||||||
nodeInfoEntry.id = info[0].id
|
nodeInfoEntry.id = info[0].id
|
||||||
|
}
|
||||||
|
session.merge(nodeInfoEntry)
|
||||||
|
tx.commit()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
session.merge(nodeInfoEntry)
|
|
||||||
tx.commit()
|
|
||||||
session.close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeInfoDB(nodeInfo: NodeInfo) {
|
private fun removeInfoDB(nodeInfo: NodeInfo) {
|
||||||
|
Reference in New Issue
Block a user