You asked me to post further outcome of JPAExtension.
There is nothing really new, but I was able to get some space on one of
the well known Scala Maven repositories. So it should be easier to play
around with JPAExtension. It is located at
http://scala-tools.org/repo-snapshots/org/scala-libs/jpaextension/0.0.2-SNAPSHOT/
(The term extension is currently related to the filter concept, which
allows the usage of type safe holder objects for binding parameter.)
*Advantages of JPAExtension (and Scala) are e.g. :*
* Get rid of the .class parameter (eg. EntitiyManager.find)
val item: ObjectItem = find(id).get
Where the Class of the entity is inferred from the type of item. get is
part of class Option, the Scala "replacement" for none-existent/existent
values (where null is different from non-existent).
* More visual transaction scope wrapper (with stackable traits, which
allow the execution of some pre or post transaction code)
withTrxAndCommit {
val item = new ObjectItem()
. . .
persist(item)
}
* Mixins for e.g. ThreadLocal EntityManager or JNDI
EntityManagerFactory implementations
class MyClass extends Something
with JndiEntityManagerFactory("jndiName")
with ThreadLocalEntityManager {
def getPersistenceUnitName = "mip"
. . .
}
* Type safe queries(QueryWrapper)
val resultList = createQuery[ObjectItem]("Select oi from ObjectItem
oi").getResultList
* functional capabilities like findAndApply or forQueryResults
forQueryResults {
oi: ObjectItem =>
. . .
} withQuery (filter)
JPAExtension is my version of a Scala wrapper for JPA (or persistence
layer in general) and is far away from being complete.
What I would like to hear is: what do you think about it?
Or even more general:
Do you think you have to care about Scala?
How does a functional programming language influence the design of already
existing Java frameworks like JPA?
Or is it better to design completely new API (if we want to use
ORM-functionality with a new language. This is kind of reinvent the wheel)?
Or is it better to write some rather "simple" and pragmatic wrapping like
I did?
Christopher
Some additional resources:
Examples for EM, EMF, Queries: http://blog.fakod.eu/?p=855
Some entity examples: http://blog.fakod.eu/?p=955
Code: http://github.com/FaKod/JPA-for-Scala
Scala: http://www.scala-lang.org/