Created
November 21, 2013 13:36
-
-
Save rzymek/7581675 to your computer and use it in GitHub Desktop.
New transaction without using UserTransaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ejb.tx; | |
import java.util.List; | |
import javax.ejb.Local; | |
@Local | |
public interface Manager { | |
void processAll(List<Object> list); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ejb.tx; | |
import java.util.List; | |
import javax.annotation.Resource; | |
import javax.ejb.Local; | |
import javax.ejb.SessionContext; | |
import javax.ejb.Stateless; | |
import javax.ejb.TransactionAttribute; | |
import javax.ejb.TransactionAttributeType; | |
@Stateless | |
public class ManagerBean implements Manager, ManagerInternal { | |
@Resource | |
private SessionContext context; | |
@Override | |
public void processAll(List<Object> list) { | |
ManagerInternal txThis = context.getBusinessObject(ManagerInternal.class); | |
for (Object obj : list) { | |
txThis.processOne(obj); | |
} | |
} | |
@Override | |
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) | |
public void processOne(Object obj) { | |
/* ... */ | |
} | |
} | |
@Local | |
interface ManagerInternal { | |
void processOne(Object obj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment