On May 26, 2006, at 4:45 PM, Craig L Russell wrote:
By the way, feel free to engage the roller alias on this thread.

A-OK. Here goes.


On May 26, 2006, at 12:00 PM, Dave Johnson wrote:
On May 26, 2006, at 2:41 PM, Craig L Russell wrote:
Hi Dave, Thanks for the doc.
I plan to add implementations that can be shared between JDO and EJB3 to implement the Roller interfaces. When I look at the Hibernate implementations, there is about 80% overlap with what JDO needs.
Can you briefly explain what parts are overlapping?

For example,

public HibernateAutoPingManagerImpl (HibernatePersistenceStrategy strat) {
        this.strategy = strat;
    }
public AutoPingData getAutoPing(String id) throws RollerException {
        return (AutoPingData) strategy.load(id, AutoPingData.class);
    }
public void saveAutoPing(AutoPingData autoPing) throws RollerException {
        strategy.store(autoPing);
    }
public void removeAutoPing(AutoPingData autoPing) throws RollerException { //TODO: first remove all related category restrictions (category restrictions are not yet implemented)
        strategy.remove(autoPing);
    }
public void removeAutoPings(Collection autopings) throws RollerException {

        // just go through the list and remove each auto ping
        Iterator pings = autopings.iterator();
        while (pings.hasNext()) {
            this.strategy.remove((AutoPingData) pings.next());
        }
    }
    public void removeAllAutoPings() throws RollerException {
        try {
Session session = ((HibernatePersistenceStrategy) strategy).getSession(); Criteria criteria = session.createCriteria (AutoPingData.class);
            List allAutoPings = criteria.list();
            this.removeAutoPings(allAutoPings);
        } catch (HibernateException e) {
            throw new RollerException(e);
        }
    }
public void queueApplicableAutoPings(WeblogEntryData changedWeblogEntry) throws RollerException {
        if (PingConfig.getSuspendPingProcessing()) {
if (log.isDebugEnabled()) log.debug("Ping processing is suspended. No auto pings will be queued.");
            return;
        }
        // TODO: new manager method for addQueueEntries(list)?
PingQueueManager pingQueueMgr = RollerFactory.getRoller ().getPingQueueManager(); List applicableAutopings = getApplicableAutoPings (changedWeblogEntry); for (Iterator i = applicableAutopings.iterator(); i.hasNext (); ) {
            AutoPingData autoPing = (AutoPingData) i.next();
            pingQueueMgr.addQueueEntry(autoPing);
        }
    }
public List getAutoPingsByWebsite(WebsiteData website) throws RollerException {
        try {
Session session = ((HibernatePersistenceStrategy) strategy).getSession(); Criteria criteria = session.createCriteria (AutoPingData.class); // Currently category restrictions are not yet implemented, so we return all auto ping configs for the
            // website.
            criteria.add(Expression.eq("website", website));
            return criteria.list();
        } catch (HibernateException e) {
            throw new RollerException(e);
        }
    }
public List getAutoPingsByTarget(PingTargetData pingTarget) throws RollerException {
        try {
Session session = ((HibernatePersistenceStrategy) strategy).getSession(); Criteria criteria = session.createCriteria (AutoPingData.class); // Currently category restrictions are not yet implemented, so we return all auto ping configs for the
            // website.
            criteria.add(Expression.eq("pingTarget", pingTarget));
            return criteria.list();
        } catch (HibernateException e) {
            throw new RollerException(e);
        }
    }
public List getCategoryRestrictions(AutoPingData autoPing) throws RollerException {
        return Collections.EMPTY_LIST;
    }
public void setCategoryRestrictions(AutoPingData autoPing, Collection newCategories) {
        // NOT YET IMPLEMENTED
        return;
    }
    public void release() {}

The only parts of the Hibernate implementation that are Hibernate- specific have to do with the criteria queries, which will require a criteria API in the JDO/Hibernate/EJB3 implementation.

You know, I wrote a complete criteria query API back in the 0.9.9 code base and an implementation for Castor-JDO (which generated OQL) and Hibernate (which generated HSQL). We had it in production at JRoller.com for a while, but we dropped it when we completely dropped Castor-JDO support (code is here -> http://tinyurl.com/k7lgm).

Cool idea, but I must admit that I'm a little concerned about maintaining a criteria API infrastructure in Roller. Seems like a criteria API should be part of JDO and/or JPA instead.

Are you proposing to implement the Hibernate Criteria API verbatim or something new?


So it looks like the best solution is to add a package datamapper and add concrete classes, e.g. DatamapperAutoPingManagerImpl that delegates to a DatamapperPersistenceManager that handles the abstraction to the specific persistence layer.
Could you expand on that a little. What does the DatamapperPersistenceManager do? Does it handle persistence and queries for all Roller POJOs?

The DatamapperPersistenceManager would have methods similar to the HibernatePersistenceStrategy: flush(), release(), load(), store(), remove(). It would also have criteria query support that allows queries based on fields and values, e.g. Criteria criteria = session.createCriteria (AutoPingData.class); // Currently category restrictions are not yet implemented, so we
            // return all auto ping configs for the website.
            criteria.add(Expression.eq("pingTarget", pingTarget));
            criteria.add(Expression.eq("website", website));
            List matches = criteria.list();

We would abstract this to allow passing the criteria Expression.eq ("pingTarget", pingTarget) as a parameter to the DatamapperPersistenceManager. Or we subclass the DatamapperAutoPingManagerImpl. We will have to look at the details.

This way, the only code specific to EJB3 or JDO would be the implementation of DatamapperPersistenceManager and Roller interfaces.

So, the JDO specific parts of the implementation would be confined to two classes? That sounds too good to be true.

Of course it's too good to be true. But that's the objective.

OK, I understand now. It might be good to come up with a brief proposal on the wiki that outlines the design. I'd be glad to help with that.

And, instead of working in the sandbox, how about we make a new branch for this work. That might be easier for us all.

- Dave

Reply via email to