Commit e932cf38 authored by Javier Romero's avatar Javier Romero

Don't attempt to lookup all databases when database set

parent d904ef08
Pipeline #29244288 passed with stages
in 13 minutes and 49 seconds
## [Unreleased]
### Added
- Don't attempt to lookup all databases when database set
### Fixed
- Crash: http://crashes.to/s/de660f491cc
......
......@@ -17,12 +17,12 @@ import java.util.concurrent.ConcurrentHashMap
*/
class ConnectionAgent {
private val mActiveConnections = ConcurrentHashMap<ConnectionInfo, Connection>()
private val activeConnections = ConcurrentHashMap<ConnectionInfo, Connection>()
fun connect(connectionInfo: ConnectionInfo): Observable<Connection> {
return Observable.create { subscriber ->
try {
if (!mActiveConnections.containsKey(connectionInfo) || mActiveConnections[connectionInfo]?.isClosed() == true) {
if (!activeConnections.containsKey(connectionInfo) || activeConnections[connectionInfo]?.isClosed() == true) {
try {
val s = Socket()
val address = InetSocketAddress(
......@@ -58,7 +58,7 @@ class ConnectionAgent {
connectionInfo.username,
connectionInfo.password)
mActiveConnections.put(connectionInfo, connection)
activeConnections.put(connectionInfo, connection)
} catch (e: ClassNotFoundException) {
throw SQLException("Class not found: " + e.message, e)
} catch (@Suppress("TooGenericExceptionCaught") e: Exception) {
......@@ -66,7 +66,7 @@ class ConnectionAgent {
}
}
subscriber.onNext(mActiveConnections[connectionInfo])
subscriber.onNext(activeConnections[connectionInfo])
subscriber.onCompleted()
} catch (e: SQLException) {
subscriber.onError(e)
......
......@@ -25,11 +25,6 @@ import android.widget.ExpandableListView
import android.widget.LinearLayout
import android.widget.ListView
import android.widget.TextView
import com.gitlab.connect2sql.R
import kotlinx.android.synthetic.main.activity_query.fab
import kotlinx.android.synthetic.main.activity_query.lblCurrentDatabase
import kotlinx.android.synthetic.main.activity_query.lblCurrentTable
import kotlinx.android.synthetic.main.activity_query.txtQuery
import app.devlife.connect2sql.ApplicationUtils
import app.devlife.connect2sql.activity.BaseActivity
import app.devlife.connect2sql.adapter.QuickKeysAdapter
......@@ -56,11 +51,17 @@ import app.devlife.connect2sql.ui.results.ResultsActivity
import app.devlife.connect2sql.ui.savedqueries.SavedQueriesActivity
import app.devlife.connect2sql.ui.widget.Toast
import app.devlife.connect2sql.util.rx.ActivityAwareSubscriber
import com.gitlab.connect2sql.R
import kotlinx.android.synthetic.main.activity_query.fab
import kotlinx.android.synthetic.main.activity_query.lblCurrentDatabase
import kotlinx.android.synthetic.main.activity_query.lblCurrentTable
import kotlinx.android.synthetic.main.activity_query.txtQuery
import rx.Observable
import rx.Subscriber
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import java.sql.Connection
import java.util.ArrayList
import javax.inject.Inject
......@@ -332,19 +333,23 @@ class QueryActivity : BaseActivity() {
EzLogger.d("[retrieveServerGraph]")
return mConnectionAgent
.connect(connectionInfo)
.flatMap<Pair<DriverAgent.Database, DriverAgent.Table>> { connection ->
.flatMap<Pair<Connection, DriverAgent.Database>> { connection ->
when {
serverGraphSubscription == null -> Observable.empty()
!connectionInfo.database.isNullOrBlank() -> {
Observable.just(Pair(connection, DriverAgent.Database(connectionInfo.database!!)))
}
else -> driverAgent.databases(connection).map { Pair(connection, it) }
}
}
.flatMap<Pair<DriverAgent.Database, DriverAgent.Table>> { (connection, database) ->
EzLogger.v("[call] database retrieved=$database")
if (serverGraphSubscription == null) Observable.empty()
else driverAgent
.databases(connection)
.flatMap<Pair<DriverAgent.Database, DriverAgent.Table>> { database ->
EzLogger.v("[call] database retrieved=$database")
if (serverGraphSubscription == null) Observable.empty()
else driverAgent
.tables(connection, database)
.map<Pair<DriverAgent.Database, DriverAgent.Table>> { table ->
EzLogger.v("[call] table retrieved=$database/$table")
Pair(database, table)
}
.tables(connection, database)
.map<Pair<DriverAgent.Database, DriverAgent.Table>> { table ->
EzLogger.v("[call] table retrieved=$database/$table")
Pair(database, table)
}
}
.collect<MutableMap<DriverAgent.Database, MutableList<DriverAgent.Table>>>(
......
buildscript {
ext {
version_androidgradle = '3.2.0-beta05'
version_kotlin = '1.2.51'
version_kotlin = '1.2.61'
version_ktlint = '4.1.0'
version_detekt = '1.0.0.RC8'
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment