mirror of
https://github.com/corda/corda.git
synced 2024-12-22 14:22:28 +00:00
PersistentNetworkMapCache close database connection (#1398)
This commit is contained in:
parent
39e44382be
commit
e1363c91cc
@ -248,21 +248,22 @@ open class PersistentNetworkMapCache(private val serviceHub: ServiceHubInternal)
|
||||
private fun updateInfoDB(nodeInfo: NodeInfo) {
|
||||
// TODO Temporary workaround to force isolated transaction (otherwise it causes race conditions when processing
|
||||
// network map registration on network map node)
|
||||
val session = serviceHub.database.entityManagerFactory.withOptions().connection(serviceHub.database.dataSource.connection
|
||||
.apply {
|
||||
transactionIsolation = 1
|
||||
}).openSession()
|
||||
|
||||
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?
|
||||
val info = findByIdentityKey(session, nodeInfo.legalIdentity.owningKey)
|
||||
val nodeInfoEntry = generateMappedObject(nodeInfo)
|
||||
if (info.isNotEmpty()) {
|
||||
nodeInfoEntry.id = info[0].id
|
||||
serviceHub.database.dataSource.connection.use {
|
||||
val session = serviceHub.database.entityManagerFactory.withOptions().connection(it.apply {
|
||||
transactionIsolation = 1
|
||||
}).openSession()
|
||||
session.use {
|
||||
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?
|
||||
val info = findByIdentityKey(session, nodeInfo.legalIdentity.owningKey)
|
||||
val nodeInfoEntry = generateMappedObject(nodeInfo)
|
||||
if (info.isNotEmpty()) {
|
||||
nodeInfoEntry.id = info[0].id
|
||||
}
|
||||
session.merge(nodeInfoEntry)
|
||||
tx.commit()
|
||||
}
|
||||
}
|
||||
session.merge(nodeInfoEntry)
|
||||
tx.commit()
|
||||
session.close()
|
||||
}
|
||||
|
||||
private fun removeInfoDB(nodeInfo: NodeInfo) {
|
||||
|
Loading…
Reference in New Issue
Block a user