Permalink
Browse files

Wrap db access in inTrasaction{} blocks so that a new transaction is …

…started if one does not already exist.
  • Loading branch information...
1 parent 86ee922 commit 43ee3440f5df21739ef6d8c25dd647c5d28f8090 @davewhittaker davewhittaker committed Dec 20, 2011
Showing with 14 additions and 6 deletions.
  1. +14 −6 persistence/squeryl-record/src/main/scala/net/liftweb/squerylrecord/CRUDify.scala
View
20 persistence/squeryl-record/src/main/scala/net/liftweb/squerylrecord/CRUDify.scala
@@ -42,11 +42,15 @@ trait CRUDify[K, T <: Record[T] with KeyedEntity[K]] extends Crudify {
override def computeFieldFromPointer(instance: TheCrudType, pointer: FieldPointerType): Box[FieldPointerType] = instance.fieldByName(pointer.name)
- override def findForParam(in: String): Box[TheCrudType] = {
- table.lookup(idFromString(in))
- }
+ override def findForParam(in: String): Box[TheCrudType] =
+ inTransaction{
+ table.lookup(idFromString(in))
+ }
- override def findForList(start: Long, count: Int) = from(table)(t => select(t)).page(start.toInt, count).toList
+ override def findForList(start: Long, count: Int) =
+ inTransaction{
+ from(table)(t => select(t)).page(start.toInt, count).toList
+ }
override def create = createRecord
@@ -58,10 +62,14 @@ trait CRUDify[K, T <: Record[T] with KeyedEntity[K]] extends Crudify {
def save = {
if (in.isPersisted) {
- table.update(in)
+ inTransaction{
+ table.update(in)
+ }
}
else {
- table.insert(in)
+ inTransaction {
+ table.insert(in)
+ }
}
true
}

0 comments on commit 43ee344

Please sign in to comment.