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.SimpleIterator
Nested classes/interfaces inherited from interface ch.tocco.nice2.persist.core.api.entity.EntityList
EntityList.Filter
-
Field Summary
Modifier and TypeFieldDescriptionprotected final EntityFacadeListenerManager
protected final RelationInterceptor
protected final RelationModel
protected final Entity
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractRelationAdapter
(RelationModel relationModel, Entity sourceEntity, EntityFacadeListenerManager entityFacadeListenerManager, EntityInterceptor entityInterceptor) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add 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 void
fireRelationChangingEvent
(Entity relatedEntity, boolean added, boolean adjusting) @Nullable Entity
get()
Get the current single target entity of this relation.abstract RelationInterceptor
getKey
(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.int
Get the number of pages in this list.int
Get the current page size.int
indexOf
(PrimaryKey key) Get the index within the list of the entity with the specified key.void
Remove an entity from the relation.void
Set the relation's entities to the specified single entity.void
setPageSize
(int pageSize) Set the page size.unwrap()
Unwrap to the underlying entity list.protected void
verifyTransactionIsRunning
(Context context) Methods inherited from class ch.tocco.nice2.persist.core.api.entity.AbstractEntityList
contains, get, get, get, isEmpty, iterator, 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, get, getFirstEntity, getOnlyResult, getOptionalOnlyResult, getOptionalOnlyResult, isEmpty, requireFirstEntity, size, spliterator, stream, toList, toList
Methods 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:Relation
Add 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:Relation
Remove an entity from the relation.TODO document what happens when the entity is not in the relation.
-
set
Description copied from interface:Relation
Set 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:Relation
Get the current single target entity of this relation. This method may only be called for relations to a single entity (n-1).- Specified by:
get
in interfaceRelation
- Returns:
- The current single target entity potentially in
unusable state
, ornull
.
-
expect
Description copied from interface:EntityList
Throws if the list does not contain exactly that amount.Example:
EntityList entityList = myQuery.execute(1).expect(1);
- Specified by:
expect
in interfaceEntityList
- Specified by:
expect
in interfaceRelation
- Overrides:
expect
in classAbstractEntityList
- Parameters:
amount
- The expected amount.- Returns:
- The list itself.
- See Also:
-
expectAtLeast
Description copied from interface:EntityList
Throws if the list contains fewer than min items.Example:
EntityList entityList = myQuery.execute().expectAtLeast(3);
- Specified by:
expectAtLeast
in interfaceEntityList
- Specified by:
expectAtLeast
in interfaceRelation
- Overrides:
expectAtLeast
in classAbstractEntityList
- Parameters:
min
- The expected minimal amount, including.- Returns:
- The list itself.
- See Also:
-
expectAtMost
Description copied from interface:EntityList
Throws if the list contains more than max items.Example:
EntityList entityList = myQuery.execute(3).expectAtMost(3);
- Specified by:
expectAtMost
in interfaceEntityList
- Specified by:
expectAtMost
in interfaceRelation
- Overrides:
expectAtMost
in classAbstractEntityList
- Parameters:
max
- The expected maximal amount, including.- Returns:
- The list itself.
- See Also:
-
getModel
Description copied from interface:EntityList
Get the model of the entity type contained in this list.- Specified by:
getModel
in interfaceEntityList
- Returns:
- The model of the entity type contained in this list.
-
getManager
Description copied from interface:EntityList
Get the entity manager.- Specified by:
getManager
in interfaceEntityList
- Returns:
- The entity manager.
-
getSource
-
getRelationModel
- Specified by:
getRelationModel
in interfaceRelation
-
unwrap
Description copied from interface:EntityList
Unwrap 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:
unwrap
in interfaceEntityList
- Specified by:
unwrap
in interfaceRelation
- Returns:
- The underlying entity list implementation.
-
setPageSize
public void setPageSize(int pageSize) Description copied from interface:EntityList
Set the page size. The page size determines how many objects will be loaded, once ahollow
entity has been accessed.- Specified by:
setPageSize
in interfaceEntityList
- Parameters:
pageSize
- The new page size.
-
getPageSize
public int getPageSize()Description copied from interface:EntityList
Get the current page size.- Specified by:
getPageSize
in interfaceEntityList
- Returns:
- The current page size.
-
getPageCount
public int getPageCount()Description copied from interface:EntityList
Get the number of pages in this list.- Specified by:
getPageCount
in interfaceEntityList
- Returns:
- The number of pages in this list
(
size/pageSize + (size%pageSize>0 ? 1 : 0)
).
-
getKeys
Description copied from interface:Relation
WARNING: 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:
getKeys
in interfaceEntityList
- Specified by:
getKeys
in interfaceRelation
- Returns:
- A defensive copy of the array. The size matches the
EntityList.size()
method.
-
getKey
Description copied from interface:EntityList
Returns the PrimaryKey at the specified position.- Specified by:
getKey
in interfaceEntityList
-
indexOf
Description copied from interface:EntityList
Get the index within the list of the entity with the specified key.- Specified by:
indexOf
in interfaceEntityList
- Parameters:
key
- The primary key.- Returns:
- The index or -1, if there's no such entity in the list.
-
fireRelationChangingEvent
-
verifyTransactionIsRunning
-