org.musicontroller.core
Class EventCountLookup

java.lang.Object
  extended by org.musicontroller.core.EventCountLookup

public class EventCountLookup
extends java.lang.Object

A class for quick eventcount lookup. Songs can have any number of Events. Counting Events, which happens a lot in MusiController, is relatively slow. Events are lazily loaded by Hibernate, thus a call to getEvents() causes an additional DB-access. Caching Events would be a solution, but is not very realistic, because of the sheer amount of them. Since we're mostly interested in counts, this class helps us.

The EventCountLookup takes up only 8 integers and a Date of memory per Song and User. Therefore, caching makes sense for this object. This class contains a LRU-list, to which all lookup-tables are added.

Author:
Varienaja

Field Summary
protected static int CACHESIZE
           
 
Method Summary
 void addEvent(Event event)
          Updates this EventCountLookup object with a new Event.
static EventCountLookup create(java.util.Set<Event> events, long songid)
          Factory method, which returns an EventCountLookup object.
 int getEventCount(long userid, int kind)
          Returns the amount of Events of a certain type.
 int getEventCountLastYear(long userid, int kind)
          Returns the amount of Events of a certain type, which took place in the last year.
 java.util.Date getLastPlay(long userid)
          Looks up the Date of the latest Play-Event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHESIZE

protected static final int CACHESIZE
See Also:
Constant Field Values
Method Detail

create

public static EventCountLookup create(java.util.Set<Event> events,
                                      long songid)
Factory method, which returns an EventCountLookup object. When a cached object is found, it is returned, otherwise a new object is created and added to the cache.

Parameters:
events - The Set of Events, for the Song. (Only accessed when a new EventCountLookup-object must be created. When a cached object is found, the Events are not touched, so that they can stay uninitialized when they were lazily loaded.)
songid - The id of the Song.
Returns:
An initialized EventCountLookup-object.

addEvent

public void addEvent(Event event)
Updates this EventCountLookup object with a new Event.

Parameters:
event - The new Event.

getEventCount

public int getEventCount(long userid,
                         int kind)
Returns the amount of Events of a certain type.

Parameters:
userid - The user to look these Events up for.
kind - The type of Events to look the count up for.
Returns:
The amount of Events.

getEventCountLastYear

public int getEventCountLastYear(long userid,
                                 int kind)
Returns the amount of Events of a certain type, which took place in the last year.

Parameters:
userid - The user to look these Events up for.
kind - The type of Events to look the count up for.
Returns:
The amount of Events.

getLastPlay

public java.util.Date getLastPlay(long userid)
Looks up the Date of the latest Play-Event.

Parameters:
userid - The user to look this Date up for.
Returns:
The Date when this User plays this song for the last time. ( Or null when never played.)


Copyright © 2010 A.J.V.. All Rights Reserved.