Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 4839dc01da
Fetching contributors…

Cannot retrieve contributors at this time

36 lines (30 sloc) 1.188 kB
package com.twitter.querulous.database
import com.twitter.xrayspecs.Duration
import com.twitter.xrayspecs.TimeConversions._
import java.sql.{Connection, SQLException, SQLIntegrityConstraintViolationException}
class AutoDisablingDatabaseFactory(databaseFactory: DatabaseFactory, disableErrorCount: Int, disableDuration: Duration) extends DatabaseFactory {
def apply(dbhosts: List[String], dbname: String, username: String, password: String, urlOptions: Map[String, String]) = {
new AutoDisablingDatabase(
databaseFactory(dbhosts, dbname, username, password, urlOptions),
dbhosts.first,
disableErrorCount,
disableDuration)
}
}
class AutoDisablingDatabase(database: Database, dbhost: String, protected val disableErrorCount: Int, protected val disableDuration: Duration) extends Database with AutoDisabler {
def open() = {
throwIfDisabled(dbhost)
try {
val rv = database.open()
noteOperationOutcome(true)
rv
} catch {
case e: SQLException =>
noteOperationOutcome(false)
throw e
case e: Exception =>
throw e
}
}
def close(connection: Connection) { database.close(connection) }
}
Jump to Line
Something went wrong with that request. Please try again.