开发者

Keep transaction between JDO and low-level API

开发者 https://www.devze.com 2023-02-19 05:03 出处:网络
I have a Spring application in GoogleApp engine which uses JDO to persists objects. So I\'m using it in this way in my service layer to keep transactions (with @Transactional annotation).

I have a Spring application in GoogleApp engine which uses JDO to persists objects. So I'm using it in this way in my service layer to keep transactions (with @Transactional annotation).

@Transactional
public void save(Object object) {
    dao1.save(object); // dao1 saves using JDO
    Object object2 = generate1Object(object)
    dao2.save(object2); // dao2 saves using low level API
    Object object3 = generate2Object(object)
    dao3.save(object3); // dao3 saves using JDO
}

The problem I have is that I need to use the low level API to persist the object2 (because it's an advanced save which cannot be done with JDO). The problem I have is that I don't know how to keep they all in the same transaction. If the dao3 fails when saving the sving done in the love level is not rolledback.

So in the dao2 I persist in this way:

//save using low-level API
public void save(Object object){
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Entity entity = generateEntity(object);
    datastore.put(entity);
}

and in the dao1 and dao3 (the ones which use JDO) I have something like this:

//save using JDO
public void save(Object object) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    pm.开发者_Python百科makePersistent(object);
}

I've seen that the datastore object has a method called:

datastore.getCurrentTransaction()

but it is null for me. How can I make the low level to be aware of the transaction of JDO and keep the three daos in the same transaction.

Thanks.


just use jdo as normal and get hold of the bigtable connection

tx.begin();
...

// Get hold of native connection
JDOConnection jdoConn = pm.getDataStoreConnection();
... cast "jdoConn.getNativeConnection()" to the right type
... (do something with the connection)
jdoConn.close(); // Hands it back to JDO

tx.commit();

at least that is the theory, assuming GAE/J implements it

0

精彩评论

暂无评论...
验证码 换一张
取 消