[Registry-dev] svn commit r11730 - in trunk/registry/modules/core/src/main/java/org/wso2/registry: . jdbc/dao jdbc/mediatypes/builtin

svn at wso2.org svn at wso2.org
Tue Jan 1 23:14:08 PST 2008


Author: chathura
Date: Tue Jan  1 23:14:02 2008
New Revision: 11730

Log:


Changed versioning impl to version only the resource content changes.



Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java	Tue Jan  1 23:14:02 2008
@@ -36,6 +36,13 @@
     private String parentPath;
 
     /**
+     * Used to detect whether the resource content is modified after it is retrieved from the
+     * Registry. If this is set to true at the time of adding the resource back to the Registry,
+     * new version will be created.
+     */
+    private boolean contentModified;
+
+    /**
      * Normal resources have the state RegistryConstants.ACTIVE_STATE (100) Deleted resources have
      * the state RegistryConstants.DELETED_STATE (101)
      */
@@ -149,6 +156,7 @@
 
     public void setContent(Object content) {
         this.content = content;
+        this.contentModified = true;
     }
 
     private String preparePath(String path) {
@@ -197,4 +205,18 @@
     public void setDependsOn(String[] dependsOn) {
         this.dependsOn = dependsOn;
     }
+
+    public boolean isContentModified() {
+        return contentModified;
+    }
+
+    /**
+     * This method is used to explicitly set the content modified state of the resource. Normal
+     * users of the Registry API should not call this method.
+     *
+     * @param contentModified
+     */
+    public void setContentModified(boolean contentModified) {
+        this.contentModified = contentModified;
+    }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java	Tue Jan  1 23:14:02 2008
@@ -255,6 +255,7 @@
                     versionResults.getTimestamp(DatabaseConstants.VERSION_UPDATED_TIME));
             resource.setContent(versionResults.getBytes(DatabaseConstants.VERSION_CONTENT_FIELD));
         }
+
         // get resource children
         if (resource.isDirectory()) {
             String[] children = getLatestChildPaths(resource.getId(),

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java	Tue Jan  1 23:14:02 2008
@@ -88,6 +88,11 @@
             }
         }
 
+        // we are just getting the content from the database. not a content modification.
+        if (resource != null) {
+            resource.setContentModified(false);
+        }
+
         return resource;
     }
 
@@ -119,7 +124,10 @@
                 resource.setState(RegistryConstants.ACTIVE_STATE);
                 resource.setLastUpdaterUserName(userID);
                 resourceDAO.update(path, resource, conn);
-                resourceDAO.addResourceVersion(resource, conn);
+
+                if (resource.isContentModified()) {
+                    resourceDAO.addResourceVersion(resource, conn);
+                }
 
             } else {
 



More information about the Registry-dev mailing list