Class MemoryEfficientLazyEntityList
java.lang.Object
ch.tocco.nice2.persist.core.api.entity.AbstractEntityList
ch.tocco.nice2.persist.core.api.hibernate.AbstractLazyEntityList
ch.tocco.nice2.persist.core.api.hibernate.MemoryEfficientLazyEntityList
- All Implemented Interfaces:
EntityList, AutoCloseable, Iterable<Entity>
An implementation of
EntityList that loads the entities in batches (similar to LazyEntityList),
but uses a new Context for every page.
When a new page is loaded, the old Context of the previous page will be closed.
This implementation is efficient when the data is accessed in the order of the list. It's very inefficient
if the elements are accessed randomly.
In addition, entities should only be used within the loop, because not all operations are supported when
the is closed.-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractEntityList
AbstractEntityList.SimpleIteratorNested classes/interfaces inherited from interface EntityList
EntityList.Filter -
Field Summary
Fields inherited from class AbstractLazyEntityList
keys, pageSize -
Constructor Summary
ConstructorsConstructorDescriptionMemoryEfficientLazyEntityList(ContextManager contextManager, PrimaryKeyList keys) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidcontextCreated(Context context) get(int index, boolean eager) Get the entity at the specified index.Get the entity manager.toList()CallingtoList()will lose the memory management functionality, so we just load all entities from the thread context.Methods inherited from class AbstractLazyEntityList
getKey, getKeys, getModel, getPageCount, getPageForIndex, getPageSize, indexOf, setPageSize, size, unwrapMethods inherited from class AbstractEntityList
contains, expect, expectAtLeast, expectAtMost, get, get, get, isEmpty, iterator, toListMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EntityList
doWithSingleResult, doWithSingleResultOr, expectAtMostOrThrow, expectOr, expectOrThrow, getOnlyResult, getOptionalOnlyResult, getOptionalOnlyResult, requireFirstEntity, spliterator, stream
-
Constructor Details
-
MemoryEfficientLazyEntityList
-
-
Method Details
-
get
Description copied from interface:EntityListGet the entity at the specified index.- Specified by:
getin interfaceEntityList- Parameters:
index- The index.eager-true, if a page should be eagerly loaded, if the entity's state ishollow, false otherwise.- Returns:
- The entity at the specified index potentially in
unusable state, ornull. - Throws:
PersistException
-
getManager
Description copied from interface:EntityListGet the entity manager.- Specified by:
getManagerin interfaceEntityList- Returns:
- The entity manager.
-
getFirstEntity
- Specified by:
getFirstEntityin interfaceEntityList- Returns:
- the first entity or null
-
toList
CallingtoList()will lose the memory management functionality, so we just load all entities from the thread context.- Specified by:
toListin interfaceEntityList- Overrides:
toListin classAbstractEntityList
-
contextCreated
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-