Created
October 31, 2012 17:03
-
-
Save meiwin/3988318 to your computer and use it in GitHub Desktop.
App Config #Play2 #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
package utils | |
import com.twitter.querulous.query.SqlQueryFactory | |
import com.twitter.querulous.evaluator.StandardQueryEvaluatorFactory | |
import com.twitter.querulous.database.ApachePoolingDatabaseFactory | |
import com.twitter.util.Duration | |
import java.util.concurrent.TimeUnit | |
import play.api.Play.current | |
import play.api.Play.configuration | |
object AppConfig { | |
val conf = configuration | |
def getString(path: String) = conf.getString(path).getOrElse(throw new Exception("MISSING CONFIG: " + path)) | |
def getInt(path: String) = conf.getInt(path).getOrElse(throw new Exception("MISSING CONFIG: " + path)) | |
val queryFactory = new SqlQueryFactory | |
val apacheDatabasePoolingFactory = new ApachePoolingDatabaseFactory( | |
minOpenConnections = getInt("database.default.pool.minOpenConnections") | |
, maxOpenConnections = getInt("database.default.pool.maxOpenConnections") | |
, checkConnectionHealthWhenIdleFor = Duration(1, TimeUnit.SECONDS) | |
, maxWaitForConnectionReservation = Duration(10, TimeUnit.MILLISECONDS) | |
, checkConnectionHealthOnReservation = true | |
, evictConnectionIfIdleFor = Duration(5, TimeUnit.MINUTES) | |
, defaultUrlOptions = Map() | |
) | |
val queryEvaluatorFactory = new StandardQueryEvaluatorFactory(apacheDatabasePoolingFactory, queryFactory) | |
val queryEvaluator = queryEvaluatorFactory( | |
dbhost = getString("database.default.host") | |
, dbname = getString("database.default.dbname") | |
, username = getString("database.default.username") | |
, password = getString("database.default.password") | |
) | |
} |
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
# database configuration | |
database.default { | |
host : "localhost", | |
dbname : "chatty", | |
username : "root", | |
password : "bubbly", | |
pool { | |
minOpenConnections : 5, | |
maxOpenConnections : 5 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment