Search in sources :

Example 96 with PersistenceException

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

the class MongoDBNoSqlResourceProviderTransactionalIT method testRoot.

@Override
protected Resource testRoot() {
    if (this.testRoot == null) {
        try {
            Resource root = context.resourceResolver().getResource("/");
            Resource providerRoot = root.getChild("test");
            if (providerRoot == null) {
                providerRoot = context.resourceResolver().create(root, "test", ImmutableMap.<String, Object>of(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED));
            }
            this.testRoot = context.resourceResolver().create(providerRoot, UUID.randomUUID().toString(), ImmutableMap.<String, Object>of(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED));
        } catch (PersistenceException ex) {
            throw new RuntimeException(ex);
        }
    }
    return this.testRoot;
}
Also used : Resource(org.apache.sling.api.resource.Resource) PersistenceException(org.apache.sling.api.resource.PersistenceException)

Example 97 with PersistenceException

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

the class SimpleNoSqlResourceProviderTransactionalTest method testRoot.

@Override
protected Resource testRoot() {
    if (this.testRoot == null) {
        try {
            Map<String, Object> props = new HashMap<String, Object>();
            props.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
            final Resource root = context.resourceResolver().getResource("/");
            Resource noSqlRoot = context.resourceResolver().create(root, "nosql-simple", props);
            this.testRoot = context.resourceResolver().create(noSqlRoot, "test", props);
            context.resourceResolver().commit();
        } catch (PersistenceException ex) {
            throw new RuntimeException(ex);
        }
    }
    return this.testRoot;
}
Also used : HashMap(java.util.HashMap) Resource(org.apache.sling.api.resource.Resource) PersistenceException(org.apache.sling.api.resource.PersistenceException)

Example 98 with PersistenceException

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

the class SimpleNoSqlResourceProviderTest method testRoot.

@Override
protected Resource testRoot() {
    if (this.testRoot == null) {
        try {
            Map<String, Object> props = new HashMap<String, Object>();
            props.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
            final Resource root = context.resourceResolver().getResource("/");
            Resource noSqlRoot = context.resourceResolver().create(root, "nosql-simple", props);
            this.testRoot = context.resourceResolver().create(noSqlRoot, "test", props);
        } catch (PersistenceException ex) {
            throw new RuntimeException(ex);
        }
    }
    return this.testRoot;
}
Also used : HashMap(java.util.HashMap) Resource(org.apache.sling.api.resource.Resource) PersistenceException(org.apache.sling.api.resource.PersistenceException)

Example 99 with PersistenceException

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

the class CustomConfigurationPersistenceStrategy method deleteConfiguration.

@Override
public boolean deleteConfiguration(ResourceResolver resourceResolver, String configResourcePath) {
    Resource resource = resourceResolver.getResource(configResourcePath);
    if (resource != null) {
        try {
            resourceResolver.delete(resource);
        } catch (PersistenceException ex) {
            throw new ConfigurationPersistenceException("Unable to delete configuration at " + configResourcePath, ex);
        }
    }
    commit(resourceResolver);
    return true;
}
Also used : Resource(org.apache.sling.api.resource.Resource) ConfigurationPersistenceException(org.apache.sling.caconfig.spi.ConfigurationPersistenceException) PersistenceException(org.apache.sling.api.resource.PersistenceException) ConfigurationPersistenceException(org.apache.sling.caconfig.spi.ConfigurationPersistenceException)

Example 100 with PersistenceException

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

the class CustomConfigurationPersistenceStrategy2 method getOrCreateResource.

private Resource getOrCreateResource(ResourceResolver resourceResolver, String path, Map<String, Object> properties) {
    try {
        Resource resource = ResourceUtil.getOrCreateResource(resourceResolver, path, DEFAULT_RESOURCE_TYPE, DEFAULT_RESOURCE_TYPE, false);
        replaceProperties(resource, properties);
        return resource;
    } catch (PersistenceException ex) {
        throw new ConfigurationPersistenceException("Unable to persist configuration to " + path, ex);
    }
}
Also used : Resource(org.apache.sling.api.resource.Resource) ConfigurationPersistenceException(org.apache.sling.caconfig.spi.ConfigurationPersistenceException) PersistenceException(org.apache.sling.api.resource.PersistenceException) ConfigurationPersistenceException(org.apache.sling.caconfig.spi.ConfigurationPersistenceException)

Aggregations

PersistenceException (org.apache.sling.api.resource.PersistenceException)143 Resource (org.apache.sling.api.resource.Resource)102 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)62 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)37 HashMap (java.util.HashMap)34 LoginException (org.apache.sling.api.resource.LoginException)32 RepositoryException (javax.jcr.RepositoryException)24 ValueMap (org.apache.sling.api.resource.ValueMap)23 Node (javax.jcr.Node)17 Calendar (java.util.Calendar)14 Map (java.util.Map)14 IOException (java.io.IOException)13 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 ConfigurationPersistenceException (org.apache.sling.caconfig.spi.ConfigurationPersistenceException)6 InstanceDescription (org.apache.sling.discovery.InstanceDescription)6 QueueInfo (org.apache.sling.event.impl.jobs.config.QueueConfigurationManager.QueueInfo)6 Test (org.junit.Test)5 JobTopicTraverser (org.apache.sling.event.impl.jobs.JobTopicTraverser)4