[Registry-dev] svn commit r16476 - in
trunk/registry/modules/core/src: main/java/org/wso2/registry
main/java/org/wso2/registry/app main/java/org/wso2/registry/jdbc
main/java/org/wso2/registry/jdbc/dao
main/java/org/wso2/registry/jdbc/utils/creators
main/java/org/wso2/registry/session main/resources/database-scripts
test/java/org/wso2/registry/jdbc
svn at wso2.org
svn at wso2.org
Fri May 2 02:41:44 PDT 2008
Author: chathura
Date: Fri May 2 02:40:41 2008
New Revision: 16476
Log:
Another phase of versioning implementation.
Completed the version creation and version browsing.
Resources track whether they are modified after fetched from the registry. If modified, new version is created automatically on put.
New version (check point) for any resource or collection can be created explicitly by calling the new Registry API method
registry.createVersion(resource_path);
Improved the test cases to validate new versioning features.
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionVersionImpl.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceVersionImpl.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceVersionDAO.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/SnapshotDAO.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/NonTransactionalJDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/TransactionalJDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/VersionRepository.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceDAO.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/creators/DerbyDatabaseCreator.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/creators/HSQLDatabaseCreator.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/session/UserRegistry.java
trunk/registry/modules/core/src/main/resources/database-scripts/derby-complete.sql
trunk/registry/modules/core/src/main/resources/database-scripts/derby-registry.sql
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/MoveTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/VersionHandlingTest.java
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionVersionImpl.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionVersionImpl.java Fri May 2 02:40:41 2008
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry;
+
+public class CollectionVersionImpl extends CollectionImpl {
+
+}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java Fri May 2 02:40:41 2008
@@ -62,6 +62,8 @@
String copy(String sourcePath, String targetPath) throws RegistryException;
+ void createVersion(String path) throws RegistryException;
+
/**
* Get a list of all versions of the resource located at the given path. Version paths are
* returned in the form /projects/myresource?v=12
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java Fri May 2 02:40:41 2008
@@ -22,6 +22,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.registry.jdbc.dao.ResourceDAO;
+import org.wso2.registry.jdbc.utils.Transaction;
import org.wso2.registry.utils.UUIDGenerator;
import javax.sql.DataSource;
@@ -48,38 +49,38 @@
/**
* UUID to identify the resource.
*/
- private String id;
+ protected String id;
/**
* Version of this instance of the resource. Versioned attributes (e.g. content,
* last modified date) can be accessed by using the combination of id and versionNumber.
*/
- private long versionNumber;
+ protected long versionNumber;
/**
* Username of the user who added the resource to the registry.
*/
- private String authorUserName;
+ protected String authorUserName;
/**
* Time at which the resource is first added to the registry.
*/
- private Timestamp createdTime;
+ protected Timestamp createdTime;
/**
* Username of the user who modified the resource most recently.
*/
- private String lastUpdaterUserName;
+ protected String lastUpdaterUserName;
/**
* Time at which the resource modified most recently.
*/
- private Timestamp lastModified;
+ protected Timestamp lastModified;
/**
* Description about the resource. This may contain any text including HTML fragments.
*/
- private String description;
+ protected String description;
/**
* Unique path of the resource within the registry. This is generated by appending all
@@ -88,7 +89,7 @@
* is inside the root level collection named "servers". Then the path of the resource is
* /servers/config/users.xml.
*/
- private String path;
+ protected String path;
/**
* Media type of the resource. Each resource can have a media type associated with it. This can
@@ -97,26 +98,39 @@
* Thus, by defining a media type for a resource and by registering a media type handler to
* handle that media type, it is possible to apply special processing for resources.
*/
- private String mediaType;
+ protected String mediaType;
/**
* Path of the parent collection of the resource. If the resource path is
* /servers/config/users.xml, parent path is /servers/config.
*/
- private String parentPath;
+ protected 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;
+ protected boolean contentModified;
+
+ /**
+ * Used to detect whether properties of this resource is modified since retrieval from the
+ * repository. If true, properties will be updated and new version will be created upon putting
+ * this resource to the repository.
+ */
+ protected boolean propertiesModified;
+
+ /**
+ * Determines whether the resource is subjected to changes, which causes it to create a new
+ * version. If true, a new version will be created upon adding the resource to the repository.
+ */
+ protected boolean versionableChange;
/**
* Normal resources have the state RegistryConstants.ACTIVE_STATE (100) Deleted resources have
* the state RegistryConstants.DELETED_STATE (101)
*/
- private int state;
+ protected int state;
/**
* Properties associated with the resource. A resource can contain zero or more properties,
@@ -146,12 +160,12 @@
* resources are considered as files. If you want to make a collection, you have to explicitly
* set the directory field to true.
*/
- private boolean directory = false;
+ protected boolean directory = false;
/**
* Content of the resource, represented as a input stream.
*/
- private InputStream contentStream;
+ protected InputStream contentStream;
/**
@@ -160,7 +174,7 @@
* fetched upon the first request to optimize the response time. Getters of such attributes use
* this datasource to fetch the values from the database.
*/
- private DataSource dataSource;
+ protected DataSource dataSource;
/**
* Resource DAO instance to access the database directly. Note that the VersionedResourceDAO is
@@ -169,12 +183,12 @@
private ResourceDAO resourceDAO;
public ResourceImpl() {
+ resourceDAO = new ResourceDAO();
id = UUIDGenerator.generateUUID();
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
- resourceDAO = new ResourceDAO();
}
public String getId() {
@@ -223,6 +237,7 @@
public void setDescription(String description) {
this.description = description;
+ versionableChange = true;
}
public String getPath() {
@@ -239,6 +254,7 @@
public void setMediaType(String mediaType) {
this.mediaType = mediaType;
+ versionableChange = true;
}
public String getParentPath() {
@@ -282,10 +298,14 @@
List propValues = new ArrayList();
propValues.add(value);
properties.put(key, propValues);
+
+ setPropertiesModified(true);
}
public void setProperty(String key, List<String> value) {
properties.put(key, value);
+
+ setPropertiesModified(true);
}
public void addProperty(String key, String value) {
@@ -299,10 +319,14 @@
propValues.add(value);
properties.put(key, propValues);
}
+
+ setPropertiesModified(true);
}
public void setProperties(Properties properties) {
this.properties = properties;
+
+ setPropertiesModified(true);
}
public String getContentID() {
@@ -328,6 +352,11 @@
new BufferedInputStream(new ByteArrayInputStream(contentBytes));
}
+ } else if (Transaction.isStarted()) {
+
+ Connection conn = Transaction.getConnection();
+ contentStream = resourceDAO.getResourceContentStream(contentID, conn);
+
} else if (dataSource != null) {
Connection conn = null;
@@ -358,7 +387,6 @@
}
public void setContentStream(InputStream contentStream) {
- contentModified = true;
// When a content is set as an input stream, prevoius contents set as object get invalidated
// But we don't want to generate that content till it is explicitly get using getContent
@@ -367,6 +395,8 @@
}
this.contentStream = contentStream;
+
+ setContentModified(true);
}
public Object getContent() throws RegistryException {
@@ -411,7 +441,7 @@
this.contentStream = null;
}
- this.contentModified = true;
+ setContentModified(true);
}
private String preparePath(String path) {
@@ -450,6 +480,24 @@
*/
public void setContentModified(boolean contentModified) {
this.contentModified = contentModified;
+ versionableChange = true;
+ }
+
+ public boolean isPropertiesModified() {
+ return propertiesModified;
+ }
+
+ public void setPropertiesModified(boolean propertiesModified) {
+ this.propertiesModified = propertiesModified;
+ versionableChange = true;
+ }
+
+ public boolean isVersionableChange() {
+ return versionableChange;
+ }
+
+ public void setVersionableChange(boolean versionableChange) {
+ this.versionableChange = versionableChange;
}
public List<String> getAspects() {
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceVersionImpl.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceVersionImpl.java Fri May 2 02:40:41 2008
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry;
+
+import org.wso2.registry.jdbc.dao.ResourceVersionDAO;
+import org.wso2.registry.jdbc.utils.Transaction;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.InputStream;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class ResourceVersionImpl extends ResourceImpl {
+
+ private static Log log = LogFactory.getLog(ResourceVersionImpl.class);
+
+ ResourceVersionDAO resourceVersionDAO = new ResourceVersionDAO();
+
+ public InputStream getContentStream() throws RegistryException {
+
+ if (contentStream == null) {
+ if (content != null) {
+
+ if (content instanceof byte[]) {
+ this.contentStream =
+ new BufferedInputStream(new ByteArrayInputStream((byte[]) content));
+
+ } else if (content instanceof String) {
+ byte[] contentBytes = ((String) content).getBytes();
+ this.contentStream =
+ new BufferedInputStream(new ByteArrayInputStream(contentBytes));
+ }
+
+ } else if (Transaction.isStarted()) {
+
+ Connection conn = Transaction.getConnection();
+ contentStream = resourceVersionDAO.getResourceContentStream(contentID, conn);
+
+ } else if (dataSource != null) {
+
+ Connection conn = null;
+
+ try {
+ conn = dataSource.getConnection();
+ contentStream = resourceVersionDAO.getResourceContentStream(contentID, conn);
+
+ } catch (Exception e) {
+ String msg =
+ "Failed to get the input stream for the content " +
+ "of versioned resource: " + path;
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+
+ } finally {
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ log.error("Failed to close the database connection.", e);
+ }
+ }
+ }
+ }
+ }
+
+ return contentStream;
+ }
+}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java Fri May 2 02:40:41 2008
@@ -490,6 +490,9 @@
return null;
}
+ public void createVersion(String path) throws RegistryException {
+ }
+
public String[] getVersions(String path) throws RegistryException {
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse =
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java Fri May 2 02:40:41 2008
@@ -66,6 +66,7 @@
protected HandlerManager handlerManager;
protected Repository repository;
+ protected VersionRepository versionRepository;
private Map<String, Aspect> aspects = new HashMap<String, Aspect>();
private UserRealm defaultRealm = null;
@@ -144,6 +145,7 @@
}
repository = new Repository(dataSource);
+ versionRepository = new VersionRepository(dataSource);
handlerManager = new HandlerManager(this, repository);
queryProcessorManager = new QueryProcessorManager(dataSource, realm, this);
@@ -165,7 +167,7 @@
registerBuiltInHandlers();
transactionalRegistry = new TransactionalJDBCRegistry(
- handlerManager, repository, queryProcessorManager, aspects);
+ handlerManager, repository, versionRepository, queryProcessorManager, aspects);
nonTransactionalRegistry = new NonTransactionalJDBCRegistry(
transactionalRegistry, dataSource);
@@ -412,8 +414,22 @@
}
}
+ public void createVersion(String path) throws RegistryException {
+
+ if (Transaction.isStarted()) {
+ transactionalRegistry.createVersion(path);
+ } else {
+ nonTransactionalRegistry.createVersion(path);
+ }
+ }
+
public String[] getVersions(String path) throws RegistryException {
- return new String[0];
+
+ if (Transaction.isStarted()) {
+ return transactionalRegistry.getVersions(path);
+ } else {
+ return nonTransactionalRegistry.getVersions(path);
+ }
}
public void restoreVersion(String versionPath) throws RegistryException {
@@ -646,7 +662,7 @@
rollbackTransaction();
- throw new RegistryException(msg);
+ throw new RegistryException(msg, e);
}
CurrentSession.removeUser();
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/NonTransactionalJDBCRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/NonTransactionalJDBCRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/NonTransactionalJDBCRegistry.java Fri May 2 02:40:41 2008
@@ -404,13 +404,51 @@
rollbackTransaction();
throw new RegistryException(msg, e);
+ }
+ }
+
+ public void createVersion(String path) throws RegistryException {
+
+ boolean success = false;
+ try {
+
+ beginTransaction();
+
+ transactionalJDBCRegistry.createVersion(path);
+
+ success = true;
+
+ } finally {
+ if (success) {
+ commitTransaction();
+ } else {
+ rollbackTransaction();
+ }
}
}
public String[] getVersions(String path) throws RegistryException {
- throw new RegistryException("Not yet implemented.");
+ boolean success = false;
+ try {
+
+ beginTransaction();
+
+ String[] versionPaths = transactionalJDBCRegistry.getVersions(path);
+
+ success = true;
+
+ return versionPaths;
+
+ } finally {
+
+ if (success) {
+ commitTransaction();
+ } else {
+ rollbackTransaction();
+ }
+ }
//String[] versionPaths = null;
//
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java Fri May 2 02:40:41 2008
@@ -38,7 +38,7 @@
/**
* Encapsulates the retrieving, storing, modifing and deleting of resources. This class only deals
* with the current versions of resources and it is unware of any versioning or snapshot activity.
- * Only the current version related tables are accessed and updated from the methods of this class.
+ * Only the current version related tables are accessed and updated from the methods of this class.
*/
public class Repository {
@@ -60,7 +60,6 @@
* Checks if a pure resource exists in the given path.
*
* @param path Path of a possible pure resource.
- *
* @return ture if a resource exists in the given path. false otherwise.
*/
public boolean resourceExists(String path) throws RegistryException {
@@ -76,8 +75,7 @@
* this gives the current version of the resource.
*
* @param path Path of a "pure" resource. Path should map to an actual resource stored
- * in the database. Paths refering to virtual resource are not handled (e.g. /c1/r1;comments).
- *
+ * in the database. Paths refering to virtual resource are not handled (e.g. /c1/r1;comments).
* @return Resource refered by the given path. Resource can be a file or a collection.
*/
public Resource get(String path) throws RegistryException {
@@ -98,7 +96,7 @@
Resource resource = resourceDAO.get(purePath);
((ResourceImpl) resource).setDataSource(dataSource);
-
+
return resource;
}
@@ -127,7 +125,7 @@
* Adds or updates the resource in the given path with the given resource. Put is executed if
* the current user has authorization to do so. Below is the method of evaluating
* authorizations.
- *
+ * <p/>
* <ul>
* <li> user should have WRITE permissions for the resource, if he wants to update the
* resource.</li>
@@ -135,10 +133,9 @@
* add a new resource.</li>
* </ul>
*
- * @param path Path of the resource to be added or updated. Path should only refer to current
- * version a pure resource. i.e. Path should not contain any version information as it is
- * impossible to add or update old versions.
- *
+ * @param path Path of the resource to be added or updated. Path should only refer to current
+ * version a pure resource. i.e. Path should not contain any version information as it is
+ * impossible to add or update old versions.
* @param resource Resource to be added or updated.
*/
public void put(String path, Resource resource) throws RegistryException {
@@ -163,9 +160,9 @@
* the given metadata resource instance. Then the created resource is put to the registry using
* the Repository.put() method.
*
- * @param path Path to put the resource
+ * @param path Path to put the resource
* @param sourceURL URL to import resource content
- * @param metadata Metadata for the new resource is extracted from this metadata resource
+ * @param metadata Metadata for the new resource is extracted from this metadata resource
* @return Actual path where the new resource is stored in the registry
* @throws RegistryException for all exceptional scenarios
*/
@@ -210,8 +207,8 @@
* Deletes the pure resource refered by the path.
*
* @param path path Path of the resource deleted. Path should only refer to current
- * version a pure resource. i.e. Path should not contain any version information as it is
- * impossible to delete old versions.
+ * version a pure resource. i.e. Path should not contain any version information as it is
+ * impossible to delete old versions.
*/
public void delete(String path) throws RegistryException {
@@ -255,8 +252,8 @@
String resourceID = resourceDAO.getResourceID(oldPath);
resourceDAO.setPath(resourceID, newPath);
- List <String> childIDs = resourceDAO.getChildIDs(resourceID);
- Iterator <String> iChild = childIDs.iterator();
+ List<String> childIDs = resourceDAO.getChildIDs(resourceID);
+ Iterator<String> iChild = childIDs.iterator();
while (iChild.hasNext()) {
String childID = iChild.next();
renameChildren(childID, newPath);
@@ -280,31 +277,40 @@
// add RID of oldPath as a child of parent of newPath
// update paths of moved resource and all its children
- oldPath = RegistryUtils.getPureResourcePath(oldPath);
- newPath = RegistryUtils.getPureResourcePath(newPath);
-
- String resourceID = resourceDAO.getResourceID(oldPath);
- resourceDAO.detachChild(resourceID);
-
- String newParentPath = RegistryUtils.getParentPath(newPath);
- String parentID = resourceDAO.getResourceID(newParentPath);
- if (parentID == null) {
- Collection parent = new CollectionImpl();
- put(newParentPath, parent);
- parentID = parent.getId();
- }
-
- resourceDAO.attachChild(parentID, resourceID);
-
- resourceDAO.setPath(resourceID, newPath);
-
- List <String> childIDs = resourceDAO.getChildIDs(resourceID);
- Iterator <String> iChild = childIDs.iterator();
- while (iChild.hasNext()) {
- String childID = iChild.next();
- renameChildren(childID, newPath);
- }
-
+ //oldPath = RegistryUtils.getPureResourcePath(oldPath);
+ //newPath = RegistryUtils.getPureResourcePath(newPath);
+ //
+ //String resourceID = resourceDAO.getResourceID(oldPath);
+ //resourceDAO.detachChild(resourceID);
+ //
+ //String newParentPath = RegistryUtils.getParentPath(newPath);
+ //String parentID = resourceDAO.getResourceID(newParentPath);
+ //if (parentID == null) {
+ // Collection parent = new CollectionImpl();
+ // put(newParentPath, parent);
+ // parentID = parent.getId();
+ //}
+ //
+ //resourceDAO.attachChild(parentID, resourceID);
+ //
+ //resourceDAO.setPath(resourceID, newPath);
+ //
+ //List<String> childIDs = resourceDAO.getChildIDs(resourceID);
+ //Iterator<String> iChild = childIDs.iterator();
+ //while (iChild.hasNext()) {
+ // String childID = iChild.next();
+ // renameChildren(childID, newPath);
+ //}
+ //
+ //return newPath;
+
+ // we are implementing move as copying the resource to the new path and deleting the old
+ // resource. therefore, the moved resource will be threated as a new resource (i.e without
+ // a version hostory. but the resource at old path (which is deleted) has its version
+ // hostory. so it is possible to restore the parent collection of old path and get old
+ // versions of that resource.
+ copy(oldPath, newPath);
+ delete(oldPath);
return newPath;
}
@@ -318,8 +324,8 @@
put(targetPath, resource);
String resourceID = resourceDAO.getResourceID(sourcePath);
- List <String> childIDs = resourceDAO.getChildIDs(resourceID);
- Iterator <String> iChild = childIDs.iterator();
+ List<String> childIDs = resourceDAO.getChildIDs(resourceID);
+ Iterator<String> iChild = childIDs.iterator();
while (iChild.hasNext()) {
String childID = iChild.next();
copy(sourcePath, targetPath, childID);
@@ -338,8 +344,8 @@
String targetPathForThisResource = targetPath + resourcePath.substring(sourcePath.length());
put(targetPathForThisResource, resource);
- List <String> childIDs = resourceDAO.getChildIDs(resourceID);
- Iterator <String> iChild = childIDs.iterator();
+ List<String> childIDs = resourceDAO.getChildIDs(resourceID);
+ Iterator<String> iChild = childIDs.iterator();
while (iChild.hasNext()) {
String childID = iChild.next();
copy(sourcePath, targetPath, childID);
@@ -403,17 +409,16 @@
* Adds all non-existent collections of the given path starting from the root. Note that we
* are not using recursive method call here to avoid possible stack overflaws due to deep
* trees.
- *
+ * <p/>
* Start from the root and check each ancestor collection exists. If we find any ancestor
* "resource" we can give this up, as resources cannot contain other collcetions or resources.
* When we find the first missing collection, we have to check whether the user has PUT
* permission for the parent of that collection. If user does, add a new collection.
- *
+ * <p/>
* Now we don't have to worry about permissions anymore. Because authorizations are copied
* from parent to child, user can add all other required resources.
*
* @param path Path of which all non-existent collections are added.
- *
* @throws RegistryException If any ancestor of the given path is a resource.
*/
private void addParents(String path) throws RegistryException {
@@ -482,8 +487,8 @@
resourceDAO.setPath(resourceID, newPath);
- List <String> childIDs = resourceDAO.getChildIDs(resourceID);
- Iterator <String> iChild = childIDs.iterator();
+ List<String> childIDs = resourceDAO.getChildIDs(resourceID);
+ Iterator<String> iChild = childIDs.iterator();
while (iChild.hasNext()) {
String childID = iChild.next();
renameChildren(childID, newPath);
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/TransactionalJDBCRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/TransactionalJDBCRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/TransactionalJDBCRegistry.java Fri May 2 02:40:41 2008
@@ -46,6 +46,7 @@
private Repository repository;
private QueryProcessorManager queryProcessorManager;
private Map<String, Aspect> aspects;
+ private VersionRepository versionRepository;
private ResourceDAO resourceDAO = new ResourceDAO();
private AssociationDAO associationDAO = new AssociationDAO();
@@ -57,11 +58,13 @@
public TransactionalJDBCRegistry(
HandlerManager handlerManager,
Repository repository,
+ VersionRepository versionRepository,
QueryProcessorManager queryProcessorManager,
Map<String, Aspect> aspects) {
this.handlerManager = handlerManager;
this.repository = repository;
+ this.versionRepository = versionRepository;
this.queryProcessorManager = queryProcessorManager;
this.aspects = aspects;
}
@@ -129,7 +132,12 @@
}
if (resource == null) {
- resource = repository.get(path);
+ VersionedPath versionedPath = RegistryUtils.getVersionedPath(path);
+ if (versionedPath.getVersion() == -1) {
+ resource = repository.get(path);
+ } else {
+ resource = versionRepository.get(versionedPath);
+ }
}
if (resource == null) {
@@ -193,6 +201,12 @@
if (!requestContext.isProcessingComplete()) {
actualPath = suggestedPath;
repository.put(suggestedPath, resource);
+
+ // we are always creating versions for resources (files), if the resource has changed.
+ if (!(resource instanceof Collection) &&
+ ((ResourceImpl) resource).isVersionableChange()) {
+ createVersion(actualPath);
+ }
}
logsDAO.addLog(suggestedPath, CurrentSession.getUser(), LogEntry.UPDATE, null);
@@ -277,9 +291,14 @@
return copiedPath;
}
+ public void createVersion(String path) throws RegistryException {
+
+ versionRepository.createSnapshot(path);
+ }
+
public String[] getVersions(String path) throws RegistryException {
- throw new RegistryException("Not yet implemented.");
+ return versionRepository.getVersions(path);
//String[] versionPaths = null;
//
@@ -318,7 +337,7 @@
public void restoreVersion(String versionPath) throws RegistryException {
- throw new RegistryException("Verioning is not yet implemented.");
+ versionRepository.restoreVersion(versionPath);
//String plainPath;
//long versionNumber;
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/VersionRepository.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/VersionRepository.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/VersionRepository.java Fri May 2 02:40:41 2008
@@ -16,21 +16,150 @@
package org.wso2.registry.jdbc;
-import org.wso2.registry.RegistryException;
-import org.wso2.registry.Resource;
-import org.wso2.registry.ActionConstants;
-import org.wso2.registry.ResourceImpl;
-import org.wso2.registry.session.CurrentSession;
-import org.wso2.registry.utils.AuthorizationUtils;
+import org.wso2.registry.*;
+import org.wso2.registry.jdbc.dao.ResourceDAO;
+import org.wso2.registry.jdbc.dao.ResourceVersionDAO;
+import org.wso2.registry.utils.VersionedPath;
import org.wso2.registry.utils.RegistryUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.net.URLConnection;
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.Iterator;
+import java.util.ArrayList;
import java.io.InputStream;
-import java.io.IOException;
public class VersionRepository {
-
+ private static Log log = LogFactory.getLog(VersionRepository.class);
+
+ private DataSource dataSource;
+
+ private ResourceDAO resourceDAO = new ResourceDAO();
+ private ResourceVersionDAO resourceVersionDAO = new ResourceVersionDAO();
+
+ public VersionRepository(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public void createSnapshot(String path) throws RegistryException {
+
+ path = RegistryUtils.getPureResourcePath(path);
+
+ String snapshotRootID = resourceDAO.getResourceID(path);
+
+ long snapshotID = resourceVersionDAO.addSnapshot(snapshotRootID);
+ versionSnapshotNetwork(snapshotID, snapshotRootID);
+ }
+
+ private void versionSnapshotNetwork(long snapshotID, String resourceID)
+ throws RegistryException {
+
+ int equivalentVersion = resourceDAO.getEquivalentVersion(resourceID);
+
+ List <String> childIDs = resourceDAO.getChildIDs(resourceID);
+
+ if (equivalentVersion == -1) {
+ // resource has changed since the last version.
+
+ ResourceImpl resourceImpl = resourceDAO.getResourceByID(resourceID);
+ if (resourceImpl instanceof CollectionImpl) {
+ resourceDAO.fillChildren((CollectionImpl) resourceImpl, -1, -1);
+ }
+ resourceDAO.fillResourceProperties(resourceImpl);
+
+ // add the resource content to the content version table and get the ID
+ // todo: if the resource content has not changed between two versions we can share the
+ // todo: same content.
+ resourceImpl.setDataSource(dataSource);
+ InputStream contentStream = resourceImpl.getContentStream();
+ String contentVersionID = resourceVersionDAO.addContentVersion(contentStream);
+
+ int versionNumber = resourceVersionDAO.
+ addResourceVersion(resourceImpl, contentVersionID);
+ resourceVersionDAO.addDependencies(resourceID, versionNumber, childIDs);
+ resourceVersionDAO.addSnapshotResource(snapshotID, resourceID, versionNumber);
+ resourceVersionDAO.addProperties(resourceImpl, versionNumber);
+ }
+
+ Iterator<String> childIterator = childIDs.iterator();
+ while (childIterator.hasNext()) {
+
+ String childID = childIterator.next();
+ versionSnapshotNetwork(snapshotID, childID);
+ }
+ }
+
+ public String[] getVersions(String resourcePath) throws RegistryException {
+
+ resourcePath = RegistryUtils.getPureResourcePath(resourcePath);
+
+ Long[] snapshotNumbers = resourceVersionDAO.getSnapshotIDs(resourcePath);
+
+ List <String> versionPaths = new ArrayList();
+ for (int i = 0; i < snapshotNumbers.length; i++) {
+ String versionPath = resourcePath + ";version=" + snapshotNumbers[i];
+ versionPaths.add(versionPath);
+ }
+
+ return versionPaths.toArray(new String[versionPaths.size()]);
+ }
+
+ public Resource get(VersionedPath versionedPath) throws RegistryException {
+
+ String resourceID = resourceDAO.getResourceID(versionedPath.getPath());
+ long snapshotID = versionedPath.getVersion();
+
+ long version = resourceVersionDAO.getVersion(resourceID, snapshotID);
+
+ if (version == -1) {
+ String msg = "Resource " + versionedPath.getPath() +
+ " does not have a version " + versionedPath.getVersion();
+ log.error(msg);
+ throw new RegistryException(msg);
+ }
+
+ ResourceImpl resourceImpl = resourceVersionDAO.get(resourceID, snapshotID, version);
+ resourceImpl.setDataSource(dataSource);
+
+ return resourceImpl;
+ }
+
+ public void restoreVersion(String versionPath) throws RegistryException {
+
+ VersionedPath versionedPath = RegistryUtils.getVersionedPath(versionPath);
+ if (versionedPath.getVersion() == -1) {
+ String msg = "Failed to restore resource. " +
+ versionedPath + " is not a valid version path.";
+ log.error(msg);
+ throw new RegistryException(msg);
+ }
+ }
+
+ private void restoreSnapshotNetwork(long snapshotID, String resourceID)
+ throws RegistryException {
+
+ // get the version number of resource for this snapshot
+ // check if the resource exists in the resource table
+ // if no,
+ // copy version to the resource table
+ // copy content to the content table and set the content ID of the resource
+ // copy all versioned properies to the properties table
+ // if yes,
+ // check if that version number and equivalent version number are same
+ // if no,
+ // replace versionalble fields of the resource table
+ // copy versioned content to content table, and set the content ID of the resource
+ // delete all properties of old resource and copy properties from the version
+ // end if
+ // end if
+ // get children of the version
+ // get chledren of the current version
+ // delete removed children
+ // for each child
+ // call restoreSnapshotNetwork
+ // end for
+
+ }
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceDAO.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceDAO.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceDAO.java Fri May 2 02:40:41 2008
@@ -277,7 +277,7 @@
return collection;
}
- private void fillResourceProperties(ResourceImpl resourceImpl) throws RegistryException {
+ public void fillResourceProperties(ResourceImpl resourceImpl) throws RegistryException {
Connection conn = Transaction.getConnection();
@@ -302,6 +302,8 @@
log.error(msg, e);
throw new RegistryException(msg, e);
}
+
+ resourceImpl.setPropertiesModified(false);
}
public void addRoot(String path, ResourceImpl resourceImpl)
@@ -328,13 +330,72 @@
public void update(String resourceID, ResourceImpl resourceImpl) throws RegistryException {
+
if (resourceImpl.isContentModified()) {
addContent(resourceImpl);
}
updateResource(resourceID, resourceImpl);
- updateProperties(resourceImpl);
+ if (resourceImpl.isPropertiesModified()) {
+ updateProperties(resourceImpl);
+ }
+
+ if (resourceImpl.isVersionableChange()) {
+ setEquivalentVersion(resourceID, -1);
+ }
+ }
+
+ public int getEquivalentVersion(String resourceID) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ int equivalentVersion = -2;
+ try {
+ String sql = "SELECT EQUIVALENT_VERSION FROM RESOURCE WHERE RID=?";
+
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setString(1, resourceID);
+
+ ResultSet result = ps.executeQuery();
+ if (result.next()) {
+ equivalentVersion = result.getInt("EQUIVALENT_VERSION");
+ }
+
+ ps.close();
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to get the equivalen version of resource " +
+ resourceID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ return equivalentVersion;
+ }
+
+ public void setEquivalentVersion(String resourceID, int equivalentVersion)
+ throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ try {
+ String sql = "UPDATE RESOURCE SET EQUIVALENT_VERSION=? WHERE RID=?";
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setInt(1, equivalentVersion);
+ ps.setString(2, resourceID);
+ ps.executeUpdate();
+ ps.close();
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to update the equivalent version of the resource " +
+ resourceID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
}
public void delete(String resourceID) throws RegistryException {
@@ -423,7 +484,7 @@
}
}
- private void fillChildren(CollectionImpl collection, int start, int pageLen)
+ public void fillChildren(CollectionImpl collection, int start, int pageLen)
throws RegistryException {
Connection conn = Transaction.getConnection();
@@ -514,6 +575,55 @@
}
}
+ public ResourceImpl getResourceByID(String resourceID) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ try {
+ String sql = "SELECT RID, PATH, MEDIA_TYPE, COLLECTION, CREATOR, CREATED_TIME, " +
+ "LAST_UPDATOR, LAST_UPDATED_TIME, DESCRIPTION, CONTENT_ID FROM RESOURCE WHERE RID=?";
+
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setString(1, resourceID);
+
+ ResultSet result = ps.executeQuery();
+
+ ResourceImpl resourceImpl = null;
+
+ if (result.next()) {
+
+ if (result.getInt("COLLECTION") == 0) {
+ resourceImpl = new ResourceImpl();
+ } else {
+ resourceImpl = new CollectionImpl();
+ }
+
+ // this is always the current version of the resource
+ resourceImpl.setVersionNumber(-1);
+
+ resourceImpl.setId(result.getString("RID"));
+ resourceImpl.setPath(result.getString("PATH"));
+ resourceImpl.setMediaType(result.getString("MEDIA_TYPE"));
+ resourceImpl.setAuthorUserName(result.getString("CREATOR"));
+ resourceImpl.setCreatedTime(result.getTimestamp("CREATED_TIME"));
+ resourceImpl.setLastUpdaterUserName(result.getString("LAST_UPDATOR"));
+ resourceImpl.setLastModified(result.getTimestamp("LAST_UPDATED_TIME"));
+ resourceImpl.setDescription(result.getString("DESCRIPTION"));
+ resourceImpl.setContentID(result.getString("CONTENT_ID"));
+ }
+
+ ps.close();
+
+ return resourceImpl;
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to get the resource " + resourceID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
/**
* Returns a input stream to fetch content of the resource. Input stream is disconnected from
* the database, so that it is possible to close the connection before reading the content
@@ -542,6 +652,7 @@
ps.setString(1, contentID);
ResultSet result = ps.executeQuery();
+
if (result.next()) {
contentStream = getDisconnectedStream(result.getBinaryStream("CONTENT_DATA"));
}
@@ -590,8 +701,9 @@
try {
String sql = "INSERT INTO RESOURCE (RID, PATH, MEDIA_TYPE, COLLECTION, CREATOR, " +
- "CREATED_TIME, LAST_UPDATOR, LAST_UPDATED_TIME, DESCRIPTION, CONTENT_ID) " +
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ "CREATED_TIME, LAST_UPDATOR, LAST_UPDATED_TIME, DESCRIPTION, " +
+ "CONTENT_ID, EQUIVALENT_VERSION) " +
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
long now = System.currentTimeMillis();
@@ -606,6 +718,7 @@
ps.setTimestamp(8, new Timestamp(now));
ps.setString(9, resourceImpl.getDescription());
ps.setString(10, resourceImpl.getContentID());
+ ps.setInt(11, -1); // this is a new resource. so there is no equivalent version.
ps.executeUpdate();
@@ -657,6 +770,8 @@
private void deleteResource(String resourceID) throws RegistryException {
+ setParentEquivalentVersion(resourceID, -1);
+
Connection conn = Transaction.getConnection();
try {
@@ -677,6 +792,31 @@
}
}
+ private void setParentEquivalentVersion(String childID, int equivalentVersion)
+ throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ try {
+ String sql = "UPDATE RESOURCE R SET R.EQUIVALENT_VERSION=? " +
+ "WHERE R.RID=(SELECT D.PARENT_RID FROM DEPENDENCY D WHERE D.CHILD_RID=?)";
+
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setInt(1, equivalentVersion);
+ ps.setString(2, childID);
+
+ ps.executeUpdate();
+ ps.close();
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to set the equivalent version of the parent of child resource " +
+ childID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
private void addDependency(String parentID, String childID) throws RegistryException {
Connection conn = Transaction.getConnection();
@@ -700,6 +840,7 @@
throw new RegistryException(msg, e);
}
+ setEquivalentVersion(parentID, -1);
}
private void addProperties(Resource resource) throws RegistryException {
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceVersionDAO.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceVersionDAO.java Fri May 2 02:40:41 2008
@@ -0,0 +1,608 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry.jdbc.dao;
+
+import org.wso2.registry.jdbc.utils.Transaction;
+import org.wso2.registry.*;
+import org.wso2.registry.Collection;
+import org.wso2.registry.utils.AuthorizationUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.sql.*;
+import java.util.*;
+import java.io.*;
+
+public class ResourceVersionDAO {
+
+ private static Log log = LogFactory.getLog(ResourceVersionDAO.class);
+
+ public long addSnapshot(String snapshotRootID) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ String sql = "INSERT INTO SNAPSHOT (ROOT_ID) VALUES (?)";
+ try {
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setString(1, snapshotRootID);
+ ps.executeUpdate();
+ ps.close();
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to add snapshot for the resource " +
+ snapshotRootID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ String sql2 = "SELECT MAX(SNAPSHOT_ID) FROM SNAPSHOT WHERE ROOT_ID=? GROUP BY ROOT_ID";
+ try {
+ PreparedStatement ps2 = conn.prepareStatement(sql2);
+ ps2.setString(1, snapshotRootID);
+
+ ResultSet result = ps2.executeQuery();
+ long snapshotID = 0;
+ if (result.next()) {
+ snapshotID = result.getLong(1);
+ }
+
+ return snapshotID;
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to get the latest snapshot ID of the resource " +
+ snapshotRootID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ public int getLatestResourceVersionNumber(String resourceID) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ String sql = "SELECT MAX(VERSOIN) " +
+ "FROM RESOURCE_VERSION WHERE RID=? GROUP BY RID";
+
+ int snapshotNumber = 0;
+ try {
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setString(1, resourceID);
+
+ ResultSet result = ps.executeQuery();
+ if (result.next()) {
+ snapshotNumber = result.getInt(1);
+ }
+
+ ps.close();
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to get the latest snapshot number of the resource " +
+ resourceID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ return snapshotNumber;
+ }
+
+ public int addResourceVersion(ResourceImpl resourceImpl, String contentVersionID)
+ throws RegistryException {
+
+ int versionNumber = getMaxResourceVersion(resourceImpl.getId()) + 1;
+
+ Connection conn = Transaction.getConnection();
+
+ String sql = "INSERT INTO RESOURCE_VERSION (RID, VERSION, PATH, MEDIA_TYPE, COLLECTION, " +
+ "CREATOR, CREATED_TIME, LAST_UPDATOR, LAST_UPDATED_TIME, DESCRIPTION, CONTENT_ID) " +
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+
+ try {
+ PreparedStatement ps = conn.prepareStatement(sql);
+
+ ps.setString(1, resourceImpl.getId());
+ ps.setInt(2, versionNumber);
+ ps.setString(3, resourceImpl.getPath());
+ ps.setString(4, resourceImpl.getMediaType());
+ ps.setInt(5, (resourceImpl instanceof Collection) ? 1: 0);
+ ps.setString(6, resourceImpl.getAuthorUserName());
+ ps.setTimestamp(7, new Timestamp(resourceImpl.getCreatedTime().getTime()));
+ ps.setString(8, resourceImpl.getLastUpdaterUserName());
+ ps.setTimestamp(9, new Timestamp(resourceImpl.getLastModified().getTime()));
+ ps.setString(10, resourceImpl.getDescription());
+ ps.setString(11, contentVersionID);
+
+ ps.executeUpdate();
+ ps.close();
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to add new version for resource " +
+ resourceImpl.getPath() + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ return versionNumber;
+ }
+
+ public int getMaxResourceVersion(String resourceID) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ String sql = "SELECT MAX(VERSION) FROM RESOURCE_VERSION WHERE RID=? GROUP BY RID";
+
+ int maxVersion = 0;
+ try {
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setString(1, resourceID);
+
+ ResultSet result = ps.executeQuery();
+ if (result.next()) {
+ maxVersion = result.getInt(1);
+ }
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to latest version number of the resource " +
+ resourceID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ return maxVersion;
+ }
+
+ public void addDependencies(String resourceID, int versionNumber, List<String> childIDs)
+ throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ String sql = "INSERT INTO DEPENDENCY_VERSION (PARENT_RID, PARENT_VERSION, CHILD_RID) " +
+ "VALUES (?, ?, ?)";
+
+ try {
+ PreparedStatement ps = conn.prepareStatement(sql);
+
+ Iterator <String> iChildIDs = childIDs.iterator();
+ while(iChildIDs.hasNext()) {
+ String childID = iChildIDs.next();
+
+ ps.setString(1, resourceID);
+ ps.setInt(2, versionNumber);
+ ps.setString(3, childID);
+
+ ps.executeUpdate();
+ ps.clearParameters();
+ }
+ ps.close();
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to add dependencies for version " + versionNumber +
+ " of resource " + resourceID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ public void addProperties(ResourceImpl resource, long version) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ try {
+ String sql = "INSERT INTO PROPERTY_VERSION (RID, VERSION, NAME, VALUE) " +
+ "VALUES (?, ?, ?, ?)";
+
+ PreparedStatement ps = conn.prepareStatement(sql);
+
+ String resourceID = resource.getId();
+ Properties props = resource.getProperties();
+ if (props != null) {
+
+ Iterator i = props.keySet().iterator();
+ while (i.hasNext()) {
+ String name = (String)i.next();
+
+ List propValues = (List) props.get(name);
+ if (propValues != null) {
+ Iterator<String> iValues = propValues.iterator();
+ while (iValues.hasNext()) {
+ String value = iValues.next();
+
+ ps.setString(1, resourceID);
+ ps.setLong(2, version);
+ ps.setString(3, name);
+ ps.setString(4, value);
+
+ ps.executeUpdate();
+ ps.clearParameters();
+ }
+ }
+ }
+ }
+
+ ps.close();
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to version properties to the resource " +
+ resource.getPath() + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ public void addSnapshotResource(long snapshotID, String resourceID, int versionNumber)
+ throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ String sql = "INSERT INTO SNAPSHOT_RESOURCE_VERSION (SNAPSHOT_ID, RID, VERSION) " +
+ "VALUES (?, ?, ?)";
+
+ try {
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setLong(1, snapshotID);
+ ps.setString(2, resourceID);
+ ps.setInt(3, versionNumber);
+
+ ps.executeUpdate();
+ ps.close();
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to add snapshot resource version for version " +
+ versionNumber + " of resource " + resourceID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ public Long[] getSnapshotIDs(String resourcePath) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ String sql = "SELECT SNAPSHOT_ID FROM SNAPSHOT " +
+ "WHERE ROOT_ID=(SELECT RID FROM RESOURCE WHERE PATH=?)";
+
+ try {
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setString(1, resourcePath);
+
+ ResultSet results = ps.executeQuery();
+ List <Long> snapshotIDs = new ArrayList();
+ while(results.next()) {
+ long snapshotNumber = results.getLong("SNAPSHOT_ID");
+ snapshotIDs.add(snapshotNumber);
+ }
+ ps.close();
+
+ return snapshotIDs.toArray(new Long[snapshotIDs.size()]);
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to get snapshot numbers of resource " +
+ resourcePath + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ public long getVersion(String resourceID, long snapshotID) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ String sql = "SELECT VERSION FROM SNAPSHOT_RESOURCE_VERSION WHERE SNAPSHOT_ID=? AND RID=?";
+
+ try {
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setLong(1, snapshotID);
+ ps.setString(2, resourceID);
+
+ ResultSet result = ps.executeQuery();
+ long version = -1;
+ if (result.next()) {
+ version = result.getLong("VERSION");
+ }
+ ps.close();
+
+ return version;
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to get version of resource " + resourceID +
+ " of snapshot " + snapshotID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ public ResourceImpl get(String resourceID, long snapshotID, long version)
+ throws RegistryException {
+
+ ResourceImpl resourceImpl = getResource(resourceID, version);
+
+ if (resourceImpl instanceof Collection) {
+ fillChildren(resourceImpl, snapshotID);
+ }
+
+ fillResourceProperties(resourceImpl);
+
+ return resourceImpl;
+ }
+
+ private void fillResourceProperties(ResourceImpl resourceImpl) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ try {
+ String propSQL = "SELECT NAME, VALUE FROM PROPERTY_VERSION WHERE RID=? AND VERSION=?";
+ PreparedStatement ps = conn.prepareStatement(propSQL);
+ ps.setString(1, resourceImpl.getId());
+ ps.setLong(2, resourceImpl.getVersionNumber());
+ ResultSet results = ps.executeQuery();
+
+ while (results.next()) {
+ String name = results.getString("NAME");
+ String value = results.getString("VALUE");
+ resourceImpl.addProperty(name, value);
+ }
+
+ ps.close();
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to add properties to the resource " +
+ resourceImpl.getPath() + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ resourceImpl.setPropertiesModified(false);
+ }
+
+ private void fillChildren(ResourceImpl resourceImpl, long snapshotID) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ try {
+ //String sql = "SELECT R.RID, R.PATH FROM RESOURCE_VERSION R, DEPENDENCY_VERSION D " +
+ // "WHERE D.PARENT_RID=? AND PARENT_VERSION=? AND D.CHILD_RID=R.RID AND R.VERSION=?";
+
+ String sql = "SELECT CHILD_RID FROM DEPENDENCY_VERSION " +
+ "WHERE PARENT_RID=? AND PARENT_VERSION=?";
+
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setString(1, resourceImpl.getId());
+ ps.setLong(2, resourceImpl.getVersionNumber());
+
+ List <String> childPathList = new ArrayList();
+ ResultSet results = ps.executeQuery();
+ while (results.next()) {
+
+ String childID = results.getString("CHILD_RID");
+
+ String sql2 = "SELECT R.PATH FROM RESOURCE_VERSION R " +
+ "WHERE R.RID=? AND R.VERSION=(" +
+ "SELECT S.VERSION FROM SNAPSHOT_RESOURCE_VERSION S " +
+ "WHERE S.SNAPSHOT_ID=? AND S.RID=?)";
+
+ PreparedStatement ps2 = conn.prepareStatement(sql2);
+ ps2.setString(1, childID);
+ ps2.setLong(2, snapshotID);
+ ps2.setString(3, childID);
+
+ ResultSet result2 = ps2.executeQuery();
+ String path = "";
+ if (result2.next()) {
+ path = result2.getString("PATH");
+ }
+ ps2.close();
+
+ if (AuthorizationUtils.authorize(childID, ActionConstants.GET)) {
+ String childPath = path + ";version=" + snapshotID;
+ childPathList.add(childPath);
+ }
+ }
+ ps.close();
+
+ String[] childPaths = childPathList.toArray(new String[childPathList.size()]);
+ resourceImpl.setContent(childPaths);
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to get child paths of resource " +
+ resourceImpl.getPath() + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ private ResourceImpl getResource(String resourceID, long version) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ try {
+ String sql = "SELECT RID, PATH, MEDIA_TYPE, COLLECTION, CREATOR, CREATED_TIME, " +
+ "LAST_UPDATOR, LAST_UPDATED_TIME, DESCRIPTION, CONTENT_ID " +
+ "FROM RESOURCE_VERSION WHERE RID=? AND VERSION=?";
+
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setString(1, resourceID);
+ ps.setLong(2, version);
+
+ ResultSet result = ps.executeQuery();
+
+ ResourceImpl resourceImpl = null;
+
+ if (result.next()) {
+
+ if (result.getInt("COLLECTION") == 0) {
+ resourceImpl = new ResourceVersionImpl();
+ } else {
+ resourceImpl = new CollectionVersionImpl();
+ }
+
+ // this is always the current version of the resource
+ resourceImpl.setVersionNumber(version);
+
+ resourceImpl.setId(result.getString("RID"));
+ resourceImpl.setPath(result.getString("PATH"));
+ resourceImpl.setMediaType(result.getString("MEDIA_TYPE"));
+ resourceImpl.setAuthorUserName(result.getString("CREATOR"));
+ resourceImpl.setCreatedTime(result.getTimestamp("CREATED_TIME"));
+ resourceImpl.setLastUpdaterUserName(result.getString("LAST_UPDATOR"));
+ resourceImpl.setLastModified(result.getTimestamp("LAST_UPDATED_TIME"));
+ resourceImpl.setDescription(result.getString("DESCRIPTION"));
+ resourceImpl.setContentID(result.getString("CONTENT_ID"));
+ }
+
+ ps.close();
+
+ return resourceImpl;
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to get resource " + resourceID + ". " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ public String addContentVersion(InputStream contentStream) throws RegistryException {
+
+ Connection conn = Transaction.getConnection();
+
+ String contentID = null;
+
+ if (contentStream != null) {
+
+ // we should first write the content stream to a temporary file because JDBC
+ // needs the length of the binary stream.
+
+ File tempFile;
+ try {
+ tempFile = File.createTempFile("reg", "tmp");
+ OutputStream fileStream = new BufferedOutputStream(new FileOutputStream(tempFile));
+ InputStream bufferedIn = new BufferedInputStream(contentStream);
+
+ byte[] dataChunk = new byte[1024];
+ int byteCount;
+ while ((byteCount = bufferedIn.read(dataChunk)) != -1) {
+ fileStream.write(dataChunk, 0, byteCount);
+ }
+ fileStream.flush();
+ bufferedIn.close();
+ fileStream.close();
+
+ } catch (IOException e) {
+
+ String msg = "Failed to write the resource content to a temporary file, " +
+ "before writing to the database. " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ try {
+
+ contentID = UUID.randomUUID().toString();
+
+ InputStream tempFileStream = new BufferedInputStream(new FileInputStream(tempFile));
+ long contentLength = tempFile.length();
+
+ String sql = "INSERT INTO CONTENT_VERSION " +
+ "(CONTENT_VERSION_ID, CONTENT_DATA) VALUES (?, ?)";
+
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setString(1, contentID);
+ ps.setBinaryStream(2, tempFileStream, (int)contentLength);
+ ps.executeUpdate();
+ ps.close();
+
+ } catch (FileNotFoundException e) {
+ String msg = "Failed to read resource content from the temporary file. " +
+ e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+
+ } catch (SQLException e) {
+
+ String msg = "Failed to write resource content to the database. " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
+ return contentID;
+ }
+
+ public InputStream getResourceContentStream(String contentID, Connection conn)
+ throws RegistryException {
+
+ InputStream contentStream = null;
+
+ try {
+ String sql = "SELECT CONTENT_DATA FROM CONTENT_VERSION WHERE CONTENT_VERSION_ID=?";
+
+ PreparedStatement ps = conn.prepareStatement(sql);
+ ps.setString(1, contentID);
+
+ ResultSet result = ps.executeQuery();
+ if (result.next()) {
+ contentStream = getDisconnectedStream(result.getBinaryStream("CONTENT_DATA"));
+ }
+ ps.close();
+
+ } catch (SQLException e) {
+ String msg = "Faild to get resource content from the database. " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+
+ } catch (IOException e) {
+ String msg = "Failed to write resource content to a temporary file. " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ return contentStream;
+ }
+
+ private InputStream getDisconnectedStream(InputStream connectedStream) throws IOException {
+
+ if (connectedStream == null) {
+ return null;
+ }
+
+ File tempFile = File.createTempFile("reg", "tmp");
+ tempFile.deleteOnExit();
+
+ BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile));
+ byte[] contentChunk = new byte[1024];
+ int byteCount;
+ while ((byteCount = connectedStream.read(contentChunk)) != -1) {
+ out.write(contentChunk, 0, byteCount);
+ }
+ out.flush();
+ out.close();
+ connectedStream.close();
+
+ return new BufferedInputStream(new FileInputStream(tempFile));
+ }
+}
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/SnapshotDAO.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/SnapshotDAO.java Fri May 2 02:40:41 2008
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry.jdbc.dao;
+
+public class SnapshotDAO {
+
+}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/creators/DerbyDatabaseCreator.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/creators/DerbyDatabaseCreator.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/creators/DerbyDatabaseCreator.java Fri May 2 02:40:41 2008
@@ -32,6 +32,7 @@
"LAST_UPDATED_TIME TIMESTAMP," +
"DESCRIPTION VARCHAR (500)," +
"CONTENT_ID VARCHAR (50)," +
+ "EQUIVALENT_VERSION INTEGER NOT NULL," +
"PRIMARY KEY (RID)," +
"FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT (CONTENT_ID)," +
"UNIQUE(PATH))";
@@ -127,10 +128,12 @@
private static final String resourceVersionTable =
"CREATE TABLE RESOURCE_VERSION (" +
- "RID VARCHAR (50)," +
+ "RESOURCE_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY," +
+ "RID VARCHAR (50) NOT NULL," +
+ "VERSION INTEGER NOT NULL," +
"PATH VARCHAR (2000) NOT NULL," +
"MEDIA_TYPE VARCHAR (500)," +
- "DIRECTORY INTEGER NOT NULL," +
+ "COLLECTION INTEGER NOT NULL," +
"CREATOR VARCHAR (500)," +
"CREATED_TIME TIMESTAMP," +
"LAST_UPDATOR VARCHAR (500)," +
@@ -138,8 +141,8 @@
"DESCRIPTION VARCHAR (500)," +
"CONTENT_ID VARCHAR (50)," +
"FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT_VERSION (CONTENT_VERSION_ID)," +
- "PRIMARY KEY (RID)," +
- "UNIQUE(PATH))";
+ "PRIMARY KEY (RESOURCE_VERSION_ID)," +
+ "UNIQUE(RID, VERSION))";
private static final String dependencyVersionTable =
"CREATE TABLE DEPENDENCY_VERSION (" +
@@ -148,9 +151,7 @@
"PARENT_VERSION INTEGER NOT NULL," +
"CHILD_RID VARCHAR (50) NOT NULL," +
"PRIMARY KEY (DEPENDENCY_VERSION_ID)," +
- "UNIQUE (PARENT_RID, PARENT_VERSION, CHILD_RID)," +
- "FOREIGN KEY (PARENT_RID) REFERENCES RESOURCE_VERSION (RID)," +
- "FOREIGN KEY (CHILD_RID) REFERENCES RESOURCE_VERSION (RID))";
+ "UNIQUE (PARENT_RID, PARENT_VERSION, CHILD_RID))";
private static final String contentVersionTable =
"CREATE TABLE CONTENT_VERSION (" +
@@ -166,7 +167,7 @@
"NAME VARCHAR (100) NOT NULL," +
"VALUE VARCHAR (500)," +
"PRIMARY KEY (PROPERTY_VERSION_ID)," +
- "FOREIGN KEY (RID) REFERENCES RESOURCE_VERSION (RID))";
+ "FOREIGN KEY (RID, VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION))";
private static final String associationVersionTable =
"CREATE TABLE ASSOCIATION_VERSION (" +
@@ -178,8 +179,8 @@
"ASSOCIATION_TYPE VARCHAR (20) NOT NULL," +
"PRIMARY KEY (ASSOCIATION_VERSION_ID)," +
"UNIQUE (RID1, RID1_VERSION, RID2, RID2_VERSION, ASSOCIATION_TYPE)," +
- "FOREIGN KEY (RID1) REFERENCES RESOURCE_VERSION (RID)," +
- "FOREIGN KEY (RID2) REFERENCES RESOURCE_VERSION (RID))";
+ "FOREIGN KEY (RID1, RID1_VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION)," +
+ "FOREIGN KEY (RID2, RID2_VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION))";
//////////////////////////////////////////////////////////////////////////////////
// Tables related to snapshot management //
@@ -190,16 +191,15 @@
private static final String snapshotTable =
"CREATE TABLE SNAPSHOT (" +
- "SNAPSHOT_ID VARCHAR (50)," +
+ "SNAPSHOT_ID INTEGER GENERATED BY DEFAULT AS IDENTITY," +
"ROOT_ID VARCHAR (50) NOT NULL," +
- "ROOT_SNAPSHOT_NUMBER INTEGER NOT NULL," +
"PRIMARY KEY (SNAPSHOT_ID)," +
- "UNIQUE (ROOT_ID, ROOT_SNAPSHOT_NUMBER))";
+ "UNIQUE (SNAPSHOT_ID, ROOT_ID))";
private static final String snapshotResourceVersionTable =
"CREATE TABLE SNAPSHOT_RESOURCE_VERSION (" +
"SRV_ID INTEGER GENERATED ALWAYS AS IDENTITY," +
- "SNAPSHOT_ID VARCHAR (50) NOT NULL," +
+ "SNAPSHOT_ID INTEGER NOT NULL," +
"RID VARCHAR (50) NOT NULL," +
"VERSION INTEGER NOT NULL," +
"UNIQUE (SNAPSHOT_ID, RID, VERSION))";
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/creators/HSQLDatabaseCreator.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/creators/HSQLDatabaseCreator.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/utils/creators/HSQLDatabaseCreator.java Fri May 2 02:40:41 2008
@@ -35,6 +35,7 @@
"LAST_UPDATED_TIME TIMESTAMP," +
"DESCRIPTION VARCHAR (500)," +
"CONTENT_ID VARCHAR (50)," +
+ "EQUIVALENT_VERSION INTEGER NOT NULL," +
"PRIMARY KEY (RID)," +
"FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT (CONTENT_ID)," +
"UNIQUE(PATH));";
@@ -130,10 +131,12 @@
private static final String resourceVersionTable =
"CREATE TABLE RESOURCE_VERSION (" +
+ "RESOURCE_VERSION_ID INTEGER GENERATED BY DEFAULT AS IDENTITY," +
"RID VARCHAR (50)," +
+ "VERSION INTEGER NOT NULL," +
"PATH VARCHAR (2000) NOT NULL," +
"MEDIA_TYPE VARCHAR (500)," +
- "DIRECTORY INTEGER NOT NULL," +
+ "COLLECTION INTEGER NOT NULL," +
"CREATOR VARCHAR (500)," +
"CREATED_TIME TIMESTAMP," +
"LAST_UPDATOR VARCHAR (500)," +
@@ -141,8 +144,8 @@
"DESCRIPTION VARCHAR (500)," +
"CONTENT_ID VARCHAR (50)," +
"FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT_VERSION (CONTENT_VERSION_ID)," +
- "PRIMARY KEY (RID)," +
- "UNIQUE(PATH));";
+ "PRIMARY KEY (RESOURCE_VERSION_ID)," +
+ "UNIQUE (RID, VERSION))";
private static final String dependencyVersionTable =
"CREATE TABLE DEPENDENCY_VERSION (" +
@@ -151,9 +154,7 @@
"PARENT_VERSION INTEGER NOT NULL," +
"CHILD_RID VARCHAR (50) NOT NULL," +
"PRIMARY KEY (DEPENDENCY_VERSION_ID)," +
- "UNIQUE (PARENT_RID, PARENT_VERSION, CHILD_RID)," +
- "FOREIGN KEY (PARENT_RID) REFERENCES RESOURCE_VERSION (RID)," +
- "FOREIGN KEY (CHILD_RID) REFERENCES RESOURCE_VERSION (RID));";
+ "UNIQUE (PARENT_RID, PARENT_VERSION, CHILD_RID))";
private static final String contentVersionTable =
"CREATE TABLE CONTENT_VERSION (" +
@@ -169,7 +170,7 @@
"NAME VARCHAR (100) NOT NULL," +
"VALUE VARCHAR (500)," +
"PRIMARY KEY (PROPERTY_VERSION_ID)," +
- "FOREIGN KEY (RID) REFERENCES RESOURCE_VERSION (RID));";
+ "FOREIGN KEY (RID, VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION));";
private static final String associationVersionTable =
"CREATE TABLE ASSOCIATION_VERSION (" +
@@ -181,8 +182,8 @@
"ASSOCIATION_TYPE VARCHAR (20)," +
"PRIMARY KEY (ASSOCIATION_VERSION_ID)," +
"UNIQUE (RID1, RID1_VERSION, RID2, RID2_VERSION, ASSOCIATION_TYPE)," +
- "FOREIGN KEY (RID1) REFERENCES RESOURCE_VERSION (RID)," +
- "FOREIGN KEY (RID2) REFERENCES RESOURCE_VERSION (RID));";
+ "FOREIGN KEY (RID1, RID1_VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION)," +
+ "FOREIGN KEY (RID2, RID2_VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION));";
//////////////////////////////////////////////////////////////////////////////////
// Tables related to snapshot management //
@@ -193,16 +194,15 @@
private static final String snapshotTable =
"CREATE TABLE SNAPSHOT (" +
- "SNAPSHOT_ID VARCHAR (50)," +
+ "SNAPSHOT_ID INTEGER GENERATED BY DEFAULT AS IDENTITY," +
"ROOT_ID VARCHAR (50) NOT NULL," +
- "ROOT_SNAPSHOT_NUMBER INTEGER NOT NULL," +
"PRIMARY KEY (SNAPSHOT_ID)," +
- "UNIQUE (ROOT_ID, ROOT_SNAPSHOT_NUMBER));";
+ "UNIQUE (SNAPSHOT_ID, ROOT_ID));";
private static final String snapshotResourceVersionTable =
"CREATE TABLE SNAPSHOT_RESOURCE_VERSION (" +
"SRV_ID INTEGER GENERATED BY DEFAULT AS IDENTITY," +
- "SNAPSHOT_ID VARCHAR (50) NOT NULL," +
+ "SNAPSHOT_ID INTEGER NOT NULL," +
"RID VARCHAR (50) NOT NULL," +
"VERSION INTEGER NOT NULL," +
"UNIQUE (SNAPSHOT_ID, RID, VERSION));";
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/session/UserRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/session/UserRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/session/UserRegistry.java Fri May 2 02:40:41 2008
@@ -258,6 +258,14 @@
return coreRegistry.copy(sourcePath, targetPath);
}
+ public void createVersion(String path) throws RegistryException {
+
+ CurrentSession.setUser(userName);
+ CurrentSession.setRealm(userRealm);
+
+ coreRegistry.createVersion(path);
+ }
+
public String[] getVersions(String path) throws RegistryException {
CurrentSession.setUser(userName);
Modified: trunk/registry/modules/core/src/main/resources/database-scripts/derby-complete.sql
==============================================================================
--- trunk/registry/modules/core/src/main/resources/database-scripts/derby-complete.sql (original)
+++ trunk/registry/modules/core/src/main/resources/database-scripts/derby-complete.sql Fri May 2 02:40:41 2008
@@ -1,148 +1,148 @@
CREATE TABLE CONTENT (
- CONTENT_ID VARCHAR (50),
- CONTENT_DATA BLOB,
- PRIMARY KEY (CONTENT_ID));
-
+ CONTENT_ID VARCHAR (50),
+ CONTENT_DATA BLOB,
+ PRIMARY KEY (CONTENT_ID));
+
CREATE TABLE RESOURCE (
- RID VARCHAR (50),
- PATH VARCHAR (2000) NOT NULL,
- MEDIA_TYPE VARCHAR (500),
- COLLECTION INTEGER NOT NULL,
- CREATOR VARCHAR (500),
- CREATED_TIME TIMESTAMP,
- LAST_UPDATOR VARCHAR (500),
- LAST_UPDATED_TIME TIMESTAMP,
- DESCRIPTION VARCHAR (500),
- CONTENT_ID VARCHAR (50),
- PRIMARY KEY (RID),
- FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT (CONTENT_ID),
- UNIQUE(PATH));
+ RID VARCHAR (50),
+ PATH VARCHAR (2000) NOT NULL,
+ MEDIA_TYPE VARCHAR (500),
+ COLLECTION INTEGER NOT NULL,
+ CREATOR VARCHAR (500),
+ CREATED_TIME TIMESTAMP,
+ LAST_UPDATOR VARCHAR (500),
+ LAST_UPDATED_TIME TIMESTAMP,
+ DESCRIPTION VARCHAR (500),
+ CONTENT_ID VARCHAR (50),
+ EQUIVALENT_VERSION INTEGER NOT NULL,
+ PRIMARY KEY (RID),
+ FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT (CONTENT_ID),
+ UNIQUE(PATH));
CREATE TABLE DEPENDENCY (
- DEPENDENCY_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- PARENT_RID VARCHAR (50) NOT NULL,
- CHILD_RID VARCHAR (50) NOT NULL,
- PRIMARY KEY (DEPENDENCY_ID),
- UNIQUE (PARENT_RID, CHILD_RID),
- FOREIGN KEY (PARENT_RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE,
- FOREIGN KEY (CHILD_RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
+ DEPENDENCY_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ PARENT_RID VARCHAR (50) NOT NULL,
+ CHILD_RID VARCHAR (50) NOT NULL,
+ PRIMARY KEY (DEPENDENCY_ID),
+ UNIQUE (PARENT_RID, CHILD_RID),
+ FOREIGN KEY (PARENT_RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE,
+ FOREIGN KEY (CHILD_RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
CREATE TABLE PROPERTY (
- PROPERTY_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID VARCHAR (50) NOT NULL,
- NAME VARCHAR (100) NOT NULL,
- VALUE VARCHAR (500),
- PRIMARY KEY (PROPERTY_ID),
- FOREIGN KEY (RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
-
+ PROPERTY_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID VARCHAR (50) NOT NULL,
+ NAME VARCHAR (100) NOT NULL,
+ VALUE VARCHAR (500),
+ PRIMARY KEY (PROPERTY_ID),
+ FOREIGN KEY (RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
+
CREATE TABLE ASSOCIATION (
- ASSOCIATION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID1 VARCHAR (50) NOT NULL,
- RID2 VARCHAR (50) NOT NULL,
- ASSOCIATION_TYPE VARCHAR (20) NOT NULL,
- UNIQUE (RID1, RID2, ASSOCIATION_TYPE),
- FOREIGN KEY (RID1) REFERENCES RESOURCE (RID) ON DELETE CASCADE,
- FOREIGN KEY (RID2) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
+ ASSOCIATION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID1 VARCHAR (50) NOT NULL,
+ RID2 VARCHAR (50) NOT NULL,
+ ASSOCIATION_TYPE VARCHAR (20) NOT NULL,
+ UNIQUE (RID1, RID2, ASSOCIATION_TYPE),
+ FOREIGN KEY (RID1) REFERENCES RESOURCE (RID) ON DELETE CASCADE,
+ FOREIGN KEY (RID2) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
CREATE TABLE TAG (
- TAG_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- TAG_NAME VARCHAR (500) NOT NULL,
- RID VARCHAR (50) NOT NULL,
- USER_ID VARCHAR (20) NOT NULL,
- TAGGED_TIME TIMESTAMP NOT NULL,
- PRIMARY KEY (TAG_ID),
- UNIQUE (TAG_NAME, RID, USER_ID));
+ TAG_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ TAG_NAME VARCHAR (500) NOT NULL,
+ RID VARCHAR (50) NOT NULL,
+ USER_ID VARCHAR (20) NOT NULL,
+ TAGGED_TIME TIMESTAMP NOT NULL,
+ PRIMARY KEY (TAG_ID),
+ UNIQUE (TAG_NAME, RID, USER_ID));
CREATE TABLE COMMENT (
- COMMENT_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID VARCHAR (50) NOT NULL,
- USER_ID VARCHAR (20) NOT NULL,
- COMMENT_TEXT VARCHAR (500) NOT NULL,
- COMMENTED_TIME TIMESTAMP NOT NULL,
- PRIMARY KEY (COMMENT_ID));
+ COMMENT_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID VARCHAR (50) NOT NULL,
+ USER_ID VARCHAR (20) NOT NULL,
+ COMMENT_TEXT VARCHAR (500) NOT NULL,
+ COMMENTED_TIME TIMESTAMP NOT NULL,
+ PRIMARY KEY (COMMENT_ID));
CREATE TABLE RATING (
- RATING_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID VARCHAR (50) NOT NULL,
- USER_ID VARCHAR (20) NOT NULL,
- RATING INTEGER NOT NULL,
- RATED_TIME TIMESTAMP NOT NULL,
- PRIMARY KEY (RATING_ID));
+ RATING_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID VARCHAR (50) NOT NULL,
+ USER_ID VARCHAR (20) NOT NULL,
+ RATING INTEGER NOT NULL,
+ RATED_TIME TIMESTAMP NOT NULL,
+ PRIMARY KEY (RATING_ID));
CREATE TABLE LOG (
- LOG_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- PATH VARCHAR (2000),
- USER_ID VARCHAR (20) NOT NULL,
- LOGGED_TIME TIMESTAMP NOT NULL,
- ACTION INTEGER NOT NULL,
- ACTION_DATA VARCHAR (500),
- PRIMARY KEY (LOG_ID));
+ LOG_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ PATH VARCHAR (2000),
+ USER_ID VARCHAR (20) NOT NULL,
+ LOGGED_TIME TIMESTAMP NOT NULL,
+ ACTION INTEGER NOT NULL,
+ ACTION_DATA VARCHAR (500),
+ PRIMARY KEY (LOG_ID));
CREATE TABLE CONTENT_VERSION (
- CONTENT_VERSION_ID VARCHAR (50),
- CONTENT_DATA BLOB,
- PRIMARY KEY (CONTENT_VERSION_ID));
+ CONTENT_VERSION_ID VARCHAR (50),
+ CONTENT_DATA BLOB,
+ PRIMARY KEY (CONTENT_VERSION_ID));
CREATE TABLE RESOURCE_VERSION (
- RID VARCHAR (50),
- PATH VARCHAR (2000) NOT NULL,
- MEDIA_TYPE VARCHAR (500),
- DIRECTORY INTEGER NOT NULL,
- CREATOR VARCHAR (500),
- CREATED_TIME TIMESTAMP,
- LAST_UPDATOR VARCHAR (500),
- LAST_UPDATED_TIME TIMESTAMP,
- DESCRIPTION VARCHAR (500),
- CONTENT_ID VARCHAR (50),
- FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT_VERSION (CONTENT_VERSION_ID),
- PRIMARY KEY (RID),
- UNIQUE(PATH));
+ RESOURCE_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID VARCHAR (50) NOT NULL,
+ VERSION INTEGER NOT NULL,
+ PATH VARCHAR (2000) NOT NULL,
+ MEDIA_TYPE VARCHAR (500),
+ COLLECTION INTEGER NOT NULL,
+ CREATOR VARCHAR (500),
+ CREATED_TIME TIMESTAMP,
+ LAST_UPDATOR VARCHAR (500),
+ LAST_UPDATED_TIME TIMESTAMP,
+ DESCRIPTION VARCHAR (500),
+ CONTENT_ID VARCHAR (50),
+ FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT_VERSION (CONTENT_VERSION_ID),
+ PRIMARY KEY (RESOURCE_VERSION_ID),
+ UNIQUE(RID, VERSION));
CREATE TABLE DEPENDENCY_VERSION (
- DEPENDENCY_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- PARENT_RID VARCHAR (50) NOT NULL,
- PARENT_VERSION INTEGER NOT NULL,
- CHILD_RID VARCHAR (50) NOT NULL,
- PRIMARY KEY (DEPENDENCY_VERSION_ID),
- UNIQUE (PARENT_RID, PARENT_VERSION, CHILD_RID),
- FOREIGN KEY (PARENT_RID) REFERENCES RESOURCE_VERSION (RID),
- FOREIGN KEY (CHILD_RID) REFERENCES RESOURCE_VERSION (RID));
+ DEPENDENCY_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ PARENT_RID VARCHAR (50) NOT NULL,
+ PARENT_VERSION INTEGER NOT NULL,
+ CHILD_RID VARCHAR (50) NOT NULL,
+ PRIMARY KEY (DEPENDENCY_VERSION_ID),
+ UNIQUE (PARENT_RID, PARENT_VERSION, CHILD_RID));
CREATE TABLE PROPERTY_VERSION (
- PROPERTY_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID VARCHAR (50) NOT NULL,
- VERSION INTEGER NOT NULL,
- NAME VARCHAR (100) NOT NULL,
- VALUE VARCHAR (500),
- PRIMARY KEY (PROPERTY_VERSION_ID),
- FOREIGN KEY (RID) REFERENCES RESOURCE_VERSION (RID));
+ PROPERTY_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID VARCHAR (50) NOT NULL,
+ VERSION INTEGER NOT NULL,
+ NAME VARCHAR (100) NOT NULL,
+ VALUE VARCHAR (500),
+ PRIMARY KEY (PROPERTY_VERSION_ID),
+ FOREIGN KEY (RID, VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION));
CREATE TABLE ASSOCIATION_VERSION (
- ASSOCIATION_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID1 VARCHAR (50) NOT NULL,
- RID1_VERSION INTEGER NOT NULL,
- RID2 VARCHAR (50) NOT NULL,
- RID2_VERSION INTEGER NOT NULL,
- ASSOCIATION_TYPE VARCHAR (20) NOT NULL,
- PRIMARY KEY (ASSOCIATION_VERSION_ID),
- UNIQUE (RID1, RID1_VERSION, RID2, RID2_VERSION, ASSOCIATION_TYPE),
- FOREIGN KEY (RID1) REFERENCES RESOURCE_VERSION (RID),
- FOREIGN KEY (RID2) REFERENCES RESOURCE_VERSION (RID));
+ ASSOCIATION_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID1 VARCHAR (50) NOT NULL,
+ RID1_VERSION INTEGER NOT NULL,
+ RID2 VARCHAR (50) NOT NULL,
+ RID2_VERSION INTEGER NOT NULL,
+ ASSOCIATION_TYPE VARCHAR (20) NOT NULL,
+ PRIMARY KEY (ASSOCIATION_VERSION_ID),
+ UNIQUE (RID1, RID1_VERSION, RID2, RID2_VERSION, ASSOCIATION_TYPE),
+ FOREIGN KEY (RID1, RID1_VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION),
+ FOREIGN KEY (RID2, RID2_VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION));
CREATE TABLE SNAPSHOT (
- SNAPSHOT_ID VARCHAR (50),
- ROOT_ID VARCHAR (50) NOT NULL,
- ROOT_SNAPSHOT_NUMBER INTEGER NOT NULL,
- PRIMARY KEY (SNAPSHOT_ID),
- UNIQUE (ROOT_ID, ROOT_SNAPSHOT_NUMBER));
+ SNAPSHOT_ID INTEGER GENERATED BY DEFAULT AS IDENTITY,
+ ROOT_ID VARCHAR (50) NOT NULL,
+ PRIMARY KEY (SNAPSHOT_ID),
+ UNIQUE (SNAPSHOT_ID, ROOT_ID));
CREATE TABLE SNAPSHOT_RESOURCE_VERSION (
- SRV_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- SNAPSHOT_ID VARCHAR (50) NOT NULL,
- RID VARCHAR (50) NOT NULL,
- VERSION INTEGER NOT NULL,
- UNIQUE (SNAPSHOT_ID, RID, VERSION));
+ SRV_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ SNAPSHOT_ID INTEGER NOT NULL,
+ RID VARCHAR (50) NOT NULL,
+ VERSION INTEGER NOT NULL,
+ UNIQUE (SNAPSHOT_ID, RID, VERSION));
CREATE TABLE UM_USERS (
ID INTEGER GENERATED ALWAYS AS IDENTITY,
Modified: trunk/registry/modules/core/src/main/resources/database-scripts/derby-registry.sql
==============================================================================
--- trunk/registry/modules/core/src/main/resources/database-scripts/derby-registry.sql (original)
+++ trunk/registry/modules/core/src/main/resources/database-scripts/derby-registry.sql Fri May 2 02:40:41 2008
@@ -1,145 +1,145 @@
CREATE TABLE CONTENT (
- CONTENT_ID VARCHAR (50),
- CONTENT_DATA BLOB,
- PRIMARY KEY (CONTENT_ID));
+ CONTENT_ID VARCHAR (50),
+ CONTENT_DATA BLOB,
+ PRIMARY KEY (CONTENT_ID));
CREATE TABLE RESOURCE (
- RID VARCHAR (50),
- PATH VARCHAR (2000) NOT NULL,
- MEDIA_TYPE VARCHAR (500),
- COLLECTION INTEGER NOT NULL,
- CREATOR VARCHAR (500),
- CREATED_TIME TIMESTAMP,
- LAST_UPDATOR VARCHAR (500),
- LAST_UPDATED_TIME TIMESTAMP,
- DESCRIPTION VARCHAR (500),
- CONTENT_ID VARCHAR (50),
- PRIMARY KEY (RID),
- FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT (CONTENT_ID),
- UNIQUE(PATH));
+ RID VARCHAR (50),
+ PATH VARCHAR (2000) NOT NULL,
+ MEDIA_TYPE VARCHAR (500),
+ COLLECTION INTEGER NOT NULL,
+ CREATOR VARCHAR (500),
+ CREATED_TIME TIMESTAMP,
+ LAST_UPDATOR VARCHAR (500),
+ LAST_UPDATED_TIME TIMESTAMP,
+ DESCRIPTION VARCHAR (500),
+ CONTENT_ID VARCHAR (50),
+ EQUIVALENT_VERSION INTEGER NOT NULL,
+ PRIMARY KEY (RID),
+ FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT (CONTENT_ID),
+ UNIQUE(PATH));
CREATE TABLE DEPENDENCY (
- DEPENDENCY_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- PARENT_RID VARCHAR (50) NOT NULL,
- CHILD_RID VARCHAR (50) NOT NULL,
- PRIMARY KEY (DEPENDENCY_ID),
- UNIQUE (PARENT_RID, CHILD_RID),
- FOREIGN KEY (PARENT_RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE,
- FOREIGN KEY (CHILD_RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
+ DEPENDENCY_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ PARENT_RID VARCHAR (50) NOT NULL,
+ CHILD_RID VARCHAR (50) NOT NULL,
+ PRIMARY KEY (DEPENDENCY_ID),
+ UNIQUE (PARENT_RID, CHILD_RID),
+ FOREIGN KEY (PARENT_RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE,
+ FOREIGN KEY (CHILD_RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
CREATE TABLE PROPERTY (
- PROPERTY_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID VARCHAR (50) NOT NULL,
- NAME VARCHAR (100) NOT NULL,
- VALUE VARCHAR (500),
- PRIMARY KEY (PROPERTY_ID),
- FOREIGN KEY (RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
+ PROPERTY_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID VARCHAR (50) NOT NULL,
+ NAME VARCHAR (100) NOT NULL,
+ VALUE VARCHAR (500),
+ PRIMARY KEY (PROPERTY_ID),
+ FOREIGN KEY (RID) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
CREATE TABLE ASSOCIATION (
- ASSOCIATION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID1 VARCHAR (50) NOT NULL,
- RID2 VARCHAR (50) NOT NULL,
- ASSOCIATION_TYPE VARCHAR (20) NOT NULL,
- UNIQUE (RID1, RID2, ASSOCIATION_TYPE),
- FOREIGN KEY (RID1) REFERENCES RESOURCE (RID) ON DELETE CASCADE,
- FOREIGN KEY (RID2) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
+ ASSOCIATION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID1 VARCHAR (50) NOT NULL,
+ RID2 VARCHAR (50) NOT NULL,
+ ASSOCIATION_TYPE VARCHAR (20) NOT NULL,
+ UNIQUE (RID1, RID2, ASSOCIATION_TYPE),
+ FOREIGN KEY (RID1) REFERENCES RESOURCE (RID) ON DELETE CASCADE,
+ FOREIGN KEY (RID2) REFERENCES RESOURCE (RID) ON DELETE CASCADE);
CREATE TABLE TAG (
- TAG_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- TAG_NAME VARCHAR (500) NOT NULL,
- RID VARCHAR (50) NOT NULL,
- USER_ID VARCHAR (20) NOT NULL,
- TAGGED_TIME TIMESTAMP NOT NULL,
- PRIMARY KEY (TAG_ID),
- UNIQUE (TAG_NAME, RID, USER_ID));
+ TAG_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ TAG_NAME VARCHAR (500) NOT NULL,
+ RID VARCHAR (50) NOT NULL,
+ USER_ID VARCHAR (20) NOT NULL,
+ TAGGED_TIME TIMESTAMP NOT NULL,
+ PRIMARY KEY (TAG_ID),
+ UNIQUE (TAG_NAME, RID, USER_ID));
CREATE TABLE COMMENT (
- COMMENT_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID VARCHAR (50) NOT NULL,
- USER_ID VARCHAR (20) NOT NULL,
- COMMENT_TEXT VARCHAR (500) NOT NULL,
- COMMENTED_TIME TIMESTAMP NOT NULL,
- PRIMARY KEY (COMMENT_ID));
+ COMMENT_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID VARCHAR (50) NOT NULL,
+ USER_ID VARCHAR (20) NOT NULL,
+ COMMENT_TEXT VARCHAR (500) NOT NULL,
+ COMMENTED_TIME TIMESTAMP NOT NULL,
+ PRIMARY KEY (COMMENT_ID));
CREATE TABLE RATING (
- RATING_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID VARCHAR (50) NOT NULL,
- USER_ID VARCHAR (20) NOT NULL,
- RATING INTEGER NOT NULL,
- RATED_TIME TIMESTAMP NOT NULL,
- PRIMARY KEY (RATING_ID));
+ RATING_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID VARCHAR (50) NOT NULL,
+ USER_ID VARCHAR (20) NOT NULL,
+ RATING INTEGER NOT NULL,
+ RATED_TIME TIMESTAMP NOT NULL,
+ PRIMARY KEY (RATING_ID));
CREATE TABLE LOG (
- LOG_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- PATH VARCHAR (2000),
- USER_ID VARCHAR (20) NOT NULL,
- LOGGED_TIME TIMESTAMP NOT NULL,
- ACTION INTEGER NOT NULL,
- ACTION_DATA VARCHAR (500),
- PRIMARY KEY (LOG_ID));
+ LOG_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ PATH VARCHAR (2000),
+ USER_ID VARCHAR (20) NOT NULL,
+ LOGGED_TIME TIMESTAMP NOT NULL,
+ ACTION INTEGER NOT NULL,
+ ACTION_DATA VARCHAR (500),
+ PRIMARY KEY (LOG_ID));
CREATE TABLE CONTENT_VERSION (
- CONTENT_VERSION_ID VARCHAR (50),
- CONTENT_DATA BLOB,
- PRIMARY KEY (CONTENT_VERSION_ID));
+ CONTENT_VERSION_ID VARCHAR (50),
+ CONTENT_DATA BLOB,
+ PRIMARY KEY (CONTENT_VERSION_ID));
CREATE TABLE RESOURCE_VERSION (
- RID VARCHAR (50),
- PATH VARCHAR (2000) NOT NULL,
- MEDIA_TYPE VARCHAR (500),
- DIRECTORY INTEGER NOT NULL,
- CREATOR VARCHAR (500),
- CREATED_TIME TIMESTAMP,
- LAST_UPDATOR VARCHAR (500),
- LAST_UPDATED_TIME TIMESTAMP,
- DESCRIPTION VARCHAR (500),
- CONTENT_ID VARCHAR (50),
- FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT_VERSION (CONTENT_VERSION_ID),
- PRIMARY KEY (RID),
- UNIQUE(PATH));
+ RESOURCE_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID VARCHAR (50) NOT NULL,
+ VERSION INTEGER NOT NULL,
+ PATH VARCHAR (2000) NOT NULL,
+ MEDIA_TYPE VARCHAR (500),
+ COLLECTION INTEGER NOT NULL,
+ CREATOR VARCHAR (500),
+ CREATED_TIME TIMESTAMP,
+ LAST_UPDATOR VARCHAR (500),
+ LAST_UPDATED_TIME TIMESTAMP,
+ DESCRIPTION VARCHAR (500),
+ CONTENT_ID VARCHAR (50),
+ FOREIGN KEY (CONTENT_ID) REFERENCES CONTENT_VERSION (CONTENT_VERSION_ID),
+ PRIMARY KEY (RESOURCE_VERSION_ID),
+ UNIQUE(RID, VERSION));
CREATE TABLE DEPENDENCY_VERSION (
- DEPENDENCY_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- PARENT_RID VARCHAR (50) NOT NULL,
- PARENT_VERSION INTEGER NOT NULL,
- CHILD_RID VARCHAR (50) NOT NULL,
- PRIMARY KEY (DEPENDENCY_VERSION_ID),
- UNIQUE (PARENT_RID, PARENT_VERSION, CHILD_RID),
- FOREIGN KEY (PARENT_RID) REFERENCES RESOURCE_VERSION (RID),
- FOREIGN KEY (CHILD_RID) REFERENCES RESOURCE_VERSION (RID));
+ DEPENDENCY_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ PARENT_RID VARCHAR (50) NOT NULL,
+ PARENT_VERSION INTEGER NOT NULL,
+ CHILD_RID VARCHAR (50) NOT NULL,
+ PRIMARY KEY (DEPENDENCY_VERSION_ID),
+ UNIQUE (PARENT_RID, PARENT_VERSION, CHILD_RID));
CREATE TABLE PROPERTY_VERSION (
- PROPERTY_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID VARCHAR (50) NOT NULL,
- VERSION INTEGER NOT NULL,
- NAME VARCHAR (100) NOT NULL,
- VALUE VARCHAR (500),
- PRIMARY KEY (PROPERTY_VERSION_ID),
- FOREIGN KEY (RID) REFERENCES RESOURCE_VERSION (RID));
+ PROPERTY_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID VARCHAR (50) NOT NULL,
+ VERSION INTEGER NOT NULL,
+ NAME VARCHAR (100) NOT NULL,
+ VALUE VARCHAR (500),
+ PRIMARY KEY (PROPERTY_VERSION_ID),
+ FOREIGN KEY (RID, VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION));
CREATE TABLE ASSOCIATION_VERSION (
- ASSOCIATION_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- RID1 VARCHAR (50) NOT NULL,
- RID1_VERSION INTEGER NOT NULL,
- RID2 VARCHAR (50) NOT NULL,
- RID2_VERSION INTEGER NOT NULL,
- ASSOCIATION_TYPE VARCHAR (20) NOT NULL,
- PRIMARY KEY (ASSOCIATION_VERSION_ID),
- UNIQUE (RID1, RID1_VERSION, RID2, RID2_VERSION, ASSOCIATION_TYPE),
- FOREIGN KEY (RID1) REFERENCES RESOURCE_VERSION (RID),
- FOREIGN KEY (RID2) REFERENCES RESOURCE_VERSION (RID));
+ ASSOCIATION_VERSION_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ RID1 VARCHAR (50) NOT NULL,
+ RID1_VERSION INTEGER NOT NULL,
+ RID2 VARCHAR (50) NOT NULL,
+ RID2_VERSION INTEGER NOT NULL,
+ ASSOCIATION_TYPE VARCHAR (20) NOT NULL,
+ PRIMARY KEY (ASSOCIATION_VERSION_ID),
+ UNIQUE (RID1, RID1_VERSION, RID2, RID2_VERSION, ASSOCIATION_TYPE),
+ FOREIGN KEY (RID1, RID1_VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION),
+ FOREIGN KEY (RID2, RID2_VERSION) REFERENCES RESOURCE_VERSION (RID, VERSION));
CREATE TABLE SNAPSHOT (
- SNAPSHOT_ID VARCHAR (50),
- ROOT_ID VARCHAR (50) NOT NULL,
- ROOT_SNAPSHOT_NUMBER INTEGER NOT NULL,
- PRIMARY KEY (SNAPSHOT_ID),
- UNIQUE (ROOT_ID, ROOT_SNAPSHOT_NUMBER));
+ SNAPSHOT_ID INTEGER GENERATED BY DEFAULT AS IDENTITY,
+ ROOT_ID VARCHAR (50) NOT NULL,
+ PRIMARY KEY (SNAPSHOT_ID),
+ UNIQUE (SNAPSHOT_ID, ROOT_ID));
CREATE TABLE SNAPSHOT_RESOURCE_VERSION (
- SRV_ID INTEGER GENERATED ALWAYS AS IDENTITY,
- SNAPSHOT_ID VARCHAR (50) NOT NULL,
- RID VARCHAR (50) NOT NULL,
- VERSION INTEGER NOT NULL,
- UNIQUE (SNAPSHOT_ID, RID, VERSION));
\ No newline at end of file
+ SRV_ID INTEGER GENERATED ALWAYS AS IDENTITY,
+ SNAPSHOT_ID INTEGER NOT NULL,
+ RID VARCHAR (50) NOT NULL,
+ VERSION INTEGER NOT NULL,
+ UNIQUE (SNAPSHOT_ID, RID, VERSION));
\ No newline at end of file
Modified: trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
==============================================================================
--- trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java (original)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java Fri May 2 02:40:41 2008
@@ -175,9 +175,9 @@
String[] versionPaths = registry.getVersions("/r5");
- Resource v1 = registry.get(versionPaths[2]);
+ Resource v1 = registry.get(versionPaths[0]);
Resource v2 = registry.get(versionPaths[1]);
- Resource v3 = registry.get(versionPaths[0]);
+ Resource v3 = registry.get(versionPaths[2]);
String content1 = new String((byte[])v1.getContent());
String content2 = new String((byte[])v2.getContent());
Modified: trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/MoveTest.java
==============================================================================
--- trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/MoveTest.java (original)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/MoveTest.java Fri May 2 02:40:41 2008
@@ -18,6 +18,9 @@
import junit.framework.TestCase;
import org.wso2.registry.*;
+import org.wso2.registry.users.UserRealm;
+import org.wso2.registry.users.UserStoreException;
+import org.wso2.registry.session.UserRegistry;
import org.wso2.registry.jdbc.realm.RegistryRealm;
public class MoveTest extends TestCase {
Modified: trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/VersionHandlingTest.java
==============================================================================
--- trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/VersionHandlingTest.java (original)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/VersionHandlingTest.java Fri May 2 02:40:41 2008
@@ -20,15 +20,137 @@
package org.wso2.registry.jdbc;
import junit.framework.TestCase;
-import org.wso2.registry.Registry;
-import org.wso2.registry.RegistryException;
-import org.wso2.registry.Resource;
-import org.wso2.registry.Collection;
+import org.wso2.registry.*;
import org.wso2.registry.jdbc.realm.InMemoryRegistryRealm;
import org.wso2.registry.jdbc.realm.RegistryRealm;
+import org.wso2.registry.jdbc.utils.RegistryDataSource;
+
+import javax.sql.DataSource;
public class VersionHandlingTest extends TestCase {
+ protected static EmbeddedRegistry embeddedRegistry = null;
+ protected static Registry registry = null;
+ protected static RegistryRealm realm = null;
+
+ public void setUp() throws RegistryException {
+ if (registry == null) {
+ DataSource dataSource = new RegistryDataSource(
+ "jdbc:derby://localhost:1527//home/chathura/test/version/db1;create=true",
+ "org.apache.derby.jdbc.ClientDriver", "admin", "admin");
+ //embeddedRegistry = new EmbeddedRegistry(dataSource);
+ embeddedRegistry = new InMemoryEmbeddedRegistry();
+ registry = embeddedRegistry.getUserRegistry(
+ RegistryConstants.ADMIN_USER, RegistryConstants.ADMIN_PASSWORD);
+ }
+ }
+
+ public void testCreateVersions() throws RegistryException {
+
+ Resource r1 = registry.newResource();
+ r1.setContent("some content");
+ registry.put("/version/r1", r1);
+
+ //registry.createVersion("/version/r1");
+
+ String[] r1Versions = registry.getVersions("/version/r1");
+
+ assertEquals("/version/r1 should have 1 version.", r1Versions.length, 1);
+
+ Resource r1v2 = registry.get("/version/r1");
+ r1v2.setContent("another content");
+ registry.put("/version/r1", r1v2);
+
+ //registry.createVersion("/version/r1");
+
+ r1Versions = registry.getVersions("/version/r1");
+ assertEquals("/version/r1 should have 2 version.", r1Versions.length, 2);
+ }
+
+ public void testResourceContentVersioning() throws RegistryException {
+
+ Resource r1 = registry.newResource();
+ r1.setContent("content 1");
+ registry.put("/v2/r1", r1);
+
+ Resource r12 = registry.get("/v2/r1");
+ r12.setContent("content 2");
+ registry.put("/v2/r1", r12);
+
+ String[] r1Versions = registry.getVersions("/v2/r1");
+
+ Resource r1vv1 = registry.get(r1Versions[0]);
+
+ assertEquals("r1's first version's content should be 'content 1'",
+ new String((byte[]) r1vv1.getContent()), "content 1");
+
+ Resource r1vv2 = registry.get(r1Versions[1]);
+
+ assertEquals("r1's second version's content should be 'content 2'",
+ new String((byte[]) r1vv2.getContent()), "content 2");
+ }
+
+ public void testResourcePropertyVersioning() throws RegistryException {
+
+ Resource r1 = registry.newResource();
+ r1.setContent("content 1");
+ r1.addProperty("p1", "v1");
+ registry.put("/v2/r1", r1);
+
+ Resource r1v2 = registry.get("/v2/r1");
+ r1v2.addProperty("p2", "v2");
+ registry.put("/v2/r1", r1v2);
+
+ String[] r1Versions = registry.getVersions("/v2/r1");
+
+ Resource r1vv1 = registry.get(r1Versions[0]);
+
+ assertEquals("r1's first version should contain a property p1 with value v1",
+ r1vv1.getProperty("p1"), "v1");
+
+ Resource r1vv2 = registry.get(r1Versions[1]);
+
+ assertEquals("r1's second version should contain a property p1 with value v1",
+ r1vv2.getProperty("p1"), "v1");
+
+ assertEquals("r1's second version should contain a property p2 with value v2",
+ r1vv2.getProperty("p2"), "v2");
+ }
+
+ public void testSimpleCollectionVersioning() throws RegistryException {
+
+ Collection c1 = registry.newCollection();
+ registry.put("/v3/c1", c1);
+
+ registry.createVersion("/v3/c1");
+
+ Collection c2 = registry.newCollection();
+ registry.put("/v3/c1/c2", c2);
+
+ registry.createVersion("/v3/c1");
+
+ Collection c3 = registry.newCollection();
+ registry.put("/v3/c1/c3", c3);
+
+ registry.createVersion("/v3/c1");
+
+ Collection c4 = registry.newCollection();
+ registry.put("/v3/c1/c2/c4", c4);
+
+ registry.createVersion("/v3/c1");
+
+ Collection c5 = registry.newCollection();
+ registry.put("/v3/c1/c2/c5", c5);
+
+ registry.createVersion("/v3/c1");
+
+ String[] c1Versions = registry.getVersions("/v3/c1");
+
+ Collection c1v1 = (Collection) registry.get(c1Versions[0]);
+ Collection c1v2 = (Collection) registry.get(c1Versions[1]);
+ Collection c1v3 = (Collection) registry.get(c1Versions[2]);
+ }
+
//protected static Registry registry = null;
//
//public void setUp() {
More information about the Registry-dev
mailing list