org.wso2.registry.jdbc
Class BasicRegistry

java.lang.Object
  extended by org.wso2.registry.jdbc.BasicRegistry
All Implemented Interfaces:
CoreRegistry, Registry

public class BasicRegistry
extends java.lang.Object
implements Registry

This class contains JDBC based implementations of all Registry API methods. This invokes handlers through the HandlerManager for all the methods that allow handlers. Once the handler invocation is complete and if the processing is not completed, it handles the request using the generic procedure. For the methods that do not allow handlers, it simply processes the request using the database layer. A valid database connection has to be available in the Transaction's thread local varaible, when invoking methods of this class. Mehtods of this class neither start nor commit the transactions when performing the operations. The caller of this class should manage database transactions outside this class. There is only one instance of this class per registry instance. This instance can be invoked by many threads. So it has to be thread safe.


Field Summary
static org.apache.commons.logging.Log log
           
 
Constructor Summary
BasicRegistry(RegistryContext registryContext, Repository repository, VersionRepository versionRepository, QueryProcessorManager queryProcessorManager)
          Instantiates the BasicRegistry instance.
 
Method Summary
 void addAssociation(java.lang.String sourcePath, java.lang.String targetPath, java.lang.String associationType)
          Adds an association stating that the resource at "associationPath" associate on the resource at "associationPath".
 java.lang.String addComment(java.lang.String resourcePath, Comment comment)
          Adds a comment to a resource.
 void applyTag(java.lang.String resourcePath, java.lang.String tag)
          Applies the given tag to the resource in the given path.
 void associateAspect(java.lang.String resourcePath, java.lang.String name)
          Associate an Aspect with a resource.
 void beginTransaction()
          BasicRegistry does not implement transaction related methods as transactions has to be handled outside of the BasicRegistry.
 void commitTransaction()
          BasicRegistry does not implement transaction related methods as transactions has to be handled outside of the BasicRegistry.
 java.lang.String copy(java.lang.String sourcePath, java.lang.String targetPath)
           
 void createVersion(java.lang.String path)
           
 void delete(java.lang.String path)
          Deletes the resource in the given path.
 void editComment(java.lang.String commentPath, java.lang.String text)
          Change the text of an existing comment.
 Collection executeQuery(java.lang.String path, java.util.Map parameters)
          Executes a custom query which lives at the given path in the Registry.
 Resource get(java.lang.String path)
          Returns the resource in the given path.
 Collection get(java.lang.String path, int start, int pageSize)
          Retrives a collection from the registry.
 Association[] getAllAssociations(java.lang.String resourcePath)
          Get all associations of the given resource.
 java.lang.String[] getAspectActions(java.lang.String resourcePath, java.lang.String aspectName)
          Obtain a list of the available actions on a given resource for a given Aspect.
 Association[] getAssociations(java.lang.String resourcePath, java.lang.String associationType)
          Get all associations of the given resource for a give association type.
 java.lang.String[] getAvailableAspects()
          Get a list of the available Aspects for this Registry
 float getAverageRating(java.lang.String resourcePath)
          Returns the average rating (from all users) for the given resource.
 Comment[] getComments(java.lang.String resourcePath)
          Returns all comments for the given resource.
 LogEntryCollection getLogCollection(java.lang.String resourcePath, int action, java.lang.String userName, java.util.Date from, java.util.Date to, boolean recentFirst)
          Returns the logs of the activities occured in the registy.
 LogEntry[] getLogs(java.lang.String resourcePath, int action, java.lang.String userName, java.util.Date from, java.util.Date to, boolean recentFirst)
          Returns the logs of the activities occured in the registy.
 int getRating(java.lang.String path, java.lang.String userName)
          Returns the rating given to the specified resource by the given user
 RegistryContext getRegistryContext()
          Get the configuration for this Registry
 Aspect getResourceAspect(Resource resource, java.lang.String aspectName)
           
 TaggedResourcePath[] getResourcePathsWithTag(java.lang.String tag)
          Returns the paths of the resources, which are tagged using the given tag.
 Tag[] getTags(java.lang.String resourcePath)
          Returns all tags used for tagging the given resource.
 java.lang.String[] getVersions(java.lang.String path)
          Get a list of all versions of the resource located at the given path.
 java.lang.String importResource(java.lang.String suggestedPath, java.lang.String sourceURL, Resource metadata)
          Creates a new resource by importing the reosurce content from the given source URL.
 void invokeAspect(java.lang.String resourcePath, java.lang.String aspectName, java.lang.String action)
          This invokes an action on a specified Aspect, which must be associated with the Resource at the given path.
 java.lang.String move(java.lang.String currentPath, java.lang.String newPath)
           
 Collection newCollection()
           
 Resource newResource()
           
 java.lang.String put(java.lang.String suggestedPath, Resource resource)
          Adds or updates resources in the registry.
 void rateResource(java.lang.String resourcePath, int rating)
          Rates the given resource.
 void removeAssociation(java.lang.String sourcePath, java.lang.String targetPath, java.lang.String associationType)
          To remove an association for a given resource
 void removeTag(java.lang.String path, java.lang.String tag)
          Removes a tag on a resource.
 java.lang.String rename(java.lang.String currentPath, java.lang.String newName)
          Move or rename a resource in the registry.
 boolean resourceExists(java.lang.String path)
          Checks whether a resource exists in the registry.
 void restoreVersion(java.lang.String versionPath)
          Reverts a resource to a given version.
 void rollbackTransaction()
          BasicRegistry does not implement transaction related methods as transactions has to be handled outside of the BasicRegistry.
 Collection searchContent(java.lang.String keywords)
          Search the content of resources
 void setRegistryContext(RegistryContext registryContext)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.commons.logging.Log log
