Class ToManyRelationAdapter
java.lang.Object
ch.tocco.nice2.persist.core.api.entity.AbstractEntityList
ch.tocco.nice2.persist.core.impl.hibernate.pojo.relation.AbstractRelationAdapter
ch.tocco.nice2.persist.core.impl.hibernate.pojo.relation.ToManyRelationAdapter
- All Implemented Interfaces:
EntityList
,Relation
,Iterable<Entity>
Maps a to-many hibernate collection to the
Relation
interface
Note: size() might execute a database query - therefore we do not use
size() if we intend to access all entities anyway (toList() or iterator()).-
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.impl.hibernate.pojo.relation.AbstractRelationAdapter
entityFacadeListenerManager, relationInterceptor, relationModel, sourceEntity
-
Constructor Summary
ConstructorDescriptionToManyRelationAdapter
(Entity sourceEntity, Set<Entity> entities, RelationModel relationModel, EntityFacadeListenerManager entityFacadeListenerManager, EntityInterceptor entityInterceptor, ch.tocco.nice2.persist.core.impl.hibernate.pojo.relation.CollectionInitializerEvaluator collectionInitializerEvaluator) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all entities in this relation.get
(int index, boolean eager) Get the entity at the specified index.iterator()
The iterator of the superclass usesEntityList.size()
which might cause a query in this implementation.void
Creates an intersection of the currently linked ones and the given ones, and then callsRelation.remove(ch.tocco.nice2.persist.core.api.entity.Entity)
andRelation.add(ch.tocco.nice2.persist.core.api.entity.Entity)
in a loop.protected void
setInverseRelation
(Entity entity, boolean added) int
size()
Get the number of entities this list contains.Methods inherited from class ch.tocco.nice2.persist.core.impl.hibernate.pojo.relation.AbstractRelationAdapter
add, expect, expectAtLeast, expectAtMost, fireRelationChangingEvent, get, getKey, getKeys, getManager, getModel, getPageCount, getPageSize, getRelationModel, getSource, indexOf, remove, set, setPageSize, unwrap, verifyTransactionIsRunning
Methods inherited from class ch.tocco.nice2.persist.core.api.entity.AbstractEntityList
contains, get, get, get, isEmpty, toList, 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
contains, doWithSingleResult, doWithSingleResultOr, expectOr, get, getFirstEntity, getOnlyResult, getOptionalOnlyResult, getOptionalOnlyResult, isEmpty, requireFirstEntity, spliterator, stream, toList, toList
Methods inherited from interface ch.tocco.nice2.persist.core.api.entity.Relation
expectAtMostOrThrow, expectOrThrow, get, get
-
Constructor Details
-
ToManyRelationAdapter
public ToManyRelationAdapter(Entity sourceEntity, Set<Entity> entities, RelationModel relationModel, EntityFacadeListenerManager entityFacadeListenerManager, EntityInterceptor entityInterceptor, ch.tocco.nice2.persist.core.impl.hibernate.pojo.relation.CollectionInitializerEvaluator collectionInitializerEvaluator)
-
-
Method Details
-
getInnerInterceptor
- Specified by:
getInnerInterceptor
in classAbstractRelationAdapter
-
setInverseRelation
-
set
Description copied from interface:Relation
Creates an intersection of the currently linked ones and the given ones, and then callsRelation.remove(ch.tocco.nice2.persist.core.api.entity.Entity)
andRelation.add(ch.tocco.nice2.persist.core.api.entity.Entity)
in a loop.- Parameters:
entities
- The list of entities that will be the only linked ones.
-
clear
public void clear()Description copied from interface:Relation
Removes all entities in this relation. Does the same as calling remove() for all linked entities. -
get
Description copied from interface:EntityList
Get the entity at the specified index.- 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
.
-
size
public int size()Description copied from interface:EntityList
Get the number of entities this list contains.- Returns:
- The number of entities.
-
iterator
The iterator of the superclass usesEntityList.size()
which might cause a query in this implementation. Therefore we avoid this unnecessary query as the collection will initialized anyway.- Specified by:
iterator
in interfaceIterable<Entity>
- Overrides:
iterator
in classAbstractEntityList
-