Skip to content

Instantly share code, notes, and snippets.

@raphaelbauer
Last active December 31, 2015 18:49
Show Gist options
  • Save raphaelbauer/8029616 to your computer and use it in GitHub Desktop.
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.
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