Constructor Detail

BasicRegistry

public BasicRegistry(RegistryContext registryContext,
                     Repository repository,
                     VersionRepository versionRepository,
                     QueryProcessorManager queryProcessorManager)
Instantiates the BasicRegistry instance. Objects passed to the constructor should be shared between JDBCRegisty and BasicRegistry instances.

Parameters:
registryContext - RegistryContext instance containing the registry configuration.
repository - Repository instance.
versionRepository - VersionRepository instance.
queryProcessorManager - QueryProcessorManager instance.
Method Detail

beginTransaction

public void beginTransaction()
                      throws RegistryException
BasicRegistry does not implement transaction related methods as transactions has to be handled outside of the BasicRegistry.

Specified by:
beginTransaction in interface Registry
Throws:
RegistryException - If an error occurs while starting a transaction

commitTransaction

public void commitTransaction()
                       throws RegistryException
BasicRegistry does not implement transaction related methods as transactions has to be handled outside of the BasicRegistry.

Specified by:
commitTransaction in interface Registry
Throws:
RegistryException - If an error occurs while committing a transaction

rollbackTransaction

public void rollbackTransaction()
                         throws RegistryException
BasicRegistry does not implement transaction related methods as transactions has to be handled outside of the BasicRegistry.

Specified by:
rollbackTransaction in interface Registry
Throws:
RegistryException - If an error occurs while rolling back a transaction

newResource

public Resource newResource()
                     throws RegistryException
Specified by:
newResource in interface CoreRegistry
Throws:
RegistryException

newCollection

public Collection newCollection()
                         throws RegistryException
Specified by:
newCollection in interface CoreRegistry
Throws:
RegistryException

getRegistryContext

public RegistryContext getRegistryContext()
Description copied from interface: Registry
Get the configuration for this Registry

Specified by:
getRegistryContext in interface Registry
Returns:
the currently active RegistryContext, or null

setRegistryContext

public void setRegistryContext(RegistryContext registryContext)

get

public Resource get(java.lang.String path)
             throws RegistryException
Returns the resource in the given path.

Specified by:
get in interface CoreRegistry
Parameters:
path - Path of the resource. e.g. /project1/server/deployment.xml
Returns:
Resource instance
Throws:
RegistryException - ResourceNotFound exception is thrown if the resource is not in the registry

get

public Collection get(java.lang.String path,
                      int start,
                      int pageSize)
               throws RegistryException
Retrives a collection from the registry. This method supports the pagination of the collection. Starting child entry number and number of entries per page can be specified.

Specified by:
get in interface CoreRegistry
Parameters:
path - Path of the collection
start - Starting child entry number
pageSize - Number of entries per page
Returns:
Collection instance filled with specified subset of child paths
Throws:
RegistryException

resourceExists

public boolean resourceExists(java.lang.String path)
                       throws RegistryException
Checks whether a resource exists in the registry.

Specified by:
resourceExists in interface CoreRegistry
Parameters:
path - Path of resource
Returns:
true if resource exists, false otherwise.
Throws:
RegistryException

put

public java.lang.String put(java.lang.String suggestedPath,
                            Resource resource)
                     throws RegistryException
Adds or updates resources in the registry. If there is no resource in the given path, resource is added. If a resource already exist in the given path, it will be replaced with the new resource.

Specified by:
put in interface CoreRegistry
Parameters:
suggestedPath - the path which we'd like to use for the new resource.
resource - Resource instance for the new resource
Returns:
the actual path that the server chose to use for our Resource
Throws:
RegistryException - This exception is thrown for all database layer and handler exceptions.

importResource

public java.lang.String importResource(java.lang.String suggestedPath,
                                       java.lang.String sourceURL,
                                       Resource metadata)
                                throws RegistryException
Creates a new resource by importing the reosurce content from the given source URL.

Specified by:
importResource in interface Registry
Parameters:
suggestedPath - Path to put the resource.
sourceURL - URL to import resource content.
metadata - Metadata for the new resource.
Returns:
Path where the resource is stored. Note that this may differ from the suggestedPath as some modifications to the suggestedPath will be done if it does not comply with Registry standards.
Throws:
RegistryException

delete

public void delete(java.lang.String path)
            throws RegistryException
Deletes the resource in the given path. If the path refers to a directory, all child resources of the directory will also be deleted.

Specified by:
delete in interface CoreRegistry
Parameters:
path - Path of the resource to be deleted.
Throws:
RegistryException - : if the user is not authorized

rename

public java.lang.String rename(java.lang.String currentPath,
                               java.lang.String newName)
                        throws RegistryException
Description copied from interface: Registry
Move or rename a resource in the registry. This is equivalent to 1) delete the resource, then 2) add the resource to the new location. The operation is atomic, so if it fails the old resource will still be there.

Specified by:
rename in interface Registry
Parameters:
currentPath - current path of the resource
newName - where we'd like to move the reosurce
Returns:
the actual path for the new resource
Throws:
RegistryException - if something went wrong

move

public java.lang.String move(java.lang.String currentPath,
                             java.lang.String newPath)
                      throws RegistryException
Specified by:
move in interface Registry
Throws:
RegistryException

copy

public java.lang.String copy(java.lang.String sourcePath,
                             java.lang.String targetPath)
                      throws RegistryException
Specified by:
copy in interface Registry
Throws:
RegistryException

createVersion

public void createVersion(java.lang.String path)
                   throws RegistryException
Specified by:
createVersion in interface Registry
Throws:
RegistryException

getVersions

public java.lang.String[] getVersions(java.lang.String path)
                               throws RegistryException
Description copied from interface: Registry
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

Specified by:
getVersions in interface Registry
Parameters:
path - path of a current version of a resource
Returns:
a String array containing the individual paths of versions
Throws:
RegistryException - if there is an error

restoreVersion

public void restoreVersion(java.lang.String versionPath)
                    throws RegistryException
Description copied from interface: Registry
Reverts a resource to a given version.

Specified by:
restoreVersion in interface Registry
Parameters:
versionPath - path of the version to be reverted. It is not necessary to provide the path of the resource as it can be derived from the version path.
Throws:
RegistryException - if there is an error

addAssociation

public void addAssociation(java.lang.String sourcePath,
                           java.lang.String targetPath,
                           java.lang.String associationType)
                    throws RegistryException
Description copied from interface: Registry
Adds an association stating that the resource at "associationPath" associate on the resource at "associationPath". Paths may be the resource paths of the current versions or paths of the old versions. If a path refers to the current version, it should contain the path in the form /c1/c2/r1. If it refers to an old version, it should be in the form /c1/c2/r1?v=2.

Specified by:
addAssociation in interface Registry
Parameters:
sourcePath - Path of the source resource
targetPath - Path of the target resource
associationType - Type of the association
Throws:
RegistryException - Depends on the implementation

removeAssociation

public void removeAssociation(java.lang.String sourcePath,
                              java.lang.String targetPath,
                              java.lang.String associationType)
                       throws RegistryException
Description copied from interface: Registry
To remove an association for a given resource

Specified by:
removeAssociation in interface Registry
Parameters:
sourcePath - Path of the source resource
targetPath - Path of the target resource
associationType - Type of the association
Throws:
RegistryException - Depends on the implementation

getAllAssociations

public Association[] getAllAssociations(java.lang.String resourcePath)
                                 throws RegistryException
Description copied from interface: Registry
Get all associations of the given resource. This is a chain of association starting from the given resource both upwards (source to destination) and downwards (destination to source). T his is useful to analyse how changes to other resources would affect the given resource.

Specified by:
getAllAssociations in interface Registry
Parameters:
resourcePath - Path of the resource to analyse associations.
Returns:
List of Association
Throws:
RegistryException - : If something went wrong

getAssociations

public Association[] getAssociations(java.lang.String resourcePath,
                                     java.lang.String associationType)
                              throws RegistryException
Description copied from interface: Registry
Get all associations of the given resource for a give association type. This is a chain of association starting from the given resource both upwards (source to destination) and downwards (destination to source). T his is useful to analyse how changes to other resources would affect the given resource.

Specified by:
getAssociations in interface Registry
Parameters:
resourcePath - Path of the resource to analyse associations.
associationType - : Type of the association , that could be dependecy , or some other type
Returns:
List of Association
Throws:
RegistryException - : If something went wrong

applyTag

public void applyTag(java.lang.String resourcePath,
                     java.lang.String tag)
              throws RegistryException
Applies the given tag to the resource in the given path. If the given tag is not defined in the registry, it will be defined.

Specified by:
applyTag in interface Registry
Parameters:
resourcePath - Path of the resource to be tagged.
tag - Tag. Any string can be used for the tag.
Throws:
RegistryException - ResourceNotFound exception is thrown if a resource does not exist in the given path.

getResourcePathsWithTag

public TaggedResourcePath[] getResourcePathsWithTag(java.lang.String tag)
                                             throws RegistryException
Returns the paths of the resources, which are tagged using the given tag.

Specified by:
getResourcePathsWithTag in interface Registry
Parameters:
tag - Tag
Returns:
Resource paths
Throws:
RegistryException - if an error occurs

getTags

public Tag[] getTags(java.lang.String resourcePath)
              throws RegistryException
Returns all tags used for tagging the given resource.

Specified by:
getTags in interface Registry
Parameters:
resourcePath - Path of the resource
Returns:
Tags
Throws:
RegistryException - ResourceNotFound exception is thrown if a resource does not exist in the given path.

removeTag

public void removeTag(java.lang.String path,
                      java.lang.String tag)
               throws RegistryException
Description copied from interface: Registry
Removes a tag on a resource. If the resource at the path is owned by the current user, all taggings done using the given tag will be removed. If the resource is not owned by the current user, only the tagging done by the current user will be removed.

Specified by:
removeTag in interface Registry
Parameters:
path - Resource path tagged with the given tag.
tag - Name of the tag to be removed.
Throws:
RegistryException - if there's a problem

addComment

public java.lang.String addComment(java.lang.String resourcePath,
                                   Comment comment)
                            throws RegistryException
Adds a comment to a resource.

Specified by:
addComment in interface Registry
Parameters:
resourcePath - Path of the resource to add the comment.
comment - Comment instance for the new comment.
Returns:
the path of the new comment.
Throws:
RegistryException - ResourceNotFound exception is thrown if a resource does not exist in the given path.

editComment

public void editComment(java.lang.String commentPath,
                        java.lang.String text)
                 throws RegistryException
Description copied from interface: Registry
Change the text of an existing comment.

Specified by:
editComment in interface Registry
Parameters:
commentPath - path to comment resource ("..foo/r1;comment:1")
text - new text for the comment.
Throws:
RegistryException - Registry implementations may handle exceptions and throw RegistryException if the exception has to be propagated to the client.

getComments

public Comment[] getComments(java.lang.String resourcePath)
                      throws RegistryException
Returns all comments for the given resource.

Specified by:
getComments in interface Registry
Parameters:
resourcePath - Path of the resource.
Returns:
Array of Comment objects.
Throws:
RegistryException - Registry implementations may handle exceptions and throw RegistryException if the exception has to be propagated to the client.

rateResource

public void rateResource(java.lang.String resourcePath,
                         int rating)
                  throws RegistryException
Rates the given resource.

Specified by:
rateResource in interface Registry
Parameters:
resourcePath - Path of the resource.
rating - rating value.
Throws:
RegistryException - ResourceNotFound exception is thrown if a resource does not exist in the given path.

getAverageRating

public float getAverageRating(java.lang.String resourcePath)
                       throws RegistryException
Returns the average rating (from all users) for the given resource.

Specified by:
getAverageRating in interface Registry
Parameters:
resourcePath - Path of the resource.
Returns:
average rating.
Throws:
RegistryException - if an error occurs

getRating

public int getRating(java.lang.String path,
                     java.lang.String userName)
              throws RegistryException
Description copied from interface: Registry
Returns the rating given to the specified resource by the given user

Specified by:
getRating in interface Registry
Parameters:
path - Path of the resource
userName - username of the user
Returns:
rating given by the given user
Throws:
RegistryException - if there is a problem

executeQuery

public Collection executeQuery(java.lang.String path,
                               java.util.Map parameters)
                        throws RegistryException
Description copied from interface: Registry
Executes a custom query which lives at the given path in the Registry.

Specified by:
executeQuery in interface Registry
Parameters:
path - Path of the query to execute.
parameters - a Map of query parameters (name -> value)
Returns:
a Collection containing any resource paths which match the query
Throws:
RegistryException - depends on the implementation.

getLogs

public LogEntry[] getLogs(java.lang.String resourcePath,
                          int action,
                          java.lang.String userName,
                          java.util.Date from,
                          java.util.Date to,
                          boolean recentFirst)
                   throws RegistryException
Description copied from interface: Registry
Returns the logs of the activities occured in the registy.

Specified by:
getLogs in interface Registry
Parameters:
resourcePath - If given, only the logs related to the resource path will be returned. If null, logs for all resources will be returned.
action - Only the logs pertaining to this action will be returned. For acceptable values, see LogEntry.
userName - If given, only the logs for activities done by the given user will be returned. If null, logs for all users will be returned.
from - If given, logs for activities occured after the given date will be returned. If null, there will not be a bound for the starting date.
to - If given, logs for activities occured before the given date will be returned. If null, there will not be a bound for the ending date.
recentFirst - If true, returned activities will be most-recent first. If false, returned activities will be oldest first.
Returns:
Array of LogEntry objects representing the logs
Throws:
RegistryException - if there is a problem
See Also:
Accepted values for action parameter

getLogCollection

public LogEntryCollection getLogCollection(java.lang.String resourcePath,
                                           int action,
                                           java.lang.String userName,
                                           java.util.Date from,
                                           java.util.Date to,
                                           boolean recentFirst)
                                    throws RegistryException
Description copied from interface: Registry
Returns the logs of the activities occured in the registy.

Specified by:
getLogCollection in interface Registry
Parameters:
resourcePath - If given, only the logs related to the resource path will be returned. If null, logs for all resources will be returned.
action - Only the logs pertaining to this action will be returned. For acceptable values, see LogEntry.
userName - If given, only the logs for activities done by the given user will be returned. If null, logs for all users will be returned.
from - If given, logs for activities occured after the given date will be returned. If null, there will not be a bound for the starting date.
to - If given, logs for activities occured before the given date will be returned. If null, there will not be a bound for the ending date.
recentFirst - If true, returned activities will be most-recent first. If false, returned activities will be oldest first.
Returns:
LogEntryCollection representing collection of log entries
Throws:
RegistryException - if there is a problem
See Also:
Accepted values for action parameter

getAvailableAspects

public java.lang.String[] getAvailableAspects()
Description copied from interface: Registry
Get a list of the available Aspects for this Registry

Specified by:
getAvailableAspects in interface Registry
Returns:
a String array containing available Aspect names

associateAspect

public void associateAspect(java.lang.String resourcePath,
                            java.lang.String name)
                     throws RegistryException
Description copied from interface: Registry
Associate an Aspect with a resource.

Specified by:
associateAspect in interface Registry
Parameters:
resourcePath - Path of the resource
name - Name of the aspect
Throws:
RegistryException - : If some thing went wrong while doing associating the phase

getResourceAspect

public Aspect getResourceAspect(Resource resource,
                                java.lang.String aspectName)
                         throws RegistryException
Throws:
RegistryException

invokeAspect

public void invokeAspect(java.lang.String resourcePath,
                         java.lang.String aspectName,
                         java.lang.String action)
                  throws RegistryException
Description copied from interface: Registry
This invokes an action on a specified Aspect, which must be associated with the Resource at the given path.

Specified by:
invokeAspect in interface Registry
Parameters:
resourcePath - Path of the resource
aspectName - Name of the aspect
action - Which action was selected - actions are aspect-specific
Throws:
RegistryException - if the Aspect isn't associated with the Resource, or the action isn't valid, or an Aspect-specific problem occurs.

getAspectActions

public java.lang.String[] getAspectActions(java.lang.String resourcePath,
                                           java.lang.String aspectName)
                                    throws RegistryException
Description copied from interface: Registry
Obtain a list of the available actions on a given resource for a given Aspect. The Aspect must be associated with the Resource (@see associateAspect). The actions are determined by asking the Aspect itself, so they may change depending on the state of the Resource, the user who's asking, etc)

Specified by:
getAspectActions in interface Registry
Parameters:
resourcePath - path of the Resource
aspectName - name of the Aspect to query for available actions
Returns:
a String[] of action names
Throws:
RegistryException - if the Aspect isn't associated or an Aspect-specific problem occurs

searchContent

public Collection searchContent(java.lang.String keywords)
                         throws RegistryException
Description copied from interface: Registry
Search the content of resources

Specified by:
searchContent in interface Registry
Parameters:
keywords - keywords to look for
Returns:
the result set as a collection
Throws:
RegistryException


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