Skip to content

Commit

Permalink
chore: be more reliable when detecting if a connection is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
kmruiz committed Jun 28, 2024
1 parent 0701b9a commit a984d25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MdbJavaEditorToolbar(
model.addAll(value)
selectDataSourceWithId(selectedItem)
}
get() = (connectionComboBox.model as DefaultComboBoxModel<LocalDataSource>).asSequence().toList()
get() = (connectionComboBox.model as DefaultComboBoxModel<LocalDataSource>).asSequence().toList().filterNotNull()

var selectedDataSource: LocalDataSource?
set(value) {
Expand All @@ -98,7 +98,11 @@ class MdbJavaEditorToolbar(
if (id == null) {
connectionComboBox.selectedItem = null
} else {
val dataSourceIndex = dataSources.indexOf { it.uniqueId == id }
val dataSourceIndex =
(connectionComboBox.model as DefaultComboBoxModel<LocalDataSource?>)
.asSequence()
.toList()
.indexOf { it?.uniqueId == id }
if (dataSourceIndex == -1) {
connectionComboBox.selectedItem = null
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ fun LocalDataSource.isConnected(): Boolean =
DatabaseConnectionManager
.getInstance()
.activeConnections
.find {
it.connectionPoint.dataSource == dataSource
}.let {
runCatching { it?.remoteConnection?.isClosed == false && it.remoteConnection.isValid(5) }.getOrDefault(false)
.any {
it.connectionPoint.dataSource == dataSource &&
runCatching {
!it.remoteConnection.isClosed && it.remoteConnection.isValid(5)
}.getOrDefault(false)
}

0 comments on commit a984d25

Please sign in to comment.