org.opencms.db.generic
Class CmsSubscriptionDriver

java.lang.Object
  extended by org.opencms.db.generic.CmsSubscriptionDriver
All Implemented Interfaces:
I_CmsDriver, I_CmsSubscriptionDriver
Direct Known Subclasses:
CmsSubscriptionDriver, CmsSubscriptionDriver, CmsSubscriptionDriver, CmsSubscriptionDriver, CmsSubscriptionDriver, CmsSubscriptionDriver, CmsSubscriptionDriver

public class CmsSubscriptionDriver
extends Object
implements I_CmsDriver, I_CmsSubscriptionDriver

Generic implementation of the user tracking and subscription driver interface.

Since:
8.0.0

Field Summary
protected  CmsDriverManager m_driverManager
          A reference to the driver manager used by this driver.
protected  CmsSqlManager m_sqlManager
          The SQL manager used by this driver.
 
Fields inherited from interface org.opencms.db.I_CmsDriver
AND_CONDITION, BEGIN_CONDITION, BEGIN_EXCLUDE_CONDITION, BEGIN_INCLUDE_CONDITION, END_CONDITION, OR_CONDITION
 
Fields inherited from interface org.opencms.db.I_CmsSubscriptionDriver
DRIVER_TYPE_ID
 
Constructor Summary
CmsSubscriptionDriver()
           
 
Method Summary
protected  void addVisit(CmsDbContext dbc, String poolName, CmsVisitEntry visit)
          Adds an entry to the table of visits.
 void deleteVisits(CmsDbContext dbc, String poolName, CmsVisitEntryFilter filter)
          Deletes visit entries matching the given filter.
 long getDateLastVisitedBy(CmsDbContext dbc, String poolName, CmsUser user, CmsResource resource)
          Returns the date when the resource was last visited by the user.
 CmsSqlManager getSqlManager()
          Returns the SQL manager of this driver, if possible.
 void init(CmsDbContext dbc, CmsConfigurationManager configurationManager, List<String> successiveDrivers, CmsDriverManager driverManager)
          Initializes the driver.
 CmsSqlManager initSqlManager(String classname)
          Initializes the SQL manager for this driver.
protected  CmsVisitEntry internalReadVisitEntry(ResultSet res)
          Creates a new CmsVisitEntry object from the given result set entry.
 void markResourceAsVisitedBy(CmsDbContext dbc, String poolName, CmsResource resource, CmsUser user)
          Mark the given resource as visited by the user.
protected  CmsPair<String,List<I_CmsPreparedStatementParameter>> prepareVisitConditions(CmsVisitEntryFilter filter)
          Build the whole WHERE SQL statement part for the given visit entry filter.
 List<CmsResource> readAllSubscribedResources(CmsDbContext dbc, String poolName, CmsPrincipal principal)
          Returns all resources subscribed by the given user or group.
 List<CmsResource> readResourcesVisitedBy(CmsDbContext dbc, String poolName, CmsVisitedByFilter filter)
          Returns the resources that were visited by a user set in the filter.
 List<I_CmsHistoryResource> readSubscribedDeletedResources(CmsDbContext dbc, String poolName, CmsUser user, List<CmsGroup> groups, CmsResource parent, boolean includeSubFolders, long deletedFrom)
          Returns the subscribed history resources that were deleted.
 List<CmsResource> readSubscribedResources(CmsDbContext dbc, String poolName, CmsSubscriptionFilter filter)
          Returns the resources that were subscribed by a user or group set in the filter.
 List<CmsVisitEntry> readVisits(CmsDbContext dbc, String poolName, CmsVisitEntryFilter filter)
          Reads CmsVisitEntry objects from the database.
 void setSubscribedResourceAsDeleted(CmsDbContext dbc, String poolName, CmsResource resource)
          Marks a subscribed resource as deleted.
 void subscribeResourceFor(CmsDbContext dbc, String poolName, CmsPrincipal principal, CmsResource resource)
          Subscribes the user or group to the resource.
 void unsubscribeAllDeletedResources(CmsDbContext dbc, String poolName, long deletedTo)
          Unsubscribes all deleted resources that were deleted before the specified time stamp.
 void unsubscribeAllResourcesFor(CmsDbContext dbc, String poolName, CmsPrincipal principal)
          Unsubscribes the principal from all resources.
 void unsubscribeResourceFor(CmsDbContext dbc, String poolName, CmsPrincipal principal, CmsResource resource)
          Unsubscribes the principal from the resource.
 void unsubscribeResourceForAll(CmsDbContext dbc, String poolName, CmsResource resource)
          Unsubscribes all groups and users from the resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opencms.db.I_CmsDriver
toString
 

Field Detail

m_driverManager

protected CmsDriverManager m_driverManager
A reference to the driver manager used by this driver.


m_sqlManager

protected CmsSqlManager m_sqlManager
The SQL manager used by this driver.

