src/main/scala/bootstrap/liftweb/Boot.scala
changeset 14 5a2f996a5ba0
parent 11 43fa65f5072e
child 15 995184977e9b
equal deleted inserted replaced
13:29d4ddcd85c8 14:5a2f996a5ba0
    27 
    27 
    28 class Boot extends ProtoBoot {
    28 class Boot extends ProtoBoot {
    29   override def boot = {
    29   override def boot = {
    30 
    30 
    31     /* DB stuff */
    31     /* DB stuff */
    32     DB.defineConnectionManager(FisConnectionIdentifier, new FisDbVendor)
    32     val dbVendor = new FisDbVendor
       
    33     DB.defineConnectionManager(FisConnectionIdentifier, dbVendor)
    33     S.addAround(DB.buildLoanWrapper(List(FisConnectionIdentifier)))
    34     S.addAround(DB.buildLoanWrapper(List(FisConnectionIdentifier)))
    34     SquerylRecord.init(() => new SeqIdPostgreSqlAdapter)
    35     SquerylRecord.init(() => new SeqIdPostgreSqlAdapter)
       
    36     SquerylTxMgr.initSqueryl(FisConnectionIdentifier,
       
    37       () => new SeqIdPostgreSqlAdapter)
       
    38     LiftRules.unloadHooks.append(dbVendor.closeAllConnections_! _)
    35 
    39 
    36     super.boot
    40     super.boot
    37 
    41 
    38   }
    42   }
    39 }
    43 }
    52   override protected def testConnection(c: Connection) = {
    56   override protected def testConnection(c: Connection) = {
    53     c.prepareStatement(testQuery).executeQuery
    57     c.prepareStatement(testQuery).executeQuery
    54   }
    58   }
    55 }
    59 }
    56 
    60 
       
    61 import org.squeryl._
       
    62 import org.squeryl.internals.DatabaseAdapter
       
    63 
       
    64 object SquerylTxMgr {
       
    65   def initSqueryl(name: ConnectionIdentifier,
       
    66     mkAdapter: () => DatabaseAdapter) = {
       
    67     SessionFactory.externalTransactionManagementAdapter =
       
    68     Some(new SquerylTxMgr(name, mkAdapter))
       
    69   }
       
    70 }
       
    71 
       
    72 class SquerylTxMgr(name: ConnectionIdentifier, mkAdapter: () => DatabaseAdapter)
       
    73   extends Loggable with Function0[Session] {
       
    74 
       
    75   private object currentSession extends DynoVar[Session]
       
    76 
       
    77 
       
    78   def apply = currentSession.is openOr {
       
    79     DB.use(name) { superConn =>
       
    80       val sess = Session.create(superConn.connection, mkAdapter())
       
    81       sess.setLogger(s => logger.debug(s))
       
    82       currentSession.set(sess)
       
    83       sess
       
    84     }
       
    85   }
       
    86 }
       
    87 
    57 // vim: set ts=2 sw=2 et:
    88 // vim: set ts=2 sw=2 et: