Class AbstractRelationAdapter
- All Implemented Interfaces:
EntityList,Relation,Iterable<Entity>
- Direct Known Subclasses:
ToManyRelationAdapter,ToOneRelationAdapter
Relation interface-
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
FieldsModifier and TypeFieldDescriptionprotected final EntityFacadeListenerManagerprotected final RelationInterceptorprotected final RelationModelprotected final Entity -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractRelationAdapter(RelationModel relationModel, Entity sourceEntity, EntityFacadeListenerManager entityFacadeListenerManager, EntityInterceptor entityInterceptor) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an entity to the relation.expect(int amount) Throws if the list does not contain exactly that amount.expectAtLeast(int min) Throws if the list contains fewer than min items.expectAtMost(int max) Throws if the list contains more than max items.protected voidfireRelationChangingEvent(Entity relatedEntity, boolean added, boolean adjusting) @Nullable Entityget()Get the current single target entity of this relation.abstract RelationInterceptorgetKey(int index) Returns the PrimaryKey at the specified position.getKeys()WARNING: this impl may return null entries! This happens when entities of state conception are in the list.Get the entity manager.getModel()Get the model of the entity type contained in this list.intGet the number of pages in this list.intGet the current page size.intindexOf(PrimaryKey key) Get the index within the list of the entity with the specified key.voidRemove an entity from the relation.voidSet the relation's entities to the specified single entity.voidsetPageSize(int pageSize) Set the page size.unwrap()Unwrap to the underlying entity list.protected voidverifyTransactionIsRunning(Context context) Methods inherited from class ch.tocco.nice2.persist.core.api.entity.AbstractEntityList
contains, get, get, get, isEmpty, iterator, 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, get, getFirstEntity, getOnlyResult, getOptionalOnlyResult, getOptionalOnlyResult, isEmpty, requireFirstEntity, size, spliterator, stream, toList, toListMethods inherited from interface ch.tocco.nice2.persist.core.api.entity.Relation
clear, expectAtMostOrThrow, expectOrThrow, get, get, set
-
Field Details
-
relationModel
-
sourceEntity
-
entityFacadeListenerManager
-
relationInterceptor
-
-
Constructor Details
-
AbstractRelationAdapter
protected AbstractRelationAdapter(RelationModel relationModel, Entity sourceEntity, EntityFacadeListenerManager entityFacadeListenerManager, EntityInterceptor entityInterceptor)
-
-
Method Details
-
getInnerInterceptor
-
add
Description copied from interface:RelationAdd an entity to the relation.If the entity is in the relation already then the call is ignored; no exception thrown, no events fired. (i'm sure about the exception, but not about the events. -andrej)
If this is a to-one relation then you are advised to use the
Relation.set(ch.tocco.nice2.persist.core.api.entity.Entity)method. If you still decide to use add() then you also need to call remove() with the old value if there was an entity linked already.Relation.set(ch.tocco.nice2.persist.core.api.entity.Entity)takes care of all this for you. -
remove
Description copied from interface:RelationRemove an entity from the relation.TODO document what happens when the entity is not in the relation.
-
set
Description copied from interface:RelationSet the relation's entities to the specified single entity. Any other entities will be removed. This method may only be called for relations to a single entity (n-1).NOTE: This calls
Relation.remove(ch.tocco.nice2.persist.core.api.entity.Entity)andRelation.add(ch.tocco.nice2.persist.core.api.entity.Entity)internally. That's also why the interceptor does not have this. -
get
Description copied from interface:RelationGet the current single target entity of this relation. This method may only be called for relations to a single entity (n-1).- Specified by:
getin interfaceRelation- Returns:
- The current single target entity potentially in
unusable state, ornull.
-
expect
Description copied from interface:EntityListThrows if the list does not contain exactly that amount.Example:
EntityList entityList = myQuery.execute(1).expect(1);- Specified by:
expectin interfaceEntityList- Specified by:
expectin interfaceRelation- Overrides:
expectin classAbstractEntityList- Parameters:
amount- The expected amount.- Returns:
- The list itself.
- See Also:
-
expectAtLeast
Description copied from interface:EntityListThrows if the list contains fewer than min items.Example:
EntityList entityList = myQuery.execute().expectAtLeast(3);- Specified by:
expectAtLeastin interfaceEntityList- Specified by:
expectAtLeastin interfaceRelation- Overrides:
expectAtLeastin classAbstractEntityList- Parameters:
min- The expected minimal amount, including.- Returns:
- The list itself.
- See Also:
-
expectAtMost
Description copied from interface:EntityListThrows if the list contains more than max items.Example:
EntityList entityList = myQuery.execute(3).expectAtMost(3);- Specified by:
expectAtMostin interfaceEntityList- Specified by:
expectAtMostin interfaceRelation- Overrides:
expectAtMostin classAbstractEntityList- Parameters:
max- The expected maximal amount, including.- Returns:
- The list itself.
- See Also:
-
getModel
Description copied from interface:EntityListGet the model of the entity type contained in this list.- Specified by:
getModelin interfaceEntityList- Returns:
- The model of the entity type contained in this list.
-
getManager
Description copied from interface:EntityListGet the entity manager.- Specified by:
getManagerin interfaceEntityList- Returns:
- The entity manager.
-
getSource
-
getRelationModel
- Specified by:
getRelationModelin interfaceRelation
-
unwrap
Description copied from interface:EntityListUnwrap to the underlying entity list. Wrappers of entity lists should delegate this to the list they're wrapping, implementations returnthis. It may be that they cannot, and then return themselves (MultiEntityList).- Specified by:
unwrapin interfaceEntityList- Specified by:
unwrapin interfaceRelation- Returns:
- The underlying entity list implementation.
-
setPageSize
public void setPageSize(int pageSize) Description copied from interface:EntityListSet the page size. The page size determines how many objects will be loaded, once ahollowentity has been accessed.- Specified by:
setPageSizein interfaceEntityList- Parameters:
pageSize- The new page size.
-
getPageSize
public int getPageSize()Description copied from interface:EntityListGet the current page size.- Specified by:
getPageSizein interfaceEntityList- Returns:
- The current page size.
-
getPageCount
public int getPageCount()Description copied from interface:EntityListGet the number of pages in this list.- Specified by:
getPageCountin interfaceEntityList- Returns:
- The number of pages in this list
(
size/pageSize + (size%pageSize>0 ? 1 : 0)).
-
getKeys
Description copied from interface:RelationWARNING: this impl may return null entries! This happens when entities of state conception are in the list. Also, after a commit this data is outdated, see class header.- Specified by:
getKeysin interfaceEntityList- Specified by:
getKeysin interfaceRelation- Returns:
- A defensive copy of the array. The size matches the
EntityList.size()method.
-
getKey
Description copied from interface:EntityListReturns the PrimaryKey at the specified position.- Specified by:
getKeyin interfaceEntityList
-
indexOf
Description copied from interface:EntityListGet the index within the list of the entity with the specified key.- Specified by:
indexOfin interfaceEntityList- Parameters:
key- The primary key.- Returns:
- The index or -1, if there's no such entity in the list.
-
fireRelationChangingEvent
-
verifyTransactionIsRunning
-