Constructor Detail

CmsSubscriptionDriver

public CmsSubscriptionDriver()
Method Detail

deleteVisits

public void deleteVisits(CmsDbContext dbc,
                         String poolName,
                         CmsVisitEntryFilter filter)
                  throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Deletes visit entries matching the given filter.

Specified by:
deleteVisits in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use, if null, the default pool is used
filter - the log entry filter
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.deleteVisits(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.db.CmsVisitEntryFilter)

getDateLastVisitedBy

public long getDateLastVisitedBy(CmsDbContext dbc,
                                 String poolName,
                                 CmsUser user,
                                 CmsResource resource)
                          throws CmsException
Description copied from interface: I_CmsSubscriptionDriver
Returns the date when the resource was last visited by the user.

Specified by:
getDateLastVisitedBy in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
user - the user to check the date
resource - the resource to check the date
Returns:
the date when the resource was last visited by the user
Throws:
CmsException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.getDateLastVisitedBy(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.file.CmsUser, org.opencms.file.CmsResource)

getSqlManager

public CmsSqlManager getSqlManager()
Description copied from interface: I_CmsSubscriptionDriver
Returns the SQL manager of this driver, if possible.

Specified by:
getSqlManager in interface I_CmsSubscriptionDriver
Returns:
an SQL manager
See Also:
I_CmsSubscriptionDriver.getSqlManager()

init

public void init(CmsDbContext dbc,
                 CmsConfigurationManager configurationManager,
                 List<String> successiveDrivers,
                 CmsDriverManager driverManager)
Description copied from interface: I_CmsDriver
Initializes the driver.

Specified by:
init in interface I_CmsDriver
Parameters:
dbc - the current database context
configurationManager - the configuration manager
successiveDrivers - a list of successive drivers to be initialized
driverManager - the initialized OpenCms driver manager
See Also:
I_CmsDriver.init(org.opencms.db.CmsDbContext, org.opencms.configuration.CmsConfigurationManager, java.util.List, org.opencms.db.CmsDriverManager)

initSqlManager

public CmsSqlManager initSqlManager(String classname)
Description copied from interface: I_CmsSubscriptionDriver
Initializes the SQL manager for this driver.

To obtain JDBC connections from different pools, further {online|offline|history} pool Urls have to be specified.

Specified by:
initSqlManager in interface I_CmsSubscriptionDriver
Parameters:
classname - the classname of the SQL manager
Returns:
the SQL manager for this driver
See Also:
I_CmsSubscriptionDriver.initSqlManager(java.lang.String)

markResourceAsVisitedBy

public void markResourceAsVisitedBy(CmsDbContext dbc,
                                    String poolName,
                                    CmsResource resource,
                                    CmsUser user)
                             throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Mark the given resource as visited by the user.

Specified by:
markResourceAsVisitedBy in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
resource - the resource to mark as visited
user - the user that visited the resource
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.markResourceAsVisitedBy(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.file.CmsResource, org.opencms.file.CmsUser)

readAllSubscribedResources

public List<CmsResource> readAllSubscribedResources(CmsDbContext dbc,
                                                    String poolName,
                                                    CmsPrincipal principal)
                                             throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Returns all resources subscribed by the given user or group.

Specified by:
readAllSubscribedResources in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
principal - the principal to read the subscribed resources
Returns:
all resources subscribed by the given user or group
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.readAllSubscribedResources(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.security.CmsPrincipal)

readResourcesVisitedBy

public List<CmsResource> readResourcesVisitedBy(CmsDbContext dbc,
                                                String poolName,
                                                CmsVisitedByFilter filter)
                                         throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Returns the resources that were visited by a user set in the filter.

Specified by:
readResourcesVisitedBy in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
filter - the filter that is used to get the visited resources
Returns:
the resources that were visited by a user set in the filter
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.readResourcesVisitedBy(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.db.CmsVisitedByFilter)

readSubscribedDeletedResources

public List<I_CmsHistoryResource> readSubscribedDeletedResources(CmsDbContext dbc,
                                                                 String poolName,
                                                                 CmsUser user,
                                                                 List<CmsGroup> groups,
                                                                 CmsResource parent,
                                                                 boolean includeSubFolders,
                                                                 long deletedFrom)
                                                          throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Returns the subscribed history resources that were deleted.

Specified by:
readSubscribedDeletedResources in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
user - the user that subscribed to the resource
groups - the groups to check subscribed resources for
parent - the parent resource (folder) of the deleted resources, if null all deleted resources will be returned
includeSubFolders - indicates if the sub folders of the specified folder path should be considered, too
deletedFrom - the time stamp from which the resources should have been deleted
Returns:
the subscribed history resources that were deleted
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.readSubscribedDeletedResources(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.file.CmsUser, java.util.List, org.opencms.file.CmsResource, boolean, long)

