protected PersistenceBroker wrapRequestedBrokerInstance(PersistenceBroker broker)
{
// all PB instance should be of this type
if (!(broker instanceof PersistenceBrokerSyncImpl))
{
throw new PBFactoryException("Expect instance of " + PersistenceBrokerSyncImpl.class
+ ", found " + broker.getClass());
}
/*
Before we return the PB handle, we jump into the running JTA tx
*/
PersistenceBrokerSyncImpl pb = (PersistenceBrokerSyncImpl) broker;
try
{
// search for an active tx
Transaction tx = searchForValidTx();
if (tx != null)
{
txRegistry.register(tx, pb);
try
{
pb.internBegin();
}
catch (Exception e)
{
/*
if something going wrong with pb-tx, we rollback the
whole JTA tx
*/
log.error("Unexpected exception when start intern pb-tx", e);
try
{
tx.setRollbackOnly();
}
catch (Throwable ignore)
{
}
throw new PBFactoryException("Unexpected exception when start intern pb-tx", e);
}
}
}
catch (Exception e)
{
throw new PBFactoryException("Error while try to participate in JTA transaction", e);
}
return super.wrapRequestedBrokerInstance(broker);
}