Skip to content

Instantly share code, notes, and snippets.

@bchetty
Created May 24, 2013 20:55
Show Gist options
  • Select an option

  • Save bchetty/5646460 to your computer and use it in GitHub Desktop.

Select an option

Save bchetty/5646460 to your computer and use it in GitHub Desktop.
Seam v2 Database Resource Loader.
@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(&quot;user&quot;);
EntityManager entityManager = (EntityManager)
Component.getInstance(&quot;entityMgr&quot;);
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(&quot;entityMgr&quot;);
Users user = (Users) Component.getInstance(&quot;user&quot;);
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