org.activemath.learner.history
Class LearnerHistoryImpl

java.lang.Object
  extended by org.activemath.learner.history.LearnerHistoryImpl
All Implemented Interfaces:
EventListener, ActivemathEventListener, ActivemathEventListenerBatched, LearnerHistory

public class LearnerHistoryImpl
extends Object
implements ActivemathEventListenerBatched, LearnerHistory

Hibernate-based implementation of the LearnerHistory interface. The query methods make use of the HistoryQuery object, which can be used to constrain the database columns to include or exclude desired values. The supplied query methods allow for the pagination of the result set if it happens to be getting too large.

See Also:
HistoryQuery

Field Summary
protected static Logger log
           
 
Constructor Summary
LearnerHistoryImpl()
          Basic Constructor
 
Method Summary
 boolean alreadySeen(String learnerId, String itemId)
          returns true if an ItemPresentedEvent for the item with the given itemId can ba found, false otherwise.
 ActivemathEvent fetchEvent(long id)
          Fetches an ActivemathEventof which the id is known from the database. if there is no such event, the method returns null.
 List getHistoryEntries(HistoryQuery query)
          Returns a list of all stored events that match the supplied query.
 List getHistoryEntries(HistoryQuery query, int firstResult, int maxResults)
          Returns a sublist of the results of the given query, starting at the position firstResult of the complete result list and having a length of at most maxResults.
 int getNumResults(HistoryQuery query)
          gets the number of events stored in the database that match the given query.
 void onActivemathEvent(ActivemathEvent event)
          The EventListener method.
 void onActivemathEvents(List<ActivemathEvent> events)
          Handle a list of Activemath events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Logger log
Constructor Detail

LearnerHistoryImpl

public LearnerHistoryImpl()
Basic Constructor

Method Detail

onActivemathEvent

public void onActivemathEvent(ActivemathEvent event)
The EventListener method. Gets called with events it is subscribed for and stores these events.

Specified by:
onActivemathEvent in interface ActivemathEventListener
Parameters:
event - the event to respond to
See Also:
ActivemathEventListener

onActivemathEvents

public void onActivemathEvents(List<ActivemathEvent> events)
Description copied from interface: ActivemathEventListenerBatched
Handle a list of Activemath events.

This method must return as quickly as possible and must not block the calling thread for long.

Specified by:
onActivemathEvents in interface ActivemathEventListenerBatched
See Also:
ActivemathEventListenerBatched

fetchEvent

public ActivemathEvent fetchEvent(long id)
Fetches an ActivemathEventof which the id is known from the database. if there is no such event, the method returns null.

Specified by:
fetchEvent in interface LearnerHistory
Parameters:
id - The id of the event to fetch
Returns:
the desired ActivemathEvent, or null idf no such event was found.
See Also:
org.activemath.xlm.history.XlmHistory#fetchEvent(long)

getHistoryEntries

public List getHistoryEntries(HistoryQuery query)
Returns a list of all stored events that match the supplied query. Be aware that this list might be really big. You might consider calling getNumResults(org.activemath.learner.history.HistoryQuery) first and then using getHistoryEntries(HistoryQuery, int, int).

Specified by:
getHistoryEntries in interface LearnerHistory
Parameters:
query -
Returns:
A list of all events stored in the database matching the given query.

getHistoryEntries

public List getHistoryEntries(HistoryQuery query,
                              int firstResult,
                              int maxResults)
Returns a sublist of the results of the given query, starting at the position firstResult of the complete result list and having a length of at most maxResults. If either firstResult or maxResults is negative (or zero for maxResults), the corresponding value is ignored.

Specified by:
getHistoryEntries in interface LearnerHistory
Parameters:
query - the query to be executed
firstResult - The position of the first result to be included in the returned list. Has to be non-negative.
maxResults - The number of results to include in the returned list. Has to be greater than zero.
Returns:
The sublist of the overall query results starting with the result at the given position and having at most the given length.

getNumResults

public int getNumResults(HistoryQuery query)
gets the number of events stored in the database that match the given query. CAVEAT: Due to filtering of void events, this may not be the actual number of events returned by getHistoryEntries()!

Specified by:
getNumResults in interface LearnerHistory
Parameters:
query - The HistoryQueryto get the number of matching events for.
Returns:
The number of stored events matching the given query

alreadySeen

public boolean alreadySeen(String learnerId,
                           String itemId)
Description copied from interface: LearnerHistory
returns true if an ItemPresentedEvent for the item with the given itemId can ba found, false otherwise.

Specified by:
alreadySeen in interface LearnerHistory