Last active
December 31, 2015 18:49
-
-
Save raphaelbauer/8029616 to your computer and use it in GitHub Desktop.
UnitOfWork Filter for Ninja - allows lightweight JPA usage ins resource-local mode. Annotate your classes / methods with @FilterWith(DatabaseAccess.class) to use JPA without explicit transactions.
This file contains 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
public class DatabaseAccess implements Filter { | |
@Inject | |
private UnitOfWork unitOfWork; | |
@Override | |
public Result filter(FilterChain filterChain, Context context) { | |
Result result; | |
try { | |
unitOfWork.begin(); | |
result = filterChain.next(context); | |
} finally { | |
unitOfWork.end(); | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment