PersistentNetworkMapCache close database connection (#1398)

This commit is contained in:
Katarzyna Streich 2017-09-04 09:41:00 +01:00 committed by Rick Parker
parent 39e44382be
commit e1363c91cc

View File

@ -248,11 +248,11 @@ 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)
@ -262,7 +262,8 @@ open class PersistentNetworkMapCache(private val serviceHub: ServiceHubInternal)
} }
session.merge(nodeInfoEntry) session.merge(nodeInfoEntry)
tx.commit() tx.commit()
session.close() }
}
} }
private fun removeInfoDB(nodeInfo: NodeInfo) { private fun removeInfoDB(nodeInfo: NodeInfo) {