org.wso2.registry.jdbc.dao
Class VersionedResourceDAO

java.lang.Object
  extended by org.wso2.registry.jdbc.dao.VersionedResourceDAO

public class VersionedResourceDAO
extends java.lang.Object


Constructor Summary
VersionedResourceDAO(javax.sql.DataSource dataSource)
           
 
Method Summary
 void add(ResourceImpl resource, java.sql.Connection conn)
          Adds the given resource to the database.
 void addDependencies(long resourceID, long version, DependencyChain[] dependencies, java.sql.Connection conn)
          Adds dependencies to the given version of a resource.
 void addDependencies(long resourceID, long version, java.lang.String[] dependencyPaths, java.sql.Connection conn)
          Adds dependencyPaths to the given version of a resource.
 void addProperties(long resourceID, java.util.Properties props, java.sql.Connection conn)
           
 long addResourceVersion(ResourceImpl resource, java.sql.Connection connection)
           
static byte[] convertToBytes(java.lang.Object object)
           
 void deleteResource(ResourceImpl resource, java.sql.Connection connection)
          To delete a resource , what actually happen here is that update the version table with the new data and resource will not actually removed from the table
 ResourceImpl get(java.lang.String path, long versionNumber, java.sql.Connection conn)
          Returns the given version of the artifact.
 java.lang.String[] getChildPaths(long artifcatID, long versionNumber, java.sql.Connection connection)
           
 java.util.List getChildren(long resourceID, long versionNumber, java.sql.Connection connection)
           
 long getCurrentVersionNumber(java.lang.String path, java.sql.Connection conn)
          To get the current version for a give resource , current version may not be the latest version in all the cases.
 DependencyChain[] getDependencies(java.lang.String resourcePath, java.sql.Connection conn)
           
 DependentChain[] getDependents(java.lang.String resourcePath, java.sql.Connection conn)
           
 java.lang.String[] getLatestChildPaths(long resourceID, long versionNumber, java.sql.Connection connection)
           
 ResourceImpl getLatestVersion(java.lang.String path, java.sql.Connection conn)
          Returns the latest (current) version of an artifact.
 long getLatestVersionNumber(long resourceId, java.sql.Connection connection)
           
 java.lang.String getParentPath(long resourceID, long versionNumber, java.sql.Connection connection)
           
 ResourceImpl getResourceByID(long artifactID, long versionNumber, java.sql.Connection conn)
           
 java.io.InputStream getResourceContentStream(long resourceID, long versionNumber, java.sql.Connection conn)
           
 long getResourceID(java.lang.String path, java.sql.Connection conn)
           
 java.lang.String getResourcePath(long id, java.sql.Connection conn)
           
 java.lang.String[] getVersionNumbers(long resourceId, java.sql.Connection connection)
           
 boolean isResourceActive(java.lang.String resourcePath, java.sql.Connection connection)
          This method is use to see whether a give resource is active or not , one can delete a resource and try to access that giving the path of the resource in that case we should not return the resource if it is deleted.
 void markActivated(long id, java.sql.Connection conn)
           
 void markDeleted(java.lang.String path, java.sql.Connection conn)
           
 void removeProperties(long resourceID, java.sql.Connection conn)
           
 void renameResource(java.lang.String oldPath, java.lang.String newPath, java.sql.Connection conn, java.lang.String userId, UserRealm realm, Registry registry)
          This method will move a resource from oldpath to newpath , the internal implementation is such that frit the release will be deleted from oldPath parent and will be added to the newptah so if the oldpath is "foo/bar/r1" then the r1 will be removed from foo/bar.
 void renameWithoutDelete(java.lang.String oldPath, java.lang.String newPath, java.lang.String userId, UserRealm realm, Registry registry)
          This method will copy a resource from oldpath to newpath , the internal implementation is such that copy all the resources from oldpath to new path including tags , comments and ratings.
 boolean resourceActive(java.lang.String path, java.sql.Connection conn)
           
 boolean resourceExist(java.lang.String path, java.sql.Connection conn)
           
 void restore(long resourceId, long toVersion, java.sql.Connection connection)
           
 void update(java.lang.String path, ResourceImpl resource, java.sql.Connection conn)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VersionedResourceDAO

public VersionedResourceDAO(javax.sql.DataSource dataSource)
Method Detail

