net.rim.pushsdk.push.stats
Class PushStatsRDBMSDAOImpl

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.jdbc.core.support.JdbcDaoSupport
          extended by net.rim.pushsdk.commons.PushSDKBaseDAO
              extended by net.rim.pushsdk.push.stats.PushStatsRDBMSDAOImpl
All Implemented Interfaces:
PushStatsDAO, org.springframework.beans.factory.InitializingBean

public class PushStatsRDBMSDAOImpl
extends PushSDKBaseDAO
implements PushStatsDAO

RDBMS implementation of the PushStatsDAO interface.

Dependencies that must be injected to properly initialize this object for use:
- dataSource
- sqlProperties
- cache (optional)

Author:
dstrelbytsky

Field Summary
 
Fields inherited from class net.rim.pushsdk.commons.PushSDKBaseDAO
DATABASE_TZ
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
PushStatsRDBMSDAOImpl()
           
 
Method Summary
 void addPushStats(PushStats pushStats)
          Adds push statistics for the push application with the specified id and provided running push count, running content sum, and daily push count.
 int[] batchUpdatePushStats(Map<String,PushStats> pushStatsMap)
          Performs a batch update of push statistics for various push applications.
 PushStats getPushStats(String pushApplicationId, boolean preferUseCache)
          Gets push statistics for the specified push application.
 void resetRunningContentSum(String pushApplicationId)
          Resets the running content sum pushed to the specified push application.
 void resetRunningPushCount(String pushApplicationId)
          Resets the running push count for the specified push application.
 void setCache(net.sf.ehcache.Cache cache)
          Sets a cache to use to cache PushStats.
 void setSqlProperties(SQLProperties sqlProperties)
           
 void updateCache(PushStats pushStats)
          Updates cached push statistics for the push application defined by the push application id of the pushStats parameter of this method.
 int updatePushStats(PushStats pushStats)
          Updates push statistics for the specified push application.
 
Methods inherited from class net.rim.pushsdk.commons.PushSDKBaseDAO
encodeSQLText, encodeSQLText, encodeSQLText, getSimpleJdbcTemplate
 
Methods inherited from class org.springframework.jdbc.core.support.JdbcDaoSupport
checkDaoConfig, createJdbcTemplate, getConnection, getDataSource, getExceptionTranslator, getJdbcTemplate, initTemplateConfig, releaseConnection, setDataSource, setJdbcTemplate
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PushStatsRDBMSDAOImpl

public PushStatsRDBMSDAOImpl()
Method Detail

setSqlProperties

public void setSqlProperties(SQLProperties sqlProperties)

setCache

public void setCache(net.sf.ehcache.Cache cache)
Sets a cache to use to cache PushStats. Optional - do not call setter if no cache should be used.

Parameters:
cache - an instance of a cache

addPushStats

public void addPushStats(PushStats pushStats)
                  throws org.springframework.dao.DataAccessException
Description copied from interface: PushStatsDAO
Adds push statistics for the push application with the specified id and provided running push count, running content sum, and daily push count.

Specified by:
addPushStats in interface PushStatsDAO
Parameters:
pushStats - push statistics that contain id of the push application, running push count, running content sum, and daily push count
Throws:
org.springframework.dao.DataAccessException - if any data access errors occur

updatePushStats

public int updatePushStats(PushStats pushStats)
                    throws org.springframework.dao.DataAccessException
Description copied from interface: PushStatsDAO
Updates push statistics for the specified push application. As a result of this update, the push statistics in the persistent store will be updated as follows:
- the running push count will be incremented by the corresponding pushStats parameter;
- the running content sum will be incremented by the corresponding pushStats parameter;
- the daily push count will be incremented by the corresponding pushStats parameter if the update happens on the same day as the in storage daily push count date. Otherwise, this is the first update during the day and the daily push count will be set to the corresponding pushStats parameter;
- the daily push count date will be set to the current date and time.

