db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matthew Adams" <matthew.ad...@xcalia.com>
Subject [DISCUSS] Convenient PC method introductions
Date Fri, 23 Feb 2007 21:36:36 GMT
This was discussed on the Feb 23 JDO conf call.  Please review and
discuss.

Overview:
Grails is a promising new framework for lightweight, Rails-style
development.  It uses GORM, which introduces several nice features to
persistent objects, but it is hard-coded against Hibernate and won't
currently run outside of the Grails application framework.

Motivation:
* Frameworks like GORM are currently specific to Hibernate only, and
they can't (to my knowledge) be extracted from Grails
* Spring provides some conveniences via JDOTemplate that would be nice
in general.

Spring has several convenient methods offered via JDOTemplate that can
be offered in an intuitive way in a manner similar to GORM.

With the introduction of JDO 2.1's PMF.getPersistenceManagerProxy(),
there are new possibilites to introduce to persistent classes convenient
static & instance methods without any work on the developer's part.

Proposed solution:
* Introduce convenient static & instance methods on persistent classes
* Identify a way to make PMF available across application
* Leverage pmf.getPersistenceManagerProxy() in introduced methods

Details:

There are some catchy (the author would say "hilarious") names for
Groovy persistence integration, as that was my original thought:

Gentities
Grentities
Perstroovy
Gersistence
Groovistence
Proovy
Proovy Gersistence
GDO:  Groovy Data Objects == Groovy + JDO
GPA:  Groovy Persistence API == Groovy + JPA
["GORM" is currently "Grails ORM" == Groovy + Hibernate within Grails
(should have been Ghibe, Ghibernate, Gribe or Gribernate to be more
accurate)]

Introducing via AOP is another possibility, but they're not as good as
the stuff above:

Paop (pronouned "pow-p":  Persistence with AOP)
Aspersistence (kind of like "aspirin")
Aspectistance
Aspentities
AOE (pronouned "ow":  Aspect-oriented Entities)
Jadaop (pronouned "jah dow-p": JDO & AOP)

Enough with the catchy names.

* Need some way to make PMF available to application, like Grails does
with GORM
    * InheritableThreadLocal holding a map of PMF by name
(Map<String,PersistenceManagerFactory>)?
    * PMF Proxy?  JDOHelper.getPersistenceManagerFactoryProxy(???) ?
    * Craig says this is not very hard -- placeholder for this
discussion is "JDO.getApplicationPMF()"

* Leverage pmf.getPersistenceManagerProxy() in order to enable:

Static methods that can be introduced:

// Foo is a persistence-capable class, btw.
// Groovy syntax here, btw -- not sure if it's totally correct

/** static method to return an instance of the class gotten by id */
get { id ->
 
JDO.getApplicationPMF().getPersistenceManagerProxy().getObjectById(getCl
ass(), id)
}
/** static method to count the number of instances of the class */
count() {
    PersistenceManager pm =
JDO.getApplicationPMF().getPersistenceManagerProxy()
    Query q = pm.newQuery(getClass(), "count(this)")
    q.execute()
}
...

instance method introduction
getId() { JDOHelper.getObjectId(this) }
save() {
JDO.getApplicationPMF().getPersistenceManagerProxy().makePersistent(this
) }
delete() {
JDO.getApplicationPMF().getPersistenceManagerProxy().deletePersistent(th
is) }
detachCopy() {
JDO.getApplicationPMF().getPersistenceManagerProxy().detachCopy(this) }
...

We can support JPA & JDO pretty easily if we can get either an EMF or
PMF like Something.getPersistenceFactory() that returns Object:

count() {
    Object factory = Something.getPersistenceFactory(); // returns
either EMF or PMF
    if (factory instanceof PersistenceManagerFactory) {
        PersistenceManager pm = ((PersistenceManagerFactory)
factory).getPersistenceManagerProxy()
        Query q = pm.newQuery(getClass(), "count(this)")
        return q.execute()
    }
    else if (factory instanceof EntityManagerFactory) {
        EntityManager em = ((EntityManagerFactory)
factory).getEntityManager() // the "right" one?
        Query q = em.createQuery("SELECT count(x) from " +
this.getClass().getName() + " x")
        return q.getSingleResult()
    }
    else {
        throw new YouAreTooAdvancedForMeException(...);
    }
} 
 
Matthew T. Adams
Senior Consultant & Product Marketing Director
Xcalia, Inc.
matthew.adams@xcalia.com
+1 206 331 3833 Office
+1 253 732 1051 Mobile
+1 815 331 0952 Fax
http://www.xcalia.com <http://www.xcalia.com/> 
745 Emerson St.
Palo Alto, CA  94301
 
Xcalia provides dynamic integration software for agile enterprises to
easily create transactional composite applications. Our unique
intermediation approach enables unified, real-time access to
heterogenous data and services. Intermediation is adaptive and
configurable so application changes can be made quickly and cost
effectively without impacting the underlying systems or infrastructure.

Mime
View raw message