get

public ResourceImpl get(java.lang.String path,
                        long versionNumber,
                        java.sql.Connection conn)
                 throws java.sql.SQLException,
                        java.io.IOException
Returns the given version of the artifact. If artifact is a collection all child paths will be added as versioned paths in the form /a/b?v=12

Parameters:
path - : path of the artifact
versionNumber - : Version number
conn - : Connection to DB
Returns:
Resource for the given version number
Throws:
java.sql.SQLException - : If something went wrong
java.io.IOException

getResourceByID

public ResourceImpl getResourceByID(long artifactID,
                                    long versionNumber,
                                    java.sql.Connection conn)
                             throws java.sql.SQLException,
                                    java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

getResourceContentStream

public java.io.InputStream getResourceContentStream(long resourceID,
                                                    long versionNumber,
                                                    java.sql.Connection conn)
                                             throws java.sql.SQLException,
                                                    java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

getDependencies

public DependencyChain[] getDependencies(java.lang.String resourcePath,
                                         java.sql.Connection conn)
                                  throws java.sql.SQLException,
                                         RegistryException
Throws:
java.sql.SQLException
RegistryException

getDependents

public DependentChain[] getDependents(java.lang.String resourcePath,
                                      java.sql.Connection conn)
                               throws java.sql.SQLException,
                                      RegistryException
Throws:
java.sql.SQLException
RegistryException

getLatestVersion

public ResourceImpl getLatestVersion(java.lang.String path,
                                     java.sql.Connection conn)
                              throws RegistryException,
                                     java.sql.SQLException,
                                     java.io.IOException
Returns the latest (current) version of an artifact. If artifact is a collection, all child paths will be added as latest paths in the form /a/b

Parameters:
path - : path of the artifact
conn - :Connection to DB
Returns:
: Result artifact
Throws:
java.sql.SQLException - : if something went wrong
RegistryException
java.io.IOException

getCurrentVersionNumber

public long getCurrentVersionNumber(java.lang.String path,
                                    java.sql.Connection conn)
                             throws RegistryException
To get the current version for a give resource , current version may not be the latest version in all the cases. If someone restore a resource then the child nodes will remain same But the parent version will be changed. In that case the parent [foo/bar] version will be the latest version but the child node version [foo/bar/v1] will be an old version . So when some one ask for the resource value foo/bar/v1 then we need to calculate them correctly and give that.

Parameters:
path - : Resource ID
conn - : Connection to DB
Returns:
: verion number of the resource user requested
Throws:
RegistryException

getChildPaths

public java.lang.String[] getChildPaths(long artifcatID,
                                        long versionNumber,
                                        java.sql.Connection connection)
                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

getParentPath

public java.lang.String getParentPath(long resourceID,
                                      long versionNumber,
                                      java.sql.Connection connection)
                               throws java.sql.SQLException
Throws:
java.sql.SQLException

getLatestChildPaths

public java.lang.String[] getLatestChildPaths(long resourceID,
                                              long versionNumber,
                                              java.sql.Connection connection)
                                       throws java.sql.SQLException
Throws:
java.sql.SQLException

getChildren

public java.util.List getChildren(long resourceID,
                                  long versionNumber,
                                  java.sql.Connection connection)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

add

public void add(ResourceImpl resource,
                java.sql.Connection conn)
         throws java.sql.SQLException,
                RegistryException
Adds the given resource to the database.

Parameters:
resource - New resource
conn - : Connection to Db
Throws:
java.sql.SQLException - : if something went wrong
RegistryException

update

public void update(java.lang.String path,
                   ResourceImpl resource,
                   java.sql.Connection conn)
            throws java.sql.SQLException,
                   RegistryException
Throws:
java.sql.SQLException
RegistryException

markDeleted

public void markDeleted(java.lang.String path,
                        java.sql.Connection conn)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

markActivated

public void markActivated(long id,
                          java.sql.Connection conn)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

addProperties

public void addProperties(long resourceID,
                          java.util.Properties props,
                          java.sql.Connection conn)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

addDependencies

public void addDependencies(long resourceID,
                            long version,
                            java.lang.String[] dependencyPaths,
                            java.sql.Connection conn)
                     throws java.sql.SQLException,
                            RegistryException
