|
11
|
1 |
/*
|
|
|
2 |
* Copyright 2011 Tomas Zeman <tzeman@volny.cz>
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
package bootstrap.liftweb
|
|
|
17 |
|
|
|
18 |
import fis.base.model._
|
|
15
|
19 |
import fis.crm.ui.ContactSnippet
|
|
11
|
20 |
import net.liftweb.common._
|
|
|
21 |
import net.liftweb.db.{DB, ConnectionIdentifier}
|
|
|
22 |
import net.liftweb.http._
|
|
15
|
23 |
import net.liftweb.sitemap._
|
|
11
|
24 |
import net.liftweb.squerylrecord.SquerylRecord
|
|
|
25 |
import net.liftweb.util._
|
|
|
26 |
import net.liftweb.util.Helpers._
|
|
|
27 |
import net.tz.lift.boot.ProtoBoot
|
|
|
28 |
import net.tz.lift.util.StandardDBVendor
|
|
|
29 |
|
|
|
30 |
class Boot extends ProtoBoot {
|
|
|
31 |
override def boot = {
|
|
|
32 |
|
|
|
33 |
/* DB stuff */
|
|
14
|
34 |
val dbVendor = new FisDbVendor
|
|
|
35 |
DB.defineConnectionManager(FisConnectionIdentifier, dbVendor)
|
|
11
|
36 |
S.addAround(DB.buildLoanWrapper(List(FisConnectionIdentifier)))
|
|
|
37 |
SquerylRecord.init(() => new SeqIdPostgreSqlAdapter)
|
|
14
|
38 |
SquerylTxMgr.initSqueryl(FisConnectionIdentifier,
|
|
|
39 |
() => new SeqIdPostgreSqlAdapter)
|
|
|
40 |
LiftRules.unloadHooks.append(dbVendor.closeAllConnections_! _)
|
|
11
|
41 |
|
|
|
42 |
super.boot
|
|
|
43 |
|
|
15
|
44 |
import Loc._
|
|
|
45 |
|
|
|
46 |
val menus = List(Menu("/", "FIS Main page") / "index" >> Hidden,
|
|
|
47 |
Menu.i("Home") / "" , ContactSnippet.menu)
|
|
|
48 |
|
|
|
49 |
LiftRules.setSiteMap(SiteMap(menus:_*))
|
|
11
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
case object FisConnectionIdentifier extends ConnectionIdentifier {
|
|
|
54 |
val jndiName = "fis"
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
import java.sql.Connection
|
|
|
58 |
|
|
|
59 |
class FisDbVendor extends StandardDBVendor(
|
|
|
60 |
"org.postgresql.Driver", Props.get("db.fis.url", ""),
|
|
|
61 |
Props.get("db.fis.user"), Props.get("db.fis.pass")) {
|
|
|
62 |
|
|
|
63 |
val testQuery = "SELECT version()"
|
|
|
64 |
override protected def testConnection(c: Connection) = {
|
|
|
65 |
c.prepareStatement(testQuery).executeQuery
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
14
|
69 |
import org.squeryl._
|
|
|
70 |
import org.squeryl.internals.DatabaseAdapter
|
|
|
71 |
|
|
|
72 |
object SquerylTxMgr {
|
|
|
73 |
def initSqueryl(name: ConnectionIdentifier,
|
|
|
74 |
mkAdapter: () => DatabaseAdapter) = {
|
|
|
75 |
SessionFactory.externalTransactionManagementAdapter =
|
|
|
76 |
Some(new SquerylTxMgr(name, mkAdapter))
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
class SquerylTxMgr(name: ConnectionIdentifier, mkAdapter: () => DatabaseAdapter)
|
|
|
81 |
extends Loggable with Function0[Session] {
|
|
|
82 |
|
|
|
83 |
private object currentSession extends DynoVar[Session]
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
def apply = currentSession.is openOr {
|
|
|
87 |
DB.use(name) { superConn =>
|
|
|
88 |
val sess = Session.create(superConn.connection, mkAdapter())
|
|
|
89 |
sess.setLogger(s => logger.debug(s))
|
|
|
90 |
currentSession.set(sess)
|
|
|
91 |
sess
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
11
|
96 |
// vim: set ts=2 sw=2 et:
|