readSubscribedResources

public List<CmsResource> readSubscribedResources(CmsDbContext dbc,
                                                 String poolName,
                                                 CmsSubscriptionFilter filter)
                                          throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Returns the resources that were subscribed by a user or group set in the filter.

Specified by:
readSubscribedResources in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
filter - the filter that is used to get the subscribed resources
Returns:
the resources that were subscribed by a user or group set in the filter
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.readSubscribedResources(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.db.CmsSubscriptionFilter)

readVisits

public List<CmsVisitEntry> readVisits(CmsDbContext dbc,
                                      String poolName,
                                      CmsVisitEntryFilter filter)
                               throws CmsDataAccessException
Reads CmsVisitEntry objects from the database.

Parameters:
dbc - the database context to use
poolName - the name of the pool which should be used for the database operation
filter - a filter for constraining the list of results
Returns:
a list of visit entries
Throws:
CmsDataAccessException - if the database operation fails

setSubscribedResourceAsDeleted

public void setSubscribedResourceAsDeleted(CmsDbContext dbc,
                                           String poolName,
                                           CmsResource resource)
                                    throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Marks a subscribed resource as deleted.

Specified by:
setSubscribedResourceAsDeleted in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
resource - the subscribed resource to mark as deleted
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.setSubscribedResourceAsDeleted(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.file.CmsResource)

subscribeResourceFor

public void subscribeResourceFor(CmsDbContext dbc,
                                 String poolName,
                                 CmsPrincipal principal,
                                 CmsResource resource)
                          throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Subscribes the user or group to the resource.

Specified by:
subscribeResourceFor in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
principal - the principal that subscribes to the resource
resource - the resource to subscribe to
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.subscribeResourceFor(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.security.CmsPrincipal, org.opencms.file.CmsResource)

unsubscribeAllDeletedResources

public void unsubscribeAllDeletedResources(CmsDbContext dbc,
                                           String poolName,
                                           long deletedTo)
                                    throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Unsubscribes all deleted resources that were deleted before the specified time stamp.

Specified by:
unsubscribeAllDeletedResources in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
deletedTo - the time stamp to which the resources have been deleted
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.unsubscribeAllDeletedResources(org.opencms.db.CmsDbContext, java.lang.String, long)

unsubscribeAllResourcesFor

public void unsubscribeAllResourcesFor(CmsDbContext dbc,
                                       String poolName,
                                       CmsPrincipal principal)
                                throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Unsubscribes the principal from all resources.

Specified by:
unsubscribeAllResourcesFor in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
principal - the principal that unsubscribes from all resources
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.unsubscribeAllResourcesFor(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.security.CmsPrincipal)

unsubscribeResourceFor

public void unsubscribeResourceFor(CmsDbContext dbc,
                                   String poolName,
                                   CmsPrincipal principal,
                                   CmsResource resource)
                            throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Unsubscribes the principal from the resource.

Specified by:
unsubscribeResourceFor in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
principal - the principal that unsubscribes from the resource
resource - the resource to unsubscribe from
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.unsubscribeResourceFor(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.security.CmsPrincipal, org.opencms.file.CmsResource)

unsubscribeResourceForAll

public void unsubscribeResourceForAll(CmsDbContext dbc,
                                      String poolName,
                                      CmsResource resource)
                               throws CmsDataAccessException
Description copied from interface: I_CmsSubscriptionDriver
Unsubscribes all groups and users from the resource.

Specified by:
unsubscribeResourceForAll in interface I_CmsSubscriptionDriver
Parameters:
dbc - the database context
poolName - the name of the database pool to use
resource - the resource to unsubscribe all groups and users from
Throws:
CmsDataAccessException - if something goes wrong
See Also:
I_CmsSubscriptionDriver.unsubscribeResourceForAll(org.opencms.db.CmsDbContext, java.lang.String, org.opencms.file.CmsResource)

addVisit

protected void addVisit(CmsDbContext dbc,
                        String poolName,
                        CmsVisitEntry visit)
                 throws CmsDbSqlException
Adds an entry to the table of visits.

Parameters:
dbc - the database context to use
poolName - the name of the database pool to use
visit - the visit bean
Throws:
CmsDbSqlException - if the database operation fails

internalReadVisitEntry

protected CmsVisitEntry internalReadVisitEntry(ResultSet res)
                                        throws SQLException
Creates a new CmsVisitEntry object from the given result set entry.

Parameters:
res - the result set
Returns:
the new CmsVisitEntry object
Throws:
SQLException - if something goes wrong

prepareVisitConditions

protected CmsPair<String,List<I_CmsPreparedStatementParameter>> prepareVisitConditions(CmsVisitEntryFilter filter)
Build the whole WHERE SQL statement part for the given visit entry filter.

Parameters:
filter - the filter
Returns:
a pair containing both the SQL and the parameters for it