This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
forked from nkallen/querulous
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor connectionpools into 'databases'
- Loading branch information
Ed Ceaser
committed
Feb 11, 2010
1 parent
6fd1a0f
commit 124e98d
Showing
15 changed files
with
107 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
src/main/scala/com/twitter/querulous/connectionpool/MemoizingConnectionPoolFactory.scala
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
src/main/scala/com/twitter/querulous/connectionpool/StatsCollectingConnectionPool.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...ulous/connectionpool/ConnectionPool.scala → ...twitter/querulous/database/Database.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/scala/com/twitter/querulous/database/MemoizingDatabase.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.twitter.querulous.database | ||
|
||
import scala.collection.mutable | ||
|
||
class MemoizingDatabaseFactory(databaseFactory: DatabaseFactory) extends DatabaseFactory { | ||
private val databases = new mutable.HashMap[String, Database] | ||
|
||
def apply(dbhosts: List[String], dbname: String, username: String, password: String) = synchronized { | ||
databases.getOrElseUpdate( | ||
dbhosts.first + "/" + dbname, | ||
databaseFactory(dbhosts, dbname, username, password)) | ||
} | ||
|
||
def close() { | ||
for ((name, pool) <- databases) pool.close() | ||
databases.clear() | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/scala/com/twitter/querulous/database/StatsCollectingDatabase.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.twitter.querulous.database | ||
|
||
import java.sql.Connection | ||
|
||
class StatsCollectingDatabaseFactory( | ||
databaseFactory: DatabaseFactory, | ||
stats: StatsCollector) extends DatabaseFactory { | ||
|
||
def apply(dbhosts: List[String], dbname: String, username: String, password: String): Database = { | ||
new StatsCollectingDatabase(databaseFactory(dbhosts, dbname, username, password), stats) | ||
} | ||
} | ||
|
||
class StatsCollectingDatabase(pool: Database, stats: StatsCollector) | ||
extends Database { | ||
|
||
override def reserve(): Connection = { | ||
stats.time("connection-pool-reserve-timing") { | ||
pool.reserve() | ||
} | ||
} | ||
|
||
override def release(connection: Connection) = { | ||
stats.time("connection-pool-release-timing") { | ||
pool.release(connection) | ||
} | ||
} | ||
|
||
override def close() = { | ||
pool.close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.