Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 46329d366f9e8263637874ad991622d40e993222 2 parents f1b9493 + 3f3d6d0
Ed Ceaser authored
Showing with 21 additions and 83 deletions.
  1. +0 −15 src/main/scala/com/twitter/querulous/Connection.scala
  2. +2 −4 src/main/scala/com/twitter/querulous/database/ApachePoolingDatabase.scala
  3. +2 −0  src/main/scala/com/twitter/querulous/database/Database.scala
  4. +2 −0  src/main/scala/com/twitter/querulous/database/StatsCollectingDatabase.scala
  5. +1 −0  src/main/scala/com/twitter/querulous/database/TimingOutDatabase.scala
  6. +1 −1  src/main/scala/com/twitter/querulous/evaluator/Transaction.scala
  7. +1 −1  src/main/scala/com/twitter/querulous/query/DebuggingQuery.scala
  8. +1 −1  src/main/scala/com/twitter/querulous/query/Query.scala
  9. +1 −1  src/main/scala/com/twitter/querulous/query/RetryingQuery.scala
  10. +1 −1  src/main/scala/com/twitter/querulous/query/SqlQuery.scala
  11. +1 −1  src/main/scala/com/twitter/querulous/query/StatsCollectingQuery.scala
  12. +3 −2 src/main/scala/com/twitter/querulous/query/TimingOutQuery.scala
  13. +1 −0  src/main/scala/com/twitter/querulous/test/FakeDatabase.scala
  14. +0 −54 src/test/scala/com/twitter/querulous/unit/ConnectionSpec.scala
  15. +1 −1  src/test/scala/com/twitter/querulous/unit/QueryEvaluatorSpec.scala
  16. +1 −1  src/test/scala/com/twitter/querulous/unit/SqlQuerySpec.scala
  17. +1 −0  src/test/scala/com/twitter/querulous/unit/StatsCollectingDatabaseSpec.scala
  18. +1 −0  src/test/scala/com/twitter/querulous/unit/TimingOutDatabaseSpec.scala
View
15 src/main/scala/com/twitter/querulous/Connection.scala
@@ -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)
-}
View
6 src/main/scala/com/twitter/querulous/database/ApachePoolingDatabase.scala
@@ -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
}
View
2  src/main/scala/com/twitter/querulous/database/Database.scala
@@ -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
}
View
2  src/main/scala/com/twitter/querulous/database/StatsCollectingDatabase.scala
@@ -1,5 +1,7 @@
package com.twitter.querulous.database
+import java.sql.Connection
+
class StatsCollectingDatabaseFactory(
databaseFactory: DatabaseFactory,
stats: StatsCollector) extends DatabaseFactory {
View
1  src/main/scala/com/twitter/querulous/database/TimingOutDatabase.scala
@@ -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 = {
View
2  src/main/scala/com/twitter/querulous/evaluator/Transaction.scala
@@ -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 {
View
2  src/main/scala/com/twitter/querulous/query/DebuggingQuery.scala
@@ -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*) = {
View
2  src/main/scala/com/twitter/querulous/query/Query.scala
@@ -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
View
2  src/main/scala/com/twitter/querulous/query/RetryingQuery.scala
@@ -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 {
View
2  src/main/scala/com/twitter/querulous/query/SqlQuery.scala
@@ -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
View
2  src/main/scala/com/twitter/querulous/query/StatsCollectingQuery.scala
@@ -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 {
View
5 src/main/scala/com/twitter/querulous/query/TimingOutQuery.scala
@@ -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
}
}
View
1  src/main/scala/com/twitter/querulous/test/FakeDatabase.scala
@@ -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
View
54 src/test/scala/com/twitter/querulous/unit/ConnectionSpec.scala
@@ -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)
- }
- }
- }
-}
-
View
2  src/test/scala/com/twitter/querulous/unit/QueryEvaluatorSpec.scala
@@ -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
View
2  src/test/scala/com/twitter/querulous/unit/SqlQuerySpec.scala
@@ -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
View
1  src/test/scala/com/twitter/querulous/unit/StatsCollectingDatabaseSpec.scala
@@ -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
View
1  src/test/scala/com/twitter/querulous/unit/TimingOutDatabaseSpec.scala
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.