Class MemoryEntityList<T extends PersistenceEntity>
- java.lang.Object
-
- com.cmobilecom.af.model.pagination.PageableEntityList<T>
-
- com.cmobilecom.af.model.pagination.MemoryEntityList<T>
-
- Type Parameters:
T
- Entity type.
- All Implemented Interfaces:
java.io.Serializable
public class MemoryEntityList<T extends PersistenceEntity> extends PageableEntityList<T>
MemoryEntityList is a PageableEntityList that holds all the entities in memory.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.cmobilecom.af.model.pagination.PageableEntityList
PageableEntityList.PaginationChangeReason, PageableEntityList.ResultsLimitReason
-
-
Field Summary
-
Fields inherited from class com.cmobilecom.af.model.pagination.PageableEntityList
currentPageIndex, currentPageLeadingStatisticsEntityCount, currentPageOffset, currentPageSize, entitiesAddedOrDeleted, entityListBackingBean, fillBlankRowsIfAdjustForward, LAST_PAGE, nextPageStartEntities, pageCount, pageListener, pageSize, size, statisticsEntity, statisticsMismatchedValueMap, supportVariablePageSize
-
-
Constructor Summary
Constructors Constructor Description MemoryEntityList(MemoryEntityList<T> memoryEntityList)
Copy constructorMemoryEntityList(java.util.List<T> entityList, DataDescriptor dataDescriptor)
ConstructorMemoryEntityList(java.util.List<T> entityList, java.lang.Integer pageSize, DataDescriptor dataDescriptor, ParameterizedMessage title)
ConstructorMemoryEntityList(java.util.List<T> entityList, java.lang.Integer pageSize, DataDescriptor dataDescriptor, java.lang.String title)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAll(java.lang.Integer position, java.util.List<T> entityList)
Insert the entity list at the position.void
addEntity(T entity)
Add the entity to the end of current page.protected void
calculatePageCount(PageableEntityList.PaginationChangeReason reason)
Calculate page count and callPageableEntityList.paginationChanged(Integer, int, PaginationChangeReason)
.void
calculateStatistics()
Calculate the statistics for all the statistics propertiesvoid
clear()
Clear the whole entity list in memory.int
getCurrentPageEntityCount()
Get the number of entities in the current page excluding embedded statistics entities.DataDescriptor
getDataDescriptor()
Get the DataDescriptor of this pageable entity list.java.util.List<T>
getEntitiesToBeDeleted(boolean create)
Get the list of entities that have been removed from memory, but have not been deleted from persistence.T
getEntity(int index)
Get the entity at the specified position.int
getEntityIndex(java.lang.Long entityId)
Get entity index.java.util.List<T>
getEntityList()
Get the entity list of all pagesjava.util.List<T>
getPageEntityList()
Get current page entity listParameterizedMessage
getTitle()
Get the title of this PageableEntityList as the title of its EntityListBackingBean.T
peekEntity(int index)
Peek the entity at the specified position without changing current page index.void
refresh(java.lang.Integer pageIndex, PageableEntityList.PaginationChangeReason reason)
Refresh the page by reloading from persistence.void
reload()
Reload the entities from persistence.void
removeEntitiesFromMemory(java.util.List<T> entitiesToRemove)
Remove the entities from entity list.T
removeEntity(int index)
Remove the entity at the index in memory without updating persistence.void
removeEntity(T entity)
Remove the entity from current page in memory without updating persistence.java.util.List<T>
removeSelectedEntitiesFromMemory()
Remove selected entities from current page in memory.protected void
setCurrentPageIndex(int pageIndex, java.lang.Integer pageOffset, java.lang.Integer maxResults, PageableEntityList.PaginationChangeReason reason)
Set current page index.void
setEntity(int index, T entity)
Set the entity at the index in memory without updating persistence.void
setEntityList(java.util.List<T> entityList)
Set the entity list for all pages.void
setEntityListBackingBean(EntityListBackingBean<T> entityListBackingBean)
Set the EntityListBackingBean to which this pageable entity list belongs.void
setEntityOfCurrentPage(int entityIndex, T entity)
Set the entity at the index in memory without updating persistencevoid
setTitle(ParameterizedMessage title)
Set the title of its EntityListBackingBeanvoid
updateStatisticsEntityPropertyValue(java.lang.String propertyName)
Calculate the statistics for the specified property-
Methods inherited from class com.cmobilecom.af.model.pagination.PageableEntityList
fastForwardPages, fastRewindPages, firstPage, getCurrentPageFirstEntityIndex, getCurrentPageIndex, getCurrentPageLastEntityIndex, getCurrentPageSize, getEntityIndex, getEntityIndexOfCurrentPage, getEntityList, getEntityListBackingBean, getEntityOfCurrentPage, getEntityOfCurrentPage, getIndexWithinCurrentPage, getNextPageStartEntities, getPageCount, getPageIndex, getPageListener, getPageSize, getResultsLimit, getResultsLimitReason, getShownPageIndexList, getSize, getStatisticsEntity, getStatisticsMismatchedValue, isAnyEntityChanged, isEmpty, isEntitiesAddedOrDeleted, isFillBlankRowsIfAdjustForward, isFirstPage, isHasNextPage, isHasPreviousPage, isInCurrentPage, isLastPage, isLastPageFull, isSupportVariablePageSize, jumpToPage, lastPage, nextPage, paginationChanged, previousPage, removeEntityOfCurrentPage, selectAllEntitiesOfCurrentPage, setCurrentPageSize, setEntitiesAddedOrDeleted, setFillBlankRowsIfAdjustForward, setNextPageStartEntities, setPageListener, setPageSize, setPageSize, setStatisticsEntity, setSupportVariablePageSize
-
-
-
-
Constructor Detail
-
MemoryEntityList
public MemoryEntityList(java.util.List<T> entityList, DataDescriptor dataDescriptor)
Constructor- Parameters:
entityList
- all the entitiesdataDescriptor
- the DataDescriptor about the entity list
-
MemoryEntityList
public MemoryEntityList(java.util.List<T> entityList, java.lang.Integer pageSize, DataDescriptor dataDescriptor, ParameterizedMessage title)
Constructor- Parameters:
entityList
- all the entitiespageSize
- page size(entities per page)dataDescriptor
- the DataDescriptor about the entity listtitle
- the title of entity list bean
-
MemoryEntityList
public MemoryEntityList(java.util.List<T> entityList, java.lang.Integer pageSize, DataDescriptor dataDescriptor, java.lang.String title)
Constructor- Parameters:
entityList
- all the entitiespageSize
- page size(entities per page)dataDescriptor
- the DataDescriptor about the entity listtitle
- the title of entity list bean
-
MemoryEntityList
public MemoryEntityList(MemoryEntityList<T> memoryEntityList)
Copy constructor- Parameters:
memoryEntityList
- the MemoryEntityList to copy from
-
-
Method Detail
-
setEntityListBackingBean
public void setEntityListBackingBean(EntityListBackingBean<T> entityListBackingBean) throws SystemException
Description copied from class:PageableEntityList
Set the EntityListBackingBean to which this pageable entity list belongs.- Overrides:
setEntityListBackingBean
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
entityListBackingBean
- an EntityListBackingBean instance- Throws:
SystemException
- throw if an error occurs
-
getPageEntityList
public java.util.List<T> getPageEntityList()
Description copied from class:PageableEntityList
Get current page entity list- Specified by:
getPageEntityList
in classPageableEntityList<T extends PersistenceEntity>
- Returns:
- a list of entities in the current page.
-
calculatePageCount
protected void calculatePageCount(PageableEntityList.PaginationChangeReason reason) throws SystemException
Description copied from class:PageableEntityList
Calculate page count and callPageableEntityList.paginationChanged(Integer, int, PaginationChangeReason)
. Assume size and pageSize have been set. if size is 0, one page with 0 entities.- Overrides:
calculatePageCount
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
reason
- the reason for calculating page count- Throws:
SystemException
- throw if an error occurs
-
setCurrentPageIndex
protected void setCurrentPageIndex(int pageIndex, java.lang.Integer pageOffset, java.lang.Integer maxResults, PageableEntityList.PaginationChangeReason reason) throws SystemException
Description copied from class:PageableEntityList
Set current page index.- Specified by:
setCurrentPageIndex
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
pageIndex
- the new page indexpageOffset
- the first entity index to fetch for the page. if null, default to pageSize * pageIndex.maxResults
- the max number of entities for the page. if null, default to pageSize.reason
- the reason for pagination- Throws:
SystemException
- throw if an error occurs in pagination
-
getEntity
public T getEntity(int index) throws SystemException
Description copied from class:PageableEntityList
Get the entity at the specified position. Load page first if the entity is not in the current page. This method will change current page index.- Specified by:
getEntity
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
index
- entity index in the whole entity list- Returns:
- the entity at the index
- Throws:
SystemException
- throw if an error occurs
-
peekEntity
public T peekEntity(int index)
Description copied from class:PageableEntityList
Peek the entity at the specified position without changing current page index.- Specified by:
peekEntity
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
index
- entity index in the whole entity list- Returns:
- the entity at the index
-
getEntityList
public java.util.List<T> getEntityList()
Get the entity list of all pages- Returns:
- a list of entities
-
setEntityList
public void setEntityList(java.util.List<T> entityList) throws SystemException
Set the entity list for all pages. Recalculate page count and statistics.- Parameters:
entityList
- the new entity list- Throws:
SystemException
- throw if an error occurs in calculating page count and statistics.
-
getCurrentPageEntityCount
public int getCurrentPageEntityCount()
Description copied from class:PageableEntityList
Get the number of entities in the current page excluding embedded statistics entities.- Specified by:
getCurrentPageEntityCount
in classPageableEntityList<T extends PersistenceEntity>
- Returns:
- entity count
-
addEntity
public void addEntity(T entity) throws SystemException
Description copied from class:PageableEntityList
Add the entity to the end of current page.- Specified by:
addEntity
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
entity
- the entity to add- Throws:
SystemException
- throw if an error occurs
-
addAll
public void addAll(java.lang.Integer position, java.util.List<T> entityList) throws SystemException
Description copied from class:PageableEntityList
Insert the entity list at the position.- Specified by:
addAll
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
position
- the position within current page. If null, append the entities to the end of current page.entityList
- the list of entities to add- Throws:
SystemException
- throw if an error occurs
-
clear
public void clear() throws SystemException
Description copied from class:PageableEntityList
Clear the whole entity list in memory.- Specified by:
clear
in classPageableEntityList<T extends PersistenceEntity>
- Throws:
SystemException
- throw if an error occurs in updating page count and statistics
-
removeSelectedEntitiesFromMemory
public java.util.List<T> removeSelectedEntitiesFromMemory() throws SystemException
Remove selected entities from current page in memory. Recalculate page count and statistics.- Specified by:
removeSelectedEntitiesFromMemory
in classPageableEntityList<T extends PersistenceEntity>
- Returns:
- the list of entities removed
- Throws:
SystemException
- throw if an error occurs
-
removeEntitiesFromMemory
public void removeEntitiesFromMemory(java.util.List<T> entitiesToRemove) throws SystemException
Remove the entities from entity list. The entities can be in different pages. Recalculate page count and statistics.- Specified by:
removeEntitiesFromMemory
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
entitiesToRemove
- the entities to remove- Throws:
SystemException
- throw if an error occurs in calculating page count and statistics.
-
removeEntity
public T removeEntity(int index) throws SystemException
Description copied from class:PageableEntityList
Remove the entity at the index in memory without updating persistence. Assume that the entity has been removed from persistence- Specified by:
removeEntity
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
index
- the entity index in the whole list- Returns:
- the removed entity if exist, null otherwise
- Throws:
SystemException
- throw if an error occurs
-
removeEntity
public void removeEntity(T entity) throws SystemException
Description copied from class:PageableEntityList
Remove the entity from current page in memory without updating persistence.- Specified by:
removeEntity
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
entity
- the entity to be removed- Throws:
SystemException
- throw if an error occurs
-
setEntity
public void setEntity(int index, T entity) throws SystemException
Description copied from class:PageableEntityList
Set the entity at the index in memory without updating persistence. If the entity is not in the current page, change current page to the page that contains the entity.- Specified by:
setEntity
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
index
- the entity index in the whole listentity
- the new entity to set- Throws:
SystemException
- throw if an error occurs
-
setEntityOfCurrentPage
public void setEntityOfCurrentPage(int entityIndex, T entity) throws SystemException
Description copied from class:PageableEntityList
Set the entity at the index in memory without updating persistence- Specified by:
setEntityOfCurrentPage
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
entityIndex
- the entity index within current page starting from 0entity
- the entity to set- Throws:
SystemException
- throw if an error occurs
-
getTitle
public ParameterizedMessage getTitle()
Description copied from class:PageableEntityList
Get the title of this PageableEntityList as the title of its EntityListBackingBean.- Specified by:
getTitle
in classPageableEntityList<T extends PersistenceEntity>
- Returns:
- ParameterizedMessage instance
-
setTitle
public void setTitle(ParameterizedMessage title)
Set the title of its EntityListBackingBean- Parameters:
title
- the title to set
-
getDataDescriptor
public DataDescriptor getDataDescriptor()
Description copied from class:PageableEntityList
Get the DataDescriptor of this pageable entity list.- Specified by:
getDataDescriptor
in classPageableEntityList<T extends PersistenceEntity>
- Returns:
- DataDescriptor instance
-
reload
public void reload()
Description copied from class:PageableEntityList
Reload the entities from persistence. The entities in memory may become stale and not usable possibly due to the transaction exception.- Specified by:
reload
in classPageableEntityList<T extends PersistenceEntity>
-
refresh
public void refresh(java.lang.Integer pageIndex, PageableEntityList.PaginationChangeReason reason)
Description copied from class:PageableEntityList
Refresh the page by reloading from persistence. Called when underlying database or query criteria is changed, which may have affected search results.- Specified by:
refresh
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
pageIndex
- the index of the page to refresh. if null, default to the current page index.reason
- PaginationChangeReason
-
getEntityIndex
public int getEntityIndex(java.lang.Long entityId)
Get entity index.- Parameters:
entityId
- the id of the entity to get- Returns:
- -1 if not found.
-
calculateStatistics
public void calculateStatistics() throws SystemException
Description copied from class:PageableEntityList
Calculate the statistics for all the statistics properties- Specified by:
calculateStatistics
in classPageableEntityList<T extends PersistenceEntity>
- Throws:
SystemException
- throw if an error occurs
-
updateStatisticsEntityPropertyValue
public void updateStatisticsEntityPropertyValue(java.lang.String propertyName) throws SystemException
Description copied from class:PageableEntityList
Calculate the statistics for the specified property- Specified by:
updateStatisticsEntityPropertyValue
in classPageableEntityList<T extends PersistenceEntity>
- Parameters:
propertyName
- the name of the property whose statistics will be recalculated- Throws:
SystemException
- throw if an error occurs
-
getEntitiesToBeDeleted
public java.util.List<T> getEntitiesToBeDeleted(boolean create)
Get the list of entities that have been removed from memory, but have not been deleted from persistence. Entities can be added to or removed from the list.- Parameters:
create
- whether to create empty list if null.- Returns:
- a list of entities
-
-