Author: bdelacretaz
Date: Fri Nov 15 11:14:14 2013
New Revision: 1542231

URL: http://svn.apache.org/r1542231
Log:
SLING-3147 - refresh Session before loading JCR resource bundle, needed for Oak

Modified:
    
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java

Modified: 
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java?rev=1542231&r1=1542230&r2=1542231&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
 (original)
+++ 
sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
 Fri Nov 15 11:14:14 2013
@@ -28,6 +28,8 @@ import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.Set;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.query.Query;
 
 import org.apache.sling.api.SlingException;
@@ -57,8 +59,9 @@ public class JcrResourceBundle extends R
     JcrResourceBundle(Locale locale, String baseName,
             ResourceResolver resourceResolver) {
         this.locale = locale;
-
+        
         long start = System.currentTimeMillis();
+        refreshSession(resourceResolver, true);
         final String loadQuery = getFullLoadQuery(locale, baseName);
         this.resources = loadFully(resourceResolver, loadQuery);
         long end = System.currentTimeMillis();
@@ -68,6 +71,19 @@ public class JcrResourceBundle extends R
                 (end - start) });
     }
 
+    static void refreshSession(ResourceResolver resolver, boolean keepChanges) 
{
+        final Session s = resolver.adaptTo(Session.class);
+        if(s == null) {
+            log.warn("ResourceResolver {} does not adapt to Session, cannot 
refresh", resolver);
+        } else {
+            try {
+                s.refresh(keepChanges);
+            } catch(RepositoryException re) {
+                throw new RuntimeException("RepositoryException in 
session.refresh", re);
+            }
+        }
+    }
+
     @Override
     protected void setParent(ResourceBundle parent) {
         super.setParent(parent);


Reply via email to