You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:59:41 UTC
[sling-org-apache-sling-resourceresolver] 11/47: SLING-2530 :
Implement CRUD based on resources (WiP)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.resourceresolver-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git
commit c9375a7ce301caa320a55ff4a8b7f2bf6ad089f5
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Jul 13 09:17:01 2012 +0000
SLING-2530 : Implement CRUD based on resources (WiP)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/resourceresolver@1361122 13f79535-47bb-0310-9956-ffa450edef68
---
.../impl/ResourceResolverImpl.java | 29 +++++++++++++++++-----
.../impl/helper/ResourceResolverContext.java | 17 +++++++++++--
.../impl/tree/ResourceProviderEntryTest.java | 8 ++++--
3 files changed, 44 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
index 0b8c431..7aa20c3 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
@@ -39,6 +39,7 @@ import org.apache.sling.api.adapter.SlingAdaptable;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ModifyingResourceProvider;
import org.apache.sling.api.resource.NonExistingResource;
+import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceNotFoundException;
import org.apache.sling.api.resource.ResourceResolver;
@@ -999,18 +1000,25 @@ public class ResourceResolverImpl extends SlingAdaptable implements ResourceReso
/**
* @see org.apache.sling.api.resource.ResourceResolver#delete(org.apache.sling.api.resource.Resource)
*/
- public boolean delete(final Resource resource) {
+ public void delete(final Resource resource)
+ throws PersistenceException {
+ // if resource is null, we get an NPE as stated in the API
final String path = resource.getPath();
final ModifyingResourceProvider mrp = this.factory.getRootProviderEntry().getModifyingProvider(this.context,
this,
path);
- return mrp.delete(this, path);
+ mrp.delete(this, path);
}
/**
* @see org.apache.sling.api.resource.ResourceResolver#addChild(org.apache.sling.api.resource.Resource, java.lang.String, org.apache.sling.api.resource.ValueMap)
*/
- public Resource addChild(final Resource parent, final String name, final ValueMap properties) {
+ public Resource addChild(final Resource parent, final String name, final ValueMap properties)
+ throws PersistenceException {
+ // if parent or name is null, we get an NPE as stated in the API
+ if ( name == null ) {
+ throw new NullPointerException("name");
+ }
final String path = parent.getPath() + '/' + name;
final ModifyingResourceProvider mrp = this.factory.getRootProviderEntry().getModifyingProvider(this.context,
this,
@@ -1021,7 +1029,9 @@ public class ResourceResolverImpl extends SlingAdaptable implements ResourceReso
/**
* @see org.apache.sling.api.resource.ResourceResolver#update(org.apache.sling.api.resource.Resource, org.apache.sling.api.resource.ValueMap)
*/
- public void update(final Resource resource, final ValueMap properties) {
+ public void update(final Resource resource, final ValueMap properties)
+ throws PersistenceException {
+ // if resource is null, we get an NPE as stated in the API
final String path = resource.getPath();
final ModifyingResourceProvider mrp = this.factory.getRootProviderEntry().getModifyingProvider(this.context,
this,
@@ -1032,14 +1042,21 @@ public class ResourceResolverImpl extends SlingAdaptable implements ResourceReso
/**
* @see org.apache.sling.api.resource.ResourceResolver#revert()
*/
- public void revert() {
+ public void revert() throws PersistenceException {
this.context.revert();
}
/**
* @see org.apache.sling.api.resource.ResourceResolver#commit()
*/
- public void commit() {
+ public void commit() throws PersistenceException {
this.context.commit();
}
+
+ /**
+ * @see org.apache.sling.api.resource.ResourceResolver#hasChanges()
+ */
+ public boolean hasChanges() {
+ return this.context.hasChanges();
+ }
}
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java b/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
index 219b9c4..a0e9445 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
@@ -24,6 +24,7 @@ import java.util.Set;
import org.apache.sling.api.resource.DynamicResourceProvider;
import org.apache.sling.api.resource.ModifyingResourceProvider;
+import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.ResourceProvider;
/**
@@ -124,7 +125,7 @@ public class ResourceResolverContext {
/**
* Revert all transient changes.
*/
- public void revert() {
+ public void revert() throws PersistenceException {
for(final ModifyingResourceProvider provider : this.modifyingProviders) {
provider.revert();
}
@@ -133,9 +134,21 @@ public class ResourceResolverContext {
/**
* Commit all transient changes
*/
- public void commit() {
+ public void commit() throws PersistenceException {
for(final ModifyingResourceProvider provider : this.modifyingProviders) {
provider.commit();
}
}
+
+ /**
+ * Do we have changes?
+ */
+ public boolean hasChanges() {
+ for(final ModifyingResourceProvider provider : this.modifyingProviders) {
+ if ( provider.hasChanges() ) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
index a47ed4e..ac36495 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
@@ -300,9 +300,8 @@ public class ResourceProviderEntryTest {
return Collections.<String> emptyList().iterator();
}
- public boolean delete(Resource resource) {
+ public void delete(Resource resource) {
// TODO Auto-generated method stub
- return false;
}
public Resource addChild(Resource parent, String name, ValueMap properties) {
@@ -323,6 +322,11 @@ public class ResourceProviderEntryTest {
// TODO Auto-generated method stub
}
+
+ public boolean hasChanges() {
+ // TODO Auto-generated method stub
+ return false;
+ }
}
private static class TestResource extends AbstractResource {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.