net.rim.pushsdk.push.stats
Class PushStatsMemoryDAOImpl

java.lang.Object
  extended by net.rim.pushsdk.push.stats.PushStatsMemoryDAOImpl
All Implemented Interfaces:
PushStatsDAO

public class PushStatsMemoryDAOImpl
extends Object
implements PushStatsDAO

Memory implementation of the PushStatsDAO interface.

Warning: Data will only survive while the JVM is running. The purpose of this class is to do quick and easy testing without needing to setup a database.

 Example of using this object outside of the Spring bean factory:
 PushStatsDAO dao = new PushStatsMemoryDAOImpl();
 dao.setPushMemoryDataStore(...);
 
 Now you can use the object...
 dao.someMethod(...);
 
Warning: This class is not intended for production use.

Dependencies that must be injected to properly initialize this object for use:
- pushStatsMemoryDataStore
- pushAppMemoryDataStore

Author:
dstrelbytsky

Constructor Summary
PushStatsMemoryDAOImpl()
           
 
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 setPushAppMemoryDataStore(PushAppMemoryDataStore pushAppMemoryDataStore)
          Sets the in-memory data store to use for storing push applications.
 void setPushStatsMemoryDataStore(PushStatsMemoryDataStore pushStatsMemoryDataStore)
          Sets the in-memory data store to use for storing push stats.
 void updateCache(PushStats pushStats)
          Updates the cache with the given push stats.
 int updatePushStats(PushStats pushStats)
          Updates push statistics for the specified push application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PushStatsMemoryDAOImpl

public PushStatsMemoryDAOImpl()
Method Detail

setPushStatsMemoryDataStore

public void setPushStatsMemoryDataStore(PushStatsMemoryDataStore pushStatsMemoryDataStore)
Sets the in-memory data store to use for storing push stats.

Parameters:
pushStatsMemoryDataStore - push stats in-memory data store

setPushAppMemoryDataStore

public void setPushAppMemoryDataStore(PushAppMemoryDataStore pushAppMemoryDataStore)
Sets the in-memory data store to use for storing push applications.

Parameters:
pushAppMemoryDataStore - push application in-memory data store

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)
Description copied from interface: PushStatsDAO
Updates the cache with the given push stats. For implementations of this DAO that do not use a cache, this method should do nothing.

Specified by:
updateCache in interface PushStatsDAO
Parameters:
pushStats - the push stats to updated the cache with


Copyright © 2011 Research In Motion. All Rights Reserved.