1 2 3 4 Previous Next 52 Replies Latest reply on Nov 17, 2007 3:10 PM by pmuir Go to original post
      • 45. Re: ResourceBundle in Database
        nickarls

        Ngh. Of course. Thanks.

        Did you BTW come to any consensus regarding the caching? For some reason I seem to get different instances of the resource loader (my cache-map is always empty even if the scope is application). Would I have to inject the data from somewhere else?

        • 46. Re: ResourceBundle in Database
          pmuir

          I would use the hibernate query cache - this is exactly the kind of scenario its designed for - and set the query cacheable e.g. for 15 minutes.

          • 47. Re: ResourceBundle in Database
            susnet

            It would be nice if someone would like to post a complete example for this including caching.

            • 48. Re: ResourceBundle in Database
              pmuir

              I blogged about this - see further up the topic. You should cache using the Hibernate 2nd level cache.

              • 49. Re: ResourceBundle in Database
                nickarls

                Yep. Query hints for enabling a 10 minute cache worked out fine.

                • 50. Re: ResourceBundle in Database
                  pbrewer_uk

                  I'm a bit puzzled as to why my custom resource loader isn't being called for anything other than page resource bundles. I'm using Seam 2.0.0.GA with Java 6:

                  components.xml

                   ...
                   <component name="org.jboss.seam.core.resourceLoader">
                   <property name="bundleNames">
                   <value>messages</value>
                   <value>labels</value>
                   <value>buttons</value>
                   <value>content</value>
                   <value>validation</value>
                   </property>
                   </component>
                   ...
                  


                  DBResourceLoader.java
                  @Scope(ScopeType.STATELESS)
                  @BypassInterceptors
                  @Install(true)
                  @Name("org.jboss.seam.core.resourceLoader")
                  public class DBResourceLoader extends org.jboss.seam.core.ResourceLoader {
                  
                   private Log log = Logging.getLog(DBResourceLoader.class) ;
                  
                   /** The serialVersionUID field */
                   private static final long serialVersionUID = -7063164147487452966L;
                  
                   // Redefine how we load a resource bundle
                   @Override
                   public ResourceBundle loadBundle(String bundleName) {
                   log.debug("Searching database resource loader for bundle #0", bundleName) ;
                   return ResourceBundle.getBundle(bundleName, Locale.instance(), Thread.currentThread().getContextClassLoader(), DBControl.INSTANCE);
                   }
                  
                  }
                  


                  And in the logs I can see from my debug message that it searches the bundle for the current page, but I can never see it trying to load the bundle names specified in components.xml.

                  If anyone can help or suggest any ides that would be greatly appreciated,
                  Thanks in advance, Pete



                  BTW: I found an oddity debugging the code. By putting a breakpoint at line 97 and 98, I hit the breakpoint at 97, step over that line and then never hit line 98. And I can't see any exceptions happening. Any ideas why?

                  org.jboss.seam.core.SeamResourceBundle.java
                  95 protected Object handleGetObject(String key)
                  96 {
                  97 List<java.util.ResourceBundle> pageBundles = getPageResourceBundles();
                  98 for (java.util.ResourceBundle pageBundle : pageBundles)
                  99 {
                  100 try
                  101 {
                  102 return interpolate(pageBundle.getObject(key));
                  103 }
                  104 catch (MissingResourceException mre) {}
                  105 }
                  106
                  107 for (java.util.ResourceBundle littleBundle : getBundlesForCurrentLocale())
                  108 {
                  109 try
                  110 {
                  111 return interpolate( littleBundle.getObject(key) );
                  112 }
                  113 catch (MissingResourceException mre) {}
                  114 }
                  115
                  116 return null; // superclass is responsible for throwing MRE
                  117 }
                  


                  • 51. Re: ResourceBundle in Database
                    pbrewer_uk

                    Ok I've solved that problem. Now I have a problem with seam caching resource bundles.

                    I'm using Java 6 to do my resource bundle caching, so I want to remove, disable or override the following method in org.jboss.seam.core.SeamResourceBundle.java:

                     private List<java.util.ResourceBundle> getBundlesForCurrentLocale()
                     {
                     Locale instance = org.jboss.seam.core.Locale.instance();
                     List<ResourceBundle> bundles = bundleCache.get(instance);
                     if ( bundles==null )
                     {
                     bundles = loadBundlesForCurrentLocale();
                     bundleCache.put(instance, bundles);
                     }
                     return bundles;
                    
                     }
                    


                    Is it possible to override this method somehow? If so any pointers would be much appreciated.

                    Cheers, Pete.

                    BTW This is the solution to my previous problem: The trick is to not allow a MissingResourceException to be thrown.
                    @Scope(ScopeType.STATELESS)
                    @BypassInterceptors
                    @Install(true)
                    @Name("org.jboss.seam.core.resourceLoader")
                    public class DBResourceLoader extends ResourceLoader {
                    
                     private Log log = Logging.getLog(DBResourceLoader.class) ;
                    
                     /** The serialVersionUID field */
                     private static final long serialVersionUID = -7063164147487452966L;
                    
                     // Redefine how we load a resource bundle
                     @Override
                     public ResourceBundle loadBundle(String bundleName) {
                     try {
                     log.debug("Searching database resource loader for bundle #0", bundleName) ;
                     return ResourceBundle.getBundle(bundleName, Locale.instance(), Thread.currentThread().getContextClassLoader(), DBControl.INSTANCE);
                     } catch (MissingResourceException ex) {
                     log.debug("Missing resource for bundleName #0", bundleName) ;
                     return null;
                     }
                    
                     }
                    
                    }
                    


                    • 52. Re: ResourceBundle in Database
                      pmuir

                      Pete, I would really suggest using the Hibernate 2nd level cache for caching, it is a simple solution.

                      1 2 3 4 Previous Next