Thanks
>
> Does anyone have any examples of how you're stitching together scala
> and hibernate?
I'd like to see this too... especially in the wiki!
> I'm looking for the most basic of basics; an example
> scala domain class and how the hibernate mapping works with it, or
> something at least at that level.
>
> Thanks
>
> >
--
David Pollak
http://blog.lostlake.org
On Dec 19, 2007, at 4:13 AM, Michael Campbell wrote:
>
> Does anyone have any examples of how you're stitching together scala
> and hibernate?
I'd like to see this too... especially in the wiki!
> I'm looking for the most basic of basics; an example
> scala domain class and how the hibernate mapping works with it, or
> something at least at that level.
>
> Thanks
>
> >
--
David Pollak
http://blog.lostlake.org
/lift/ committer (www.liftweb.net)
SGS member (Scala Group Sweden)
SEJUG member (Swedish Java User Group)
Coffee drinker (Skånerost)
\_____________________________________/
I found this mention of lift, but it makes it seem like you can't use
lift with hibernate.
http://jonasfagundes.com/blog/2008/01/grails-the-good-the-ugly-and-the-bad
On Dec 19 2007, 8:15 am, David Pollak < d...@athena.com> wrote:
> On Dec 19, 2007, at 4:13 AM, Michael Campbell wrote:
>
>
>
> > Does anyone have any examples of how you're stitching together scala
> > andhibernate?
>
> I'd like to see this too... especially in the wiki!
>
> > I'm looking for the most basic of basics; an example
> > scala domain class and how thehibernatemapping works with it, or
> > something at least at that level.
>
> > Thanks
>
> --
> David Pollakhttp://blog.lostlake.org
There was a base actor for all actors servicing a class:
abstract class ServiceActor[T](val servicedClass : Class[T]) extends Actor {
override def act {
loop {
react {
provide
}
}
}
def provide : PartialFunction[Any,Unit]
def services(f : PartialFunction[Any,Unit]) = f
}
so if i wanted to implement CRUD operations I'd first write a convenience trait:
trait CRUDServices[T <: POSO] {
val serviceActor : CRUDService[T]
def delete(poso : T) = serviceActor !? Delete(poso)
def get(id : int) : T = (serviceActor !? Get(id)).asInstanceOf[T]
def save(poso : T) : int = (serviceActor !? Save(poso)).asInstanceOf[int]
}
and then I'd implement that actor:
class CRUDService[T <: POSO](servicedClass : Class[T]) extends
ServiceActor[T](servicedClass) with CRUDServices {
override val serviceActor = this
override def provide = services {
case Save(poso) => reply {
transact((s, t) => s.save(poso))
poso.id
}
case Delete(poso) => reply(transact((s,t) => s.delete(poso)))
case Get(id) => reply {
transact { (s,t) =>
val poso = s.load(servicedClass, id).asInstanceOf[T]
Hibernate.initialize(poso)
poso.id = id
poso
}
}
}
}
and now for... THE END RESULT!
If I just wanted an instance of a generic crud service to manage a
class I could:
val service = new CRUDService(classOf[User])
service.start
service.delete(user)
or if I needed to batch a mass delete of users and then move on to do
other stuff:
users.foreach(service ! Delete(_))
Or if I wanted to get fancy and implement some non-crud operations or
override crud operations:
// This will need to be started before it can be used
object UserService extends CRUDService(classOf[User]) {
override def provide = services {
case GetFriends(id) => reply(/*...*/)
case Delete(poso) => reply(/* overrides generic delete */)
} orElse super.provide
}
and that's all you need to do stuff like
UserService.delete(user)
// or
val user = UserService.get(id)
This is a really cool system and you can wire it to do some very fun
stuff. With Terracotta integration it is even better. In my POSO
(plain old scala object) trait I have tie ins to crud operations so I
can do stuff like
user.delete
// and
user.save
I've also written a bunch of hibernate utilities for searching,
paginating, etc.
/lift/ committer (www.liftweb.net)
SGS member (Scala Group Sweden)
SEJUG member (Swedish Java User Group)
\_____________________________________/