Specified by:
updatePushStats in interface PushStatsDAO
Parameters:
pushStats - push statistics that contain id of the push application, running push count, running content sum, and daily push count
Returns:
number of records in the persistent store affected as a result of this update. In most cases (when the record for this push application already exists), the method returns 1. Otherwise 0 is returned, meaning that the user of the method should call addPushStats.
Throws:
org.springframework.dao.DataAccessException - if any data access errors occur

batchUpdatePushStats

public int[] batchUpdatePushStats(Map<String,PushStats> pushStatsMap)
                           throws org.springframework.dao.DataAccessException
Description copied from interface: PushStatsDAO
Performs a batch update of push statistics for various push applications.

Specified by:
batchUpdatePushStats in interface PushStatsDAO
Parameters:
pushStatsMap - the push stats to update in storage
Returns:
an array where each item corresponds to an update in the batch and indicates the number of rows changed by that update (typically 1 if the row was updated or 0 if the row was not updated)
Throws:
org.springframework.dao.DataAccessException - if any data access errors occur

getPushStats

public PushStats getPushStats(String pushApplicationId,
                              boolean preferUseCache)
                       throws org.springframework.dao.DataAccessException
Description copied from interface: PushStatsDAO
Gets push statistics for the specified push application.

Specified by:
getPushStats in interface PushStatsDAO
Parameters:
pushApplicationId - id of the push application
preferUseCache - specifies whether the cached value of the remaining quota is preferable or not. In the first case ( preferUseCache is equal to true), the method will try to retrieve the remaining quota from the cache first. If there is no cached value found, a look up in the persistent store will be done. If preferUseCache is equal to false, the remaining quota will always be retrieved from the persistent store. Using the cache will generally be a faster operation. Note: Retrieving the remaining quota from the persistent store can be somewhat inaccurate. Updates to the push statistics in storage are batched and persisted at a regular interval and so the stats might be slightly off within that interval.
Returns:
push statistics
Throws:
org.springframework.dao.DataAccessException - if any data access errors occur

resetRunningPushCount

public void resetRunningPushCount(String pushApplicationId)
                           throws org.springframework.dao.DataAccessException
Description copied from interface: PushStatsDAO
Resets the running push count for the specified push application. This method can be useful for report generation. For example, if the content provider wants to generate weekly push statistics reports, then they should call this API weekly to reset the count.

Specified by:
resetRunningPushCount in interface PushStatsDAO
Parameters:
pushApplicationId - id of the push application
Throws:
org.springframework.dao.DataAccessException - if any data access errors occur

resetRunningContentSum

public void resetRunningContentSum(String pushApplicationId)
                            throws org.springframework.dao.DataAccessException
Description copied from interface: PushStatsDAO
Resets the running content sum pushed to the specified push application. This method can be useful for report generation. For example, if the content provider wants to generate weekly push statistics reports, then they should call this API weekly to reset the running content sum.

Specified by:
resetRunningContentSum in interface PushStatsDAO
Parameters:
pushApplicationId - id of the push application
Throws:
org.springframework.dao.DataAccessException - if any data access errors occur

updateCache

public void updateCache(PushStats pushStats)
Updates cached push statistics for the push application defined by the push application id of the pushStats parameter of this method. As a result of this update the cached push statistics will be updated as follows:
- the running push count will be incremented by the corresponding property of the pushStats parameter;
- the running content sum will be incremented by the corresponding property of the pushStats parameter;
- the daily push count will be incremented by the corresponding property of the pushStats parameter if the update happens on the same day as the loaded daily push count date. Otherwise, this is the first update during the day and the daily push count will be set to the corresponding property of the pushStats parameter;
- the daily push count date will be set to the current date.
Note: See ehcache.xml and distributed-ehcache-sample.xml for configuration options for the push statistics cache.

Specified by:
updateCache in interface PushStatsDAO
Parameters:
pushStats - the push statistics to update the cache with


Copyright © 2011 Research In Motion. All Rights Reserved.