Permalink
Browse files

Merge branch 'master' of github.com:nkallen/querulous

  • Loading branch information...
2 parents f1b9493 + 3f3d6d0 commit 46329d366f9e8263637874ad991622d40e993222 Ed Ceaser committed Feb 23, 2010
@@ -1,15 +0,0 @@
-package com.twitter.querulous
-
-import java.sql.{Connection => JConnection, PreparedStatement}
-
-class Connection(connection: JConnection, val hosts: Seq[String]) {
- def commit(): Unit = connection.commit()
-
- def close(): Unit = connection.close()
-
- def rollback(): Unit = connection.rollback()
-
- def prepareStatement(query: String): PreparedStatement = connection.prepareStatement(query)
-
- def setAutoCommit(value: Boolean): Unit = connection.setAutoCommit(value)
-}
@@ -1,6 +1,6 @@
package com.twitter.querulous.database
-import java.sql.SQLException
+import java.sql.{SQLException, Connection}
import org.apache.commons.dbcp.{PoolableConnectionFactory, DriverManagerConnectionFactory, PoolingDataSource}
import org.apache.commons.pool.impl.{GenericObjectPool, StackKeyedObjectPoolFactory}
import com.twitter.xrayspecs.Duration
@@ -73,9 +73,7 @@ class ApachePoolingDatabase(
}
}
- def open() = {
- new Connection(poolingDataSource.getConnection(), dbhosts)
- }
+ def open() = poolingDataSource.getConnection()
override def toString = dbhosts.first + "_" + dbname
}
@@ -1,5 +1,7 @@
package com.twitter.querulous.database
+import java.sql.Connection
+
trait DatabaseFactory {
def apply(dbhosts: List[String], dbname: String, username: String, password: String): Database
}
@@ -1,5 +1,7 @@
package com.twitter.querulous.database
+import java.sql.Connection
+
class StatsCollectingDatabaseFactory(
databaseFactory: DatabaseFactory,
stats: StatsCollector) extends DatabaseFactory {
@@ -2,6 +2,7 @@ package com.twitter.querulous.database
import java.util.concurrent.{TimeoutException => JTimeoutException, _}
import com.twitter.xrayspecs.Duration
+import java.sql.Connection
class TimingOutDatabaseFactory(databaseFactory: DatabaseFactory, poolSize: Int, queueSize: Int, openTimeout: Duration, initialTimeout: Duration) extends DatabaseFactory {
def apply(dbhosts: List[String], dbname: String, username: String, password: String): Database = {
@@ -1,6 +1,6 @@
package com.twitter.querulous.evaluator
-import java.sql.{ResultSet, SQLException, SQLIntegrityConstraintViolationException}
+import java.sql.{ResultSet, SQLException, SQLIntegrityConstraintViolationException, Connection}
import com.twitter.querulous.query.QueryFactory
class Transaction(queryFactory: QueryFactory, connection: Connection) extends QueryEvaluator {
@@ -1,6 +1,6 @@
package com.twitter.querulous.query
-import java.sql.{Timestamp}
+import java.sql.{Timestamp, Connection}
class DebuggingQueryFactory(queryFactory: QueryFactory, log: String => Unit) extends QueryFactory {
def apply(connection: Connection, query: String, params: Any*) = {
@@ -1,6 +1,6 @@
package com.twitter.querulous.query
-import java.sql.ResultSet
+import java.sql.{ResultSet, Connection}
trait QueryFactory {
def apply(connection: Connection, queryString: String, params: Any*): Query
@@ -1,6 +1,6 @@
package com.twitter.querulous.query
-import java.sql.SQLException
+import java.sql.{SQLException, Connection}
import com.twitter.xrayspecs.Duration
class RetryingQueryFactory(queryFactory: QueryFactory, retries: Int) extends QueryFactory {
@@ -1,6 +1,6 @@
package com.twitter.querulous.query
-import java.sql.{PreparedStatement, ResultSet, SQLException, Timestamp}
+import java.sql.{PreparedStatement, ResultSet, SQLException, Timestamp, Connection}
import java.util.regex.Pattern
import scala.collection.mutable
@@ -1,6 +1,6 @@
package com.twitter.querulous.query
-import java.sql.ResultSet
+import java.sql.{ResultSet, Connection}
class StatsCollectingQueryFactory(queryFactory: QueryFactory, stats: StatsCollector)
extends QueryFactory {
@@ -1,8 +1,9 @@
package com.twitter.querulous.query
-import java.sql.SQLException
+import java.sql.{SQLException, Connection}
import com.twitter.xrayspecs.Duration
+
class SqlTimeoutException extends SQLException("Query timeout")
class TimingOutQueryFactory(queryFactory: QueryFactory, timeout: Duration) extends QueryFactory {
@@ -28,7 +29,7 @@ class TimingOutQuery(query: Query, timeout: Duration) extends QueryProxy(query)
cancel()
}
} catch {
- case e: TimeoutException =>
+ case e: TimeoutException =>
throw new SqlTimeoutException
}
}
@@ -1,5 +1,6 @@
package com.twitter.querulous.test
+import java.sql.Connection
import com.twitter.xrayspecs.{Duration, Time}
import com.twitter.xrayspecs.TimeConversions._
import com.twitter.querulous.database.Database
@@ -1,54 +0,0 @@
-package com.twitter.querulous.unit
-
-import java.sql.{Connection => JConnection}
-import org.specs.Specification
-import org.specs.mock.JMocker
-
-object ConnectionSpec extends Specification with JMocker {
- "Connection" should {
- "delegate" in {
- val sqlConnection = mock[JConnection]
- var connection: Connection = null
-
- doBefore {
- connection = new Connection(sqlConnection, List("host1", "host2"))
- }
-
- "commit" >> {
- expect {
- one(sqlConnection).commit()
- }
- connection.commit()
- }
-
- "close" >> {
- expect {
- one(sqlConnection).close()
- }
- connection.close()
- }
-
- "rollback" >> {
- expect {
- one(sqlConnection).rollback()
- }
- connection.rollback()
- }
-
- "prepareStatement" >> {
- expect {
- one(sqlConnection).prepareStatement("SELECT 1 FROM DUAL")
- }
- connection.prepareStatement("SELECT 1 FROM DUAL")
- }
-
- "setAutoCommit" >> {
- expect {
- one(sqlConnection).setAutoCommit(true)
- }
- connection.setAutoCommit(true)
- }
- }
- }
-}
-
@@ -1,6 +1,6 @@
package com.twitter.querulous.unit
-import java.sql.{SQLException, DriverManager}
+import java.sql.{SQLException, DriverManager, Connection}
import scala.collection.mutable
import net.lag.configgy.Configgy
import com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException
@@ -1,6 +1,6 @@
package com.twitter.querulous.unit
-import java.sql.PreparedStatement
+import java.sql.{PreparedStatement, Connection}
import org.specs.Specification
import org.specs.mock.{ClassMocker, JMocker}
import com.twitter.querulous.query.SqlQuery
@@ -1,6 +1,7 @@
package com.twitter.querulous.unit
import scala.collection.mutable.Map
+import java.sql.Connection
import org.specs.Specification
import org.specs.mock.{ClassMocker, JMocker}
import com.twitter.querulous.database.StatsCollectingDatabase
@@ -1,6 +1,7 @@
package com.twitter.querulous.unit
import java.util.concurrent.{CountDownLatch, TimeUnit}
+import java.sql.Connection
import com.twitter.querulous.TimeoutException
import com.twitter.querulous.database.{Database, TimingOutDatabase}
import com.twitter.xrayspecs.Time

0 comments on commit 46329d3

Please sign in to comment.