Java Code Examples for javax.transaction.Transactional#TxType
The following examples show how to use
javax.transaction.Transactional#TxType .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DomaTransactionMiddleware.java From enkan with Eclipse Public License 1.0 | 6 votes |
@Override public RES handle(REQ req, MiddlewareChain<REQ, RES, ?, ?> chain) { if (req instanceof Routable) { Routable routable = (Routable) req; Method m = routable.getControllerMethod(); Transactional.TxType type= getTransactionType(m); if (type != null) { switch(type) { case REQUIRED: return tm.required(() -> chain.next(req)); case REQUIRES_NEW: return tm.requiresNew(() -> chain.next(req)); default: throw new MisconfigurationException("doma2.UNSUPPORTED_TX_TYPE", type); } } } return chain.next(req); }
Example 2
Source File: NonJtaTransactionMiddleware.java From enkan with Eclipse Public License 1.0 | 5 votes |
@Override public RES handle(REQ req, MiddlewareChain<REQ, RES, ?, ?> chain) { EntityManager em = Optional.ofNullable(req) .filter(EntityManageable.class::isInstance) .map(EntityManageable.class::cast) .map(EntityManageable::getEntityManager) .orElseThrow(() -> new MisconfigurationException("jpa.NOT_ENTITY_MANAGEABLE_REQUEST")); if (req instanceof Routable) { Routable routable = (Routable) req; Transactional.TxType type = getTransactionType(routable.getControllerClass()); Method m = routable.getControllerMethod(); if (m != null) { type = Optional.ofNullable(getTransactionType(m)).orElse(type); } if (type != null) { em.getTransaction().begin(); try { RES ret = chain.next(req); if (em.getTransaction().getRollbackOnly()) { em.getTransaction().rollback(); } else { em.getTransaction().commit(); } return ret; } catch (Throwable t) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } throw t; } } } return chain.next(req); }
Example 3
Source File: DomaTransactionMiddleware.java From enkan with Eclipse Public License 1.0 | 4 votes |
private Transactional.TxType getTransactionType(Method m) { Transactional transactional = m.getDeclaredAnnotation(Transactional.class); return transactional != null ? transactional.value() : null; }
Example 4
Source File: NonJtaTransactionMiddleware.java From enkan with Eclipse Public License 1.0 | 4 votes |
private Transactional.TxType getTransactionType(Class<?> cls) { Transactional transactional = cls.getDeclaredAnnotation(Transactional.class); return transactional != null ? transactional.value() : null; }
Example 5
Source File: NonJtaTransactionMiddleware.java From enkan with Eclipse Public License 1.0 | 4 votes |
private Transactional.TxType getTransactionType(Method m) { Transactional transactional = m.getDeclaredAnnotation(Transactional.class); return transactional != null ? transactional.value() : null; }