Created
July 3, 2013 16:30
-
-
Save rhyskeepence/5920163 to your computer and use it in GitHub Desktop.
squeryl
This file contains hidden or 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 sky.sns.jibberjabber | |
import org.squeryl.{Schema, Session} | |
import org.squeryl.adapters.OracleAdapter | |
import org.squeryl.PrimitiveTypeMode._ | |
object Connectaroo extends App { | |
val database = Database( | |
driver = "oracle.jdbc.driver.OracleDriver", | |
url = "jdbc:oracle:thin:@blah", | |
username = "x", | |
password = "y") | |
def configurationValue(key: String) = using(database.newSession) { | |
from(Knitware.configurations)(a => | |
where(a.key === key) | |
select a.value | |
).headOption.getOrElse("nada") | |
} | |
println(configurationValue("expression.format")) | |
} | |
class Configuration(var key: String, var value: String, var description: String) | |
object Knitware extends Schema { | |
val configurations = table[Configuration] | |
} | |
case class Database(driver: String, url: String, username: String, password: String, | |
initialPoolSize: Int = 2, maxPoolSize: Int = 10, minPoolSize: Int = 2, | |
preferredTestQuery: String = "select sysdate from dual") { | |
import com.mchange.v2.c3p0.ComboPooledDataSource | |
val pool = { | |
val ds = new ComboPooledDataSource | |
ds.setDriverClass(driver) | |
ds.setJdbcUrl(url) | |
ds.setUser(username) | |
ds.setPassword(password) | |
ds.setInitialPoolSize(initialPoolSize) | |
ds.setMaxPoolSize(maxPoolSize) | |
ds.setMinPoolSize(minPoolSize) | |
ds.setPreferredTestQuery(preferredTestQuery) | |
ds.setTestConnectionOnCheckin(true) | |
ds | |
} | |
org.squeryl.SessionFactory.concreteFactory = Some(() => newSession) | |
def newSession: Session = Session.create(pool.getConnection, new OracleAdapter) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment