Search in sources :

Example 86 with ResourceResolver

use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.

the class ResourceResolverFactoryTest method testNestedThreadLocal.

@Test
public void testNestedThreadLocal() throws Exception {
    assertNull(this.commonFactory.getThreadResourceResolver());
    // create first resolver
    final ResourceResolver rr1 = this.commonFactory.getResourceResolver(null);
    assertNotNull(rr1);
    assertEquals(rr1, this.commonFactory.getThreadResourceResolver());
    // create second resolver
    final ResourceResolver rr2 = this.commonFactory.getResourceResolver(null);
    assertNotNull(rr2);
    assertEquals(rr2, this.commonFactory.getThreadResourceResolver());
    rr2.close();
    assertEquals(rr1, this.commonFactory.getThreadResourceResolver());
    rr1.close();
    assertNull(this.commonFactory.getThreadResourceResolver());
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 87 with ResourceResolver

use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.

the class ResourceResolverFactoryTest method testNestedUnorderedCloseThreadLocal.

@Test
public void testNestedUnorderedCloseThreadLocal() throws Exception {
    assertNull(this.commonFactory.getThreadResourceResolver());
    // create three resolver
    final ResourceResolver rr1 = this.commonFactory.getResourceResolver(null);
    final ResourceResolver rr2 = this.commonFactory.getResourceResolver(null);
    final ResourceResolver rr3 = this.commonFactory.getResourceResolver(null);
    assertEquals(rr3, this.commonFactory.getThreadResourceResolver());
    rr2.close();
    assertEquals(rr3, this.commonFactory.getThreadResourceResolver());
    rr3.close();
    assertEquals(rr1, this.commonFactory.getThreadResourceResolver());
    rr1.close();
    assertNull(this.commonFactory.getThreadResourceResolver());
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 88 with ResourceResolver

use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.

the class ResourceResolverFactoryTest method testSingleThreadLocal.

@Test
public void testSingleThreadLocal() throws Exception {
    assertNull(this.commonFactory.getThreadResourceResolver());
    // create first resolver
    final ResourceResolver rr1 = this.commonFactory.getResourceResolver(null);
    assertNotNull(rr1);
    assertEquals(rr1, this.commonFactory.getThreadResourceResolver());
    rr1.close();
    assertNull(this.commonFactory.getThreadResourceResolver());
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 89 with ResourceResolver

use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.

the class ResourceResolverFactoryTest method testThreadLocalWithAdmin.

@Test
public void testThreadLocalWithAdmin() throws Exception {
    assertNull(this.commonFactory.getThreadResourceResolver());
    final ResourceResolver rr1 = this.commonFactory.getResourceResolver(null);
    final ResourceResolver admin = this.commonFactory.getAdministrativeResourceResolver(null);
    assertEquals(rr1, this.commonFactory.getThreadResourceResolver());
    rr1.close();
    assertNull(this.commonFactory.getThreadResourceResolver());
    admin.close();
    assertNull(this.commonFactory.getThreadResourceResolver());
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 90 with ResourceResolver

use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.

the class ScriptingResourceResolverProviderImpl method getRequestScopedResourceResolver.

@Override
public ResourceResolver getRequestScopedResourceResolver() {
    ScriptingResourceResolver threadResolver = perThreadResourceResolver.get();
    if (threadResolver == null) {
        try {
            ResourceResolver delegate = rrf.getServiceResourceResolver(null);
            threadResolver = new ScriptingResourceResolver(logStackTraceOnResolverClose, delegate);
            perThreadResourceResolver.set(threadResolver);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Set per thread resource resolver for thread {}.", Thread.currentThread().getId());
            }
        } catch (LoginException e) {
            throw new IllegalStateException("Cannot create per thread resource resolver.", e);
        }
    }
    return threadResolver;
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) LoginException(org.apache.sling.api.resource.LoginException)

Aggregations

ResourceResolver (org.apache.sling.api.resource.ResourceResolver)339 Resource (org.apache.sling.api.resource.Resource)168 Test (org.junit.Test)131 HashMap (java.util.HashMap)65 LoginException (org.apache.sling.api.resource.LoginException)53 PersistenceException (org.apache.sling.api.resource.PersistenceException)52 Session (javax.jcr.Session)31 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)29 ValueMap (org.apache.sling.api.resource.ValueMap)27 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)26 ArrayList (java.util.ArrayList)23 DistributionRequest (org.apache.sling.distribution.DistributionRequest)23 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)21 Map (java.util.Map)19 Before (org.junit.Before)19 IOException (java.io.IOException)17 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)17 ChildResource (org.apache.sling.validation.model.ChildResource)17 HashSet (java.util.HashSet)16 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)15