Adds dependencyPaths to the given version of a resource. If dependency path does not contain a version number, latest version of the dependency will be used.

Throws:
java.sql.SQLException
RegistryException

addDependencies

public void addDependencies(long resourceID,
                            long version,
                            DependencyChain[] dependencies,
                            java.sql.Connection conn)
                     throws java.sql.SQLException,
                            RegistryException
Adds dependencies to the given version of a resource. Note that only the first level dependencies are added as other dependencies are not associated with this resource.

Throws:
java.sql.SQLException
RegistryException

removeProperties

public void removeProperties(long resourceID,
                             java.sql.Connection conn)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

resourceExist

public boolean resourceExist(java.lang.String path,
                             java.sql.Connection conn)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

resourceActive

public boolean resourceActive(java.lang.String path,
                              java.sql.Connection conn)
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

getResourceID

public long getResourceID(java.lang.String path,
                          java.sql.Connection conn)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getResourcePath

public java.lang.String getResourcePath(long id,
                                        java.sql.Connection conn)
                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

renameWithoutDelete

public void renameWithoutDelete(java.lang.String oldPath,
                                java.lang.String newPath,
                                java.lang.String userId,
                                UserRealm realm,
                                Registry registry)
                         throws java.sql.SQLException,
                                RegistryException,
                                java.io.IOException
This method will copy a resource from oldpath to newpath , the internal implementation is such that copy all the resources from oldpath to new path including tags , comments and ratings.

Parameters:
oldPath - : Current path of the resource
newPath - : Where to move the resource
userId - : current user
realm - : Realm
Throws:
RegistryException - : If something went wrong
java.sql.SQLException
java.io.IOException

renameResource

public void renameResource(java.lang.String oldPath,
                           java.lang.String newPath,
                           java.sql.Connection conn,
                           java.lang.String userId,
                           UserRealm realm,
                           Registry registry)
                    throws java.sql.SQLException,
                           java.io.IOException,
                           RegistryException
This method will move a resource from oldpath to newpath , the internal implementation is such that frit the release will be deleted from oldPath parent and will be added to the newptah so if the oldpath is "foo/bar/r1" then the r1 will be removed from foo/bar. However later we can restore and get everything working fine

Parameters:
oldPath - : Current path of the resource
newPath - : Where to move the resource
conn - : Connection to DB
userId - : current user
realm - : Realm
Throws:
RegistryException - : If something went wrong
java.sql.SQLException
java.io.IOException

addResourceVersion

public long addResourceVersion(ResourceImpl resource,
                               java.sql.Connection connection)
                        throws java.sql.SQLException,
                               java.io.IOException,
                               RegistryException
Throws:
java.sql.SQLException
java.io.IOException
RegistryException

convertToBytes

public static byte[] convertToBytes(java.lang.Object object)

getLatestVersionNumber

public long getLatestVersionNumber(long resourceId,
                                   java.sql.Connection connection)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

getVersionNumbers

public java.lang.String[] getVersionNumbers(long resourceId,
                                            java.sql.Connection connection)
                                     throws java.sql.SQLException
Throws:
java.sql.SQLException

restore

public void restore(long resourceId,
                    long toVersion,
                    java.sql.Connection connection)
             throws java.sql.SQLException,
                    java.io.IOException,
                    RegistryException
Throws:
java.sql.SQLException
java.io.IOException
RegistryException

deleteResource

public void deleteResource(ResourceImpl resource,
                           java.sql.Connection connection)
                    throws java.sql.SQLException,
                           java.io.IOException,
                           RegistryException
To delete a resource , what actually happen here is that update the version table with the new data and resource will not actually removed from the table

Parameters:
resource - : Resource to be deleted
connection - : Connection to the DB
Throws:
java.sql.SQLException - : if something went wrong
java.io.IOException
RegistryException

isResourceActive

public boolean isResourceActive(java.lang.String resourcePath,
                                java.sql.Connection connection)
This method is use to see whether a give resource is active or not , one can delete a resource and try to access that giving the path of the resource in that case we should not return the resource if it is deleted.

Parameters:
resourcePath - : Path of the resource
connection - : Connection to DB
Returns:
: return true if the resource is active , else false


Copyright © 2007 Apache Web Services Project. All Rights Reserved.