Skip to content

Instantly share code, notes, and snippets.

@struberg
Created October 15, 2014 10:06
Show Gist options
  • Save struberg/569a0c7890cee81e6c42 to your computer and use it in GitHub Desktop.
Save struberg/569a0c7890cee81e6c42 to your computer and use it in GitHub Desktop.
self interception in CDI
@ApplicationScoped
public class CountryService {
private @Inject Cache<String, Country> cache;
private @Inject CountryService self;
public Country getByIsoA3(String isoA3) {
Country ctry = cache.get(isoA3);
if (ctry == null) {
ctry = self.fillCacheFromDb(isoA3);
}
return ctry;
}
@Transactional
Country fillCacheFromDb(String isoA3) {
transactionally load from db...
and fill cache
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment