Skip to content
Browse files

change db/qry constructor API to inject a new factory

  • Loading branch information...
1 parent 894fe49 commit 25f8adabffae8fa17062010443a22548eba12532 eaceaser committed Apr 26, 2011
View
2 project/build.properties
@@ -3,6 +3,6 @@
project.organization=com.twitter
project.name=querulous
sbt.version=0.7.4
-project.version=2.0.2-SNAPSHOT
+project.version=2.0.2-stats-SNAPSHOT
build.scala.versions=2.8.1
project.initialize=false
View
10 src/main/scala/com/twitter/querulous/config/Database.scala
@@ -35,7 +35,11 @@ class Database {
def timeout_=(t: TimingOutDatabase) { timeout = Some(t) }
var memoize: Boolean = true
- def apply(stats: StatsCollector): DatabaseFactory = {
+ def apply(stats: StatsCollector): DatabaseFactory = apply(stats, None)
+
+ def apply(stats: StatsCollector, statsFactory: DatabaseFactory => DatabaseFactory): DatabaseFactory = apply(stats, Some(statsFactory))
+
+ def apply(stats: StatsCollector, statsFactory: Option[DatabaseFactory => DatabaseFactory]): DatabaseFactory = {
var factory: DatabaseFactory = pool.map(apacheConfig =>
new ApachePoolingDatabaseFactory(
apacheConfig.sizeMin,
@@ -54,6 +58,10 @@ class Database {
timeoutConfig.poolSize)
}
+ statsFactory.foreach { f =>
+ factory = f(factory)
+ }
+
if (stats ne NullStatsCollector) {
factory = new StatsCollectingDatabaseFactory(factory, stats)
}
View
7 src/main/scala/com/twitter/querulous/config/Query.scala
@@ -29,7 +29,11 @@ class Query {
var retries: Int = 0
var debug: (String => Unit) = NoDebugOutput
- def apply(statsCollector: StatsCollector): QueryFactory = {
+ def apply(statsCollector: StatsCollector): QueryFactory = apply(statsCollector, None)
+
+ def apply(statsCollector: StatsCollector, statsFactory: QueryFactory => QueryFactory): QueryFactory = apply(statsCollector, Some(statsFactory))
+
+ def apply(statsCollector: StatsCollector, statsFactory: Option[QueryFactory => QueryFactory]): QueryFactory = {
var queryFactory: QueryFactory = new SqlQueryFactory
if (!timeouts.isEmpty) {
@@ -40,6 +44,7 @@ class Query {
queryFactory = new PerQueryTimingOutQueryFactory(new SqlQueryFactory, tupleTimeout)
}
+ statsFactory.foreach { f => queryFactory = f(queryFactory) }
if (statsCollector ne NullStatsCollector) {
queryFactory = new StatsCollectingQueryFactory(queryFactory, statsCollector)
}
View
9 src/main/scala/com/twitter/querulous/config/QueryEvaluator.scala
@@ -1,6 +1,8 @@
package com.twitter.querulous.config
import com.twitter.querulous._
+import com.twitter.querulous.database.DatabaseFactory
+import com.twitter.querulous.query.QueryFactory
import com.twitter.util.Duration
import evaluator._
@@ -16,10 +18,11 @@ class QueryEvaluator {
var autoDisable: Option[AutoDisablingQueryEvaluator] = None
def autoDisable_=(a: AutoDisablingQueryEvaluator) { autoDisable = Some(a) }
-
- def apply(stats: StatsCollector): QueryEvaluatorFactory = {
+ def apply(stats: StatsCollector): QueryEvaluatorFactory = apply(stats, None, None)
+ def apply(stats: StatsCollector, dbStatsFactory: DatabaseFactory => DatabaseFactory, queryStatsFactory: QueryFactory => QueryFactory): QueryEvaluatorFactory = apply(stats, Some(dbStatsFactory), Some(queryStatsFactory))
+ def apply(stats: StatsCollector, dbStatsFactory: Option[DatabaseFactory => DatabaseFactory], queryStatsFactory: Option[QueryFactory => QueryFactory]): QueryEvaluatorFactory = {
var factory: QueryEvaluatorFactory =
- new StandardQueryEvaluatorFactory(database(stats), query(stats))
+ new StandardQueryEvaluatorFactory(database(stats, dbStatsFactory), query(stats, queryStatsFactory))
autoDisable.foreach { disable =>
factory = new AutoDisablingQueryEvaluatorFactory(

0 comments on commit 25f8ada

Please sign in to comment.
Something went wrong with that request. Please try again.