Announcement Announcement Module
Collapse
No announcement yet.
JdoTemplate and detach/attach Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JdoTemplate and detach/attach

    Hi,

    i am using JdoTemplate for my DAO operations and i would like to ask if it would make sense to add detach/attach operations to it. Of course also to the underlying JdoOperations. This functionality will be defined in JDO2, so its no vendor extension anymore.

    Kodo provides these:

    Object detach(Object ob)
    Object[] detachAll(Object[] obs)
    Collection detachAll(Collection obs)

    Object attach(Object ob)
    Object[] attachAll(Object[] obs)
    Collection attachAll(Collection obs)

    Also i have one more beginner like question. Where does JdoTemplate know when to close the PersistenceManager?

    Marc

  • #2
    Thinking about that a second time, its most likely not the way to go, because as long as the JDO PersistenceManager Interface doesnt have these methods (that is, pre JDO 2.0 phase), there is no generic way to access the detach/attach functionality. Or we have to assume that all PersistenceManagerImpl of the JDO products support these methods allready.

    Right now, we are stuck with code like that in the moment, arent we?:

    Code:
           
    // Set "allowCreate" to false to ensure that we're using the PM associated
    // with this thread/request by the JDO interceptor.
    JdoTemplate template = new JdoTemplate(persistenceManagerFactory, false);
    Collection c = template.find(User.class);
    
    // Set allowCreate to false to ensure that we're using the PM provided
    // by the interceptor.
    KodoPersistenceManager pm = (KodoPersistenceManager)PersistenceManagerFactoryUtils.getPersistenceManager
                   (persistenceManagerFactory, false);
    Collection detachedCollection = pm.detachAll(c);
    
    return (detachedCollection);
    Or one could of course not use the JdoTemplate at all. This would make the code cleaner.

    Marc

    Comment


    • #3
      Also i have one more beginner like question. Where does JdoTemplate know when to close the PersistenceManager?
      It's integrated with Spring's transaction management. Specifically, JdoTransactionManager.doCleanupAfterCompletion(). If you use JCA configuration with your JDO tool, that will manage it.

      Since you're using Kodo, you might want to talk to SolarMetric about their recommendations for doing attach/detach with Spring.

      Comment


      • #4
        Basically i know how to detach/attach with Kodo, i just wanted to ask about the future of JdoTemplate about these two operations.

        I dont use JCA with Kodo but it works anyway. So ok, i will take a look at the transaction Manager to see things more clearly.

        marc

        Comment

        Working...
        X