1 16 17 package org.springframework.orm.toplink; 18 19 import oracle.toplink.exceptions.TopLinkException; 20 import oracle.toplink.sessions.Session; 21 import oracle.toplink.sessions.UnitOfWork; 22 23 36 public abstract class UnitOfWorkCallback implements TopLinkCallback { 37 38 43 public final Object doInTopLink(Session session) throws TopLinkException { 44 UnitOfWork unitOfWork = session.getActiveUnitOfWork(); 46 boolean newUnitOfWork = false; 47 if (unitOfWork == null) { 48 unitOfWork = session.acquireUnitOfWork(); 49 newUnitOfWork = true; 50 } 51 52 try { 55 Object result = doInUnitOfWork(unitOfWork); 56 if (newUnitOfWork) { 57 unitOfWork.commit(); 58 } 59 return result; 60 } 61 finally { 62 if (newUnitOfWork) { 63 unitOfWork.release(); 64 } 65 } 66 } 67 68 75 protected abstract Object doInUnitOfWork(UnitOfWork unitOfWork) throws TopLinkException; 76 77 } 78 | Popular Tags |