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.SimpleIteratorNested 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
ConstructorsConstructorDescriptionToManyRelationAdapter(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 TypeMethodDescriptionvoidclear()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.voidCreates 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 voidsetInverseRelation(Entity entity, boolean added) intsize()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, verifyTransactionIsRunningMethods inherited from class ch.tocco.nice2.persist.core.api.entity.AbstractEntityList
contains, get, get, get, isEmpty, toList, toListMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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, toListMethods 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:
getInnerInterceptorin classAbstractRelationAdapter
-
setInverseRelation
-
set
Description copied from interface:RelationCreates 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:RelationRemoves all entities in this relation. Does the same as calling remove() for all linked entities. -
get
Description copied from interface:EntityListGet 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:EntityListGet 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:
iteratorin interfaceIterable<Entity>- Overrides:
iteratorin classAbstractEntityList
-