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 ch.tocco.nice2.persist.core.api.entity.AbstractEntityList
AbstractEntityList.SimpleIterator
Nested classes/interfaces inherited from interface ch.tocco.nice2.persist.core.api.entity.EntityList
EntityList.Filter
-
Field Summary
Fields inherited from class ch.tocco.nice2.persist.core.api.hibernate.AbstractLazyEntityList
keys, pageSize
-
Constructor Summary
ConstructorDescriptionMemoryEfficientLazyEntityList
(ContextManager contextManager, PrimaryKeyList keys) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected void
contextCreated
(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 ch.tocco.nice2.persist.core.api.hibernate.AbstractLazyEntityList
getKey, getKeys, getModel, getPageCount, getPageForIndex, getPageSize, indexOf, setPageSize, size, unwrap
Methods inherited from class ch.tocco.nice2.persist.core.api.entity.AbstractEntityList
contains, expect, expectAtLeast, expectAtMost, get, get, get, isEmpty, iterator, toList
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.tocco.nice2.persist.core.api.entity.EntityList
doWithSingleResult, doWithSingleResultOr, expectAtMostOrThrow, expectOr, expectOrThrow, getOnlyResult, getOptionalOnlyResult, getOptionalOnlyResult, requireFirstEntity, spliterator, stream
-
Constructor Details
-
MemoryEfficientLazyEntityList
-
-
Method Details
-
get
Description copied from interface:EntityList
Get the entity at the specified index.- Specified by:
get
in 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:EntityList
Get the entity manager.- Specified by:
getManager
in interfaceEntityList
- Returns:
- The entity manager.
-
getFirstEntity
- Specified by:
getFirstEntity
in 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:
toList
in interfaceEntityList
- Overrides:
toList
in classAbstractEntityList
-
contextCreated
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-