Package com.tagtraum.beatunes.analysis
Class HibernateTaskQueue
- java.lang.Object
-
- com.tagtraum.beatunes.analysis.HibernateTaskQueue
-
- All Implemented Interfaces:
TaskQueue
,PageCacheDataSource<SongTask>
,ApplicationComponent<BeaTunes>
,ListModel
public class HibernateTaskQueue extends Object implements TaskQueue, PageCacheDataSource<SongTask>
Hibernate task queue.- Author:
- Hendrik Schreiber
-
-
Constructor Summary
Constructors Constructor Description HibernateTaskQueue()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListDataListener(ListDataListener l)
void
clear()
org.hibernate.Query
createPageQuery(org.hibernate.Session session)
Creates a query that selects persistent objects in the right order.BeaTunes
getApplication()
Returns the main application component.Task
getElementAt(int index)
Return task with given index.HibernateUtil
getHibernateUtil()
String
getId()
Unique id for each instance of this object.Long
getId(SongTask songTask)
Needs to be implemented to get the persistent id of the objects that are cached in this cache.IndexedId[]
getIds(org.hibernate.Session session)
A complete list of sorted ids along with their natural indices.int
getSize()
List<Long>
getSongIdsForTasksUsingOnlineResources()
Ids for tasks that use online resources.PlayList.SortDirection
getSortDirection()
String
getSortProperty()
SongTask
getWithId(org.hibernate.Session session, Long id)
List<SongTask>
getWithIds(org.hibernate.Session session, Long... ids)
Creates a query that selects persistent objects in the right order.int
indexOf(long id)
Returns the index of a given Task or-1
if not found or not displayed.int
indexOf(Object object)
Returns the index of a given Task or-1
if not found or not displayed.void
init()
Initializes this component and its sub-components.boolean
isEmpty()
void
objectsAvailable(int index0, int index1)
Notifies the data source, that the given index range has been loaded.List<Long>
offer(List<Long> songIds, TaskFactory taskFactory, DiscreteProgressListener discreteProgressListener)
Create tasks using the provided factory and list of song ids and add them to the queue.Task
poll(long timeout, TimeUnit unit)
boolean
remove(Task task)
void
removeListDataListener(ListDataListener l)
void
setApplication(BeaTunes beaTunes)
Sets the main application component.void
setHibernateUtil(HibernateUtil hibernateUtil)
void
setSortDirection(PlayList.SortDirection sortDirection)
void
setSortProperty(String sortProperty)
void
shutdown()
Shuts down this component and its sub-components.
-
-
-
Method Detail
-
getHibernateUtil
public HibernateUtil getHibernateUtil()
- Specified by:
getHibernateUtil
in interfacePageCacheDataSource<SongTask>
- Returns:
- hibernate utilities
-
setHibernateUtil
public void setHibernateUtil(HibernateUtil hibernateUtil)
-
getId
public Long getId(SongTask songTask)
Description copied from interface:PageCacheDataSource
Needs to be implemented to get the persistent id of the objects that are cached in this cache.- Specified by:
getId
in interfacePageCacheDataSource<SongTask>
- Parameters:
songTask
- some persistent object- Returns:
- persistent id
-
getWithId
public SongTask getWithId(org.hibernate.Session session, Long id)
- Specified by:
getWithId
in interfacePageCacheDataSource<SongTask>
- Parameters:
session
- sessionid
- id of the object we are looking for- Returns:
- the persistent object or null, if not found
- See Also:
PageCacheDataSource.getWithIds(Session, Long...)
-
getWithIds
public List<SongTask> getWithIds(org.hibernate.Session session, Long... ids)
Description copied from interface:PageCacheDataSource
Creates a query that selects persistent objects in the right order. query.setMaxResults(..) and query.setFirstResult(..) are set by the caller.- Specified by:
getWithIds
in interfacePageCacheDataSource<SongTask>
- Parameters:
session
- sessionids
- ids of the objects we are looking for- Returns:
- list of objects. not found objects are
null
- See Also:
PageCacheDataSource.getWithId(Session, Long)
-
getIds
public IndexedId[] getIds(org.hibernate.Session session)
Description copied from interface:PageCacheDataSource
A complete list of sorted ids along with their natural indices. Indices of filtered out objects are flipped:-(index+1)
- Specified by:
getIds
in interfacePageCacheDataSource<SongTask>
- Parameters:
session
- hibernate session- Returns:
- a complete list of persistent ids
-
createPageQuery
public org.hibernate.Query createPageQuery(org.hibernate.Session session)
Description copied from interface:PageCacheDataSource
Creates a query that selects persistent objects in the right order. query.setMaxResults(..) and query.setFirstResult(..) are set by the caller.- Specified by:
createPageQuery
in interfacePageCacheDataSource<SongTask>
- Parameters:
session
- session- Returns:
- a query that returns objects in the right order or null, if such a query cannot be constructed
-
objectsAvailable
public void objectsAvailable(int index0, int index1)
Description copied from interface:PageCacheDataSource
Notifies the data source, that the given index range has been loaded.- Specified by:
objectsAvailable
in interfacePageCacheDataSource<SongTask>
- Parameters:
index0
- start indexindex1
- end index (inclusive)
-
setApplication
public void setApplication(BeaTunes beaTunes)
Description copied from interface:ApplicationComponent
Sets the main application component.- Specified by:
setApplication
in interfaceApplicationComponent<BeaTunes>
- Specified by:
setApplication
in interfaceTaskQueue
- Parameters:
beaTunes
- beaTunes instance
-
getApplication
public BeaTunes getApplication()
Description copied from interface:ApplicationComponent
Returns the main application component.- Specified by:
getApplication
in interfaceApplicationComponent<BeaTunes>
- Returns:
- application object
-
getId
public String getId()
Description copied from interface:ApplicationComponent
Unique id for each instance of this object.- Specified by:
getId
in interfaceApplicationComponent<BeaTunes>
- Returns:
- id
-
init
public void init()
Description copied from interface:ApplicationComponent
Initializes this component and its sub-components.- Specified by:
init
in interfaceApplicationComponent<BeaTunes>
-
shutdown
public void shutdown()
Description copied from interface:ApplicationComponent
Shuts down this component and its sub-components.- Specified by:
shutdown
in interfaceApplicationComponent<BeaTunes>
-
getElementAt
public Task getElementAt(int index)
Description copied from interface:TaskQueue
Return task with given index.- Specified by:
getElementAt
in interfaceListModel
- Specified by:
getElementAt
in interfaceTaskQueue
- Parameters:
index
- index- Returns:
- task or null, if there is no task with the given index.
-
indexOf
public int indexOf(Object object)
Description copied from interface:TaskQueue
Returns the index of a given Task or-1
if not found or not displayed.
-
indexOf
public int indexOf(long id)
Description copied from interface:TaskQueue
Returns the index of a given Task or-1
if not found or not displayed.
-
offer
public List<Long> offer(List<Long> songIds, TaskFactory taskFactory, DiscreteProgressListener discreteProgressListener)
Description copied from interface:TaskQueue
Create tasks using the provided factory and list of song ids and add them to the queue.
-
poll
public Task poll(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
poll
in interfaceTaskQueue
- Throws:
InterruptedException
- See Also:
BlockingQueue.poll(long, java.util.concurrent.TimeUnit)
-
getSongIdsForTasksUsingOnlineResources
public List<Long> getSongIdsForTasksUsingOnlineResources()
Description copied from interface:TaskQueue
Ids for tasks that use online resources.- Specified by:
getSongIdsForTasksUsingOnlineResources
in interfaceTaskQueue
- Returns:
- list of ids.
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceTaskQueue
- See Also:
Collection.isEmpty()
-
remove
public boolean remove(Task task)
- Specified by:
remove
in interfaceTaskQueue
- See Also:
BlockingQueue.remove(Object)
-
clear
public void clear()
- Specified by:
clear
in interfaceTaskQueue
- See Also:
Collection.clear()
-
setSortProperty
public void setSortProperty(String sortProperty)
- Specified by:
setSortProperty
in interfaceTaskQueue
-
getSortProperty
public String getSortProperty()
- Specified by:
getSortProperty
in interfaceTaskQueue
-
setSortDirection
public void setSortDirection(PlayList.SortDirection sortDirection)
- Specified by:
setSortDirection
in interfaceTaskQueue
-
getSortDirection
public PlayList.SortDirection getSortDirection()
- Specified by:
getSortDirection
in interfaceTaskQueue
-
addListDataListener
public void addListDataListener(ListDataListener l)
- Specified by:
addListDataListener
in interfaceListModel
-
removeListDataListener
public void removeListDataListener(ListDataListener l)
- Specified by:
removeListDataListener
in interfaceListModel
-
-