Created
May 24, 2013 20:55
-
-
Save bchetty/5646460 to your computer and use it in GitHub Desktop.
Seam v2 Database Resource Loader.
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
| @Scope(ScopeType.STATELESS) | |
| @BypassInterceptors | |
| @Install(precedence = Install.APPLICATION, dependencies = "org.jboss.seam.security.identity") | |
| @Name("org.jboss.seam.core.resourceLoader") | |
| public class DatabaseResourceLoader extends ResourceLoader { | |
| @Override | |
| public ResourceBundle loadBundle(String bundleName) { | |
| return new ResourceBundle() { | |
| public Enumeration<String> getKeys() { | |
| //Locale locale = org.jboss.seam.core.Locale.instance(); | |
| Users user = (Users) Component.getInstance("user"); | |
| EntityManager entityManager = (EntityManager) | |
| Component.getInstance("entityMgr"); | |
| List resources = entityManager.createNativeQuery("select key from messages where locale = '" + | |
| user.getLanguage() + "-" + user.getCountry() + "'").getResultList(); | |
| return Collections.enumeration(resources); | |
| } | |
| protected Object handleGetObject(String key) { | |
| //Locale locale = org.jboss.seam.core.Locale.instance(); | |
| EntityManager entityManager = (EntityManager) | |
| Component.getInstance("entityMgr"); | |
| Users user = (Users) Component.getInstance("user"); | |
| try { | |
| return entityManager.createNativeQuery("select value from messages where locale = '" + | |
| user.getUserLanguage() + "' and key = '" + key + "'").getSingleResult(); | |
| } catch (NoResultException NRE1) { | |
| return null; | |
| } | |
| } | |
| }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment