org.wso2.carbon.registry.core.jdbc.dao
Class JDBCRatingsDAO

java.lang.Object
  extended by org.wso2.carbon.registry.core.jdbc.dao.JDBCRatingsDAO
All Implemented Interfaces:
RatingsDAO
Direct Known Subclasses:
JDBCRatingsVersionDAO

public class JDBCRatingsDAO
extends java.lang.Object
implements RatingsDAO

An implementation of the RatingsDAO to store ratings on a JDBC-based database.


Field Summary
protected static java.lang.Object ADD_RATING_LOCK
           
 
Constructor Summary
JDBCRatingsDAO(DAOManager daoManager)
          Default constructor
 
Method Summary
 void addRating(ResourceImpl resourceImpl, java.lang.String userID, int rating)
          Method to persist a rating.
 void addRatings(ResourceImpl resource, RatingDO[] ratingDOs)
          Method to persist ratings.
 void copyRatings(ResourceImpl fromResource, ResourceImpl toResource)
          Method to copy ratings.
 float getAverageRating(ResourceImpl resourceImpl)
          Method to get the average rating added to a given resource.
 java.lang.String[] getRatedUserNames(ResourceImpl resourceImpl)
          Method to get users who rated the given resource.
 int getRateID(ResourceImpl resourceImpl, java.lang.String userID)
          Method to get a id of a rating added to a given resource.
 RatingDO getRating(long ratingID)
          Method to get a rating corresponding to the given id.
 int getRating(ResourceImpl resourceImpl, java.lang.String userID)
          Method to get a rating added to a given resource.
 RatingDO getRatingDO(ResourceImpl resourceImpl, java.lang.String userID)
          Method to get a rating added by the given user to the given resource.
 RatingDO[] getResourceRatingDO(ResourceImpl resourceImpl)
          Method to get ratings added by all users to the given resource.
 ResourceImpl getResourceWithMinimumData(java.lang.String path)
          Gets the resource with sufficient data to differentiate it from another resource.
 void moveRatingPaths(ResourceIDImpl source, ResourceIDImpl target)
          Method to move rating paths.
 void moveRatings(ResourceIDImpl source, ResourceIDImpl target)
          Method to move ratings.
 void removeRatings(ResourceImpl resourceImpl)
          Method to remove all ratings added to a resource.
 void updateRating(ResourceImpl resourceImpl, int rateID, int rating)
          Method to update a rating added to a resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADD_RATING_LOCK

protected static final java.lang.Object ADD_RATING_LOCK
Constructor Detail

JDBCRatingsDAO

public JDBCRatingsDAO(DAOManager daoManager)
Default constructor

Parameters:
daoManager - instance of the data access object manager.
Method Detail

addRating

public void addRating(ResourceImpl resourceImpl,
                      java.lang.String userID,
                      int rating)
               throws RegistryException
Description copied from interface: RatingsDAO
Method to persist a rating.

Specified by:
addRating in interface RatingsDAO
Parameters:
resourceImpl - the resource
userID - the id of the user who added the rating.
rating - the rating to be persisted.
Throws:
RegistryException - if some error occurs while adding a rating

copyRatings

public void copyRatings(ResourceImpl fromResource,
                        ResourceImpl toResource)
                 throws RegistryException
Description copied from interface: RatingsDAO
Method to copy ratings.

Specified by:
copyRatings in interface RatingsDAO
Parameters:
fromResource - the source resource.
toResource - the target resource.
Throws:
RegistryException - if some error occurs while copying ratings

addRatings

public void addRatings(ResourceImpl resource,
                       RatingDO[] ratingDOs)
                throws RegistryException
Description copied from interface: RatingsDAO
Method to persist ratings.

Specified by:
addRatings in interface RatingsDAO
Parameters:
resource - the resource
ratingDOs - the ratings to be persisted.
Throws:
RegistryException - if some error occurs while adding ratings

updateRating

public void updateRating(ResourceImpl resourceImpl,
                         int rateID,
                         int rating)
                  throws RegistryException
Description copied from interface: RatingsDAO
Method to update a rating added to a resource.

Specified by:
updateRating in interface RatingsDAO
Parameters:
resourceImpl - the resource.
rateID - the rate id.
rating - the rating.
Throws:
RegistryException - if some error occurs while updating the rating.

getRateID

public int getRateID(ResourceImpl resourceImpl,
                     java.lang.String userID)
              throws RegistryException
Description copied from interface: RatingsDAO
Method to get a id of a rating added to a given resource.

Specified by:
getRateID in interface RatingsDAO
Parameters:
resourceImpl - the resource.
userID - the id of the user who added the rating.
Returns:
the rate id.
Throws:
RegistryException - if an error occurs while getting the rate id.

getAverageRating

public float getAverageRating(ResourceImpl resourceImpl)
                       throws RegistryException
Description copied from interface: RatingsDAO
Method to get the average rating added to a given resource.

Specified by:
getAverageRating in interface RatingsDAO
Parameters:
resourceImpl - the resource.
Returns:
the average rating.
Throws:
RegistryException - if an error occurs while getting the average rating.

getRatingDO

public RatingDO getRatingDO(ResourceImpl resourceImpl,
                            java.lang.String userID)
                     throws RegistryException
Description copied from interface: RatingsDAO
Method to get a rating added by the given user to the given resource.

Specified by:
getRatingDO in interface RatingsDAO
Parameters:
resourceImpl - the resource.
userID - the id of the user who added the rating.
Returns:
the rating data object.
Throws:
RegistryException - if an error occurs while getting the rating.

getRating

public int getRating(ResourceImpl resourceImpl,
                     java.lang.String userID)
              throws RegistryException
Description copied from interface: RatingsDAO
Method to get a rating added to a given resource.

Specified by:
getRating in interface RatingsDAO
Parameters:
resourceImpl - the resource.
userID - the id of the user who added the rating.
Returns:
the rating.
Throws:
RegistryException - if an error occurs while getting the rating.

getRating

public RatingDO getRating(long ratingID)
                   throws java.sql.SQLException,
                          RegistryException
Method to get a rating corresponding to the given id.

Parameters:
ratingID - the id of the rating.
Returns:
the rating data object.
Throws:
RegistryException - if an error occurs while getting the resource path.
java.sql.SQLException - if an error occurs while getting the rating.

removeRatings

public void removeRatings(ResourceImpl resourceImpl)
                   throws RegistryException
Description copied from interface: RatingsDAO
Method to remove all ratings added to a resource.

Specified by:
removeRatings in interface RatingsDAO
Parameters:
resourceImpl - the resource.
Throws:
RegistryException - if some error occurs while removing ratings.

getResourceRatingDO

public RatingDO[] getResourceRatingDO(ResourceImpl resourceImpl)
                               throws RegistryException
Description copied from interface: RatingsDAO
Method to get ratings added by all users to the given resource.

Specified by:
getResourceRatingDO in interface RatingsDAO
Parameters:
resourceImpl - the resource.
Returns:
array of rating data objects.
Throws:
RegistryException - if an error occurs while getting the rating.

getRatedUserNames

public java.lang.String[] getRatedUserNames(ResourceImpl resourceImpl)
                                     throws RegistryException
Description copied from interface: RatingsDAO
Method to get users who rated the given resource.

Specified by:
getRatedUserNames in interface RatingsDAO
Parameters:
resourceImpl - the resource.
Returns:
array of user names.
Throws:
RegistryException - if an error occurs while getting the rating.

getResourceWithMinimumData

public ResourceImpl getResourceWithMinimumData(java.lang.String path)
                                        throws RegistryException
Description copied from interface: RatingsDAO
Gets the resource with sufficient data to differentiate it from another resource. This would populate a ResourceImpl with the path, name and path identifier of a resource.

Specified by:
getResourceWithMinimumData in interface RatingsDAO
Parameters:
path - the path of the resource.
Returns:
the resource with minimum data.
Throws:
RegistryException - if an error occurs while retrieving resource data.

moveRatings

public void moveRatings(ResourceIDImpl source,
                        ResourceIDImpl target)
                 throws RegistryException
Description copied from interface: RatingsDAO
Method to move ratings.

Specified by:
moveRatings in interface RatingsDAO
Parameters:
source - the source resource.
target - the target resource.
Throws:
RegistryException - if some error occurs while moving ratings

moveRatingPaths

public void moveRatingPaths(ResourceIDImpl source,
                            ResourceIDImpl target)
                     throws RegistryException
Description copied from interface: RatingsDAO
Method to move rating paths. This function will move the paths from one path id to another regardless of the resource name.

Specified by:
moveRatingPaths in interface RatingsDAO
Parameters:
source - the source resource.
target - the target resource.
Throws:
RegistryException - if some error occurs while moving rating paths


Copyright © 2011 WSO2 Inc. All Rights Reserved.