Created
May 2, 2016 22:51
-
-
Save eishay/6ed19f0793b3a3a8b91086448d1b83a1 to your computer and use it in GitHub Desktop.
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
abstract class SessionWrapper(_session: => Session) extends Session { | |
lazy val session = _session | |
def conn: Connection = session.conn | |
def metaData = session.metaData | |
def capabilities = session.capabilities | |
override def resultSetType = session.resultSetType | |
override def resultSetConcurrency = session.resultSetConcurrency | |
override def resultSetHoldability = session.resultSetHoldability | |
def close() { throw new UnsupportedOperationException } | |
def rollback() { session.rollback() } | |
def withTransaction[T](f: => T): T = session.withTransaction(f) | |
private val statementCache = new mutable.HashMap[String, PreparedStatement] | |
def getPreparedStatement(statement: String): PreparedStatement = | |
statementCache.getOrElseUpdate(statement, this.conn.prepareStatement(statement)) | |
override def forParameters(rsType: ResultSetType = resultSetType, rsConcurrency: ResultSetConcurrency = resultSetConcurrency, | |
rsHoldability: ResultSetHoldability = resultSetHoldability) = throw new UnsupportedOperationException | |
} | |
abstract class RSession(roSession: => Session) extends SessionWrapper(roSession) | |
class ROSession(roSession: => Session) extends RSession(roSession) | |
class RWSession(rwSession: Session) extends RSession(rwSession) | |
implicit def roToSession(roSession: ROSession): Session = roSession.session | |
implicit def rwToSession(rwSession: RWSession): Session = rwSession.session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment