+ "\n\t-localSessionBean=" + localSessionBean
+ "\n\t-action=" + action
);
}
UserTransaction jtatx = null;
PMHolder pmh = new PMHolder(persistenceManagerFactory);
Transaction jdotx = null;
if (withTransaction) {
if (isJdoTx && (!useSessionBean || localSessionBean)) {
logger.log(BasicLevel.DEBUG, "fetch JDO PersistenceManager");
jdotx = pmh.getPersistenceManager().currentTransaction();
logger.log(BasicLevel.DEBUG, "Begin JDO Transaction (local)");
jdotx.begin();
} else {
try {
jtatx = (UserTransaction) getObjectFromContext(
null, "java:comp/UserTransaction");
} catch (Exception e) {
logger.log(BasicLevel.ERROR, "Cannot lookup java:comp/UserTransaction: ", e);
throw new ServletException(e);
}
logger.log(BasicLevel.DEBUG, "Begin JTA Transaction");
try {
jtatx.begin();
} catch (Exception e) {
logger.log(BasicLevel.ERROR, "Cannot begin JTA transaction", e);
throw new ServletException(e);
}
}
}
try {
if (useSessionBean) {
//The action will be done by the Session bean
if (localSessionBean) {
//Invoke the session bean through the local interface
logger.log(BasicLevel.DEBUG, "Use local session bean");
StoreServicesLocal lstoreServices = null;
try {
lstoreServices = lstoreServicesLH.create();
} catch (CreateException e) {
logger.log(BasicLevel.ERROR, "Error during the creation of Local Session", e);
throw new ServletException(e);
}
try {
ServletOutputStream out = resp.getOutputStream();
out.println(lstoreServices.doAction(pmh, action));
} finally {
//release the session bean from the pool
lstoreServices.remove();
}
} else {
//Invoke the session bean through the Remote interface
logger.log(BasicLevel.DEBUG, "Use remote session bean");
StoreServicesRemote lstoreServices = null;
try {
lstoreServices = lstoreServicesRH.create();
} catch (CreateException e) {
logger.log(BasicLevel.ERROR, "Error during the creation of Local Session", e);
throw new ServletException(e);
}
try {
ServletOutputStream out = resp.getOutputStream();
out.println(lstoreServices.doAction(action));
} finally {
//release the session bean from the pool
lstoreServices.remove();
}
}
} else {
logger.log(BasicLevel.DEBUG, "Use direct call");
ServletOutputStream out = resp.getOutputStream();
String outStr = DatabaseImpl.instance.doAction(action, false, pmh);
out.println(outStr);
}
if (jtatx != null) {
logger.log(BasicLevel.DEBUG, "Commit the JTA Transaction");
jtatx.commit();
} else if (jdotx != null && jdotx.isActive()) {
logger.log(BasicLevel.DEBUG, "Commit the local JDOTransactionItf");
jdotx.commit();
}
} catch (Exception e) {
if (jtatx != null) {
logger.log(BasicLevel.WARN, "Rolling back the JTA Transaction due to an error: ", e);
try {
jtatx.rollback();
} catch (Exception jtae) {
logger.log(BasicLevel.ERROR, "Cannot rollback JTA transaction", jtae);
}
} else if (jdotx != null && jdotx.isActive()) {
logger.log(BasicLevel.WARN, "Rolling back the JDO Transaction due to an error: ", e);
jdotx.rollback();
} else {
logger.log(BasicLevel.WARN, "An error has occured: ", e);
}
throw new ServletException(e);
} finally {
if (jdotx != null) {
pmh.closePersistenceManager();
}
}
}