Created
May 28, 2013 00:57
-
-
Save seratch/5659871 to your computer and use it in GitHub Desktop.
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
| import java.util.UUID | |
| import org.joda.time.DateTime | |
| import java.sql.SQLException | |
| import scala.Option | |
| import scalikejdbc.SQLInterpolation.SQLSyntaxSupport | |
| import util.control.Exception._ | |
| import java.sql.Connection | |
| import scalikejdbc._ | |
| import scalikejdbc.SQLInterpolation._ | |
| case class AbilityRow(id: UUID, can: Boolean, verb: String, subject: String, context: String) | |
| object AbilitiesTable extends SQLSyntaxSupport[AbilityRow] | |
| { | |
| def convertUUID(any : Any) : UUID = { | |
| UUID.randomUUID() | |
| } | |
| override val tableName = "abilities" | |
| def apply(a: SyntaxProvider[AbilityRow])(rs: WrappedResultSet): AbilityRow = apply(a.resultName)(rs) | |
| def apply(a: ResultName[AbilityRow])(rs: WrappedResultSet): AbilityRow = new AbilityRow(convertUUID(rs.any(a.id)), rs.boolean(a.can), rs.string(a.verb), rs.string(a.subject), rs.string(a.context)) | |
| // def opt(a: SyntaxProvider[AbilityRow])(rs: WrappedResultSet): Option[AbilityRow] = rs.intOpt(a.resultName.id).map(_ => apply(a)(rs)) | |
| } | |
| object ConsoleApp { | |
| // loading jdbc.properties | |
| private val props = new java.util.Properties | |
| props.load(classOf[AbilityRow].getClassLoader.getResourceAsStream("jdbc.properties")) | |
| // loading JDBC driver | |
| val driverClassName = props.getProperty("driverClassName") | |
| Class.forName(driverClassName) | |
| // preparing the connection pool settings | |
| val poolSettings = new ConnectionPoolSettings(initialSize = 100, maxSize = 100) | |
| // JDBC settings | |
| val url = props.getProperty("url") | |
| val user = props.getProperty("user") | |
| val password = props.getProperty("password") | |
| // create singleton(default) connection pool | |
| ConnectionPool.singleton(url, user, password, poolSettings) | |
| // named connection pool | |
| ConnectionPool.add('named, url, user, password, poolSettings) | |
| def main(args: Array[String]) { | |
| println("-----") | |
| val dbFile = "c:/work/sideprojects/nook/hermes/h2.db" | |
| val url: String = "jdbc:h2:file:" + dbFile | |
| Class.forName("org.h2.Driver") | |
| ConnectionPool.singleton("jdbc:h2:file:db/test", "sa", "") | |
| } | |
| } |
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
| version := "1.0" | |
| scalaVersion := "2.10.1" | |
| scalacOptions := Seq("-unchecked", "-language:reflectiveCalls,postfixOps,implicitConversions", "-deprecation", "-feature", "-encoding", "utf8") | |
| name := "scalikejdbc_test" | |
| libraryDependencies <+= (scalaVersion)("org.scala-lang" % "scala-compiler" % _) | |
| libraryDependencies ++= { | |
| Seq( | |
| "com.h2database" % "h2" % "1.3.171", | |
| "com.github.seratch" %% "scalikejdbc" % "[1.6,)", | |
| "com.github.seratch" %% "scalikejdbc-interpolation" % "[1.6,)" | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment