TEntity
- The type of entity in the set.public class EntitySet<TEntity extends IEntityIdentifier> extends Object
Transaction
, guaranteeing snapshot
isolation.Constructor and Description |
---|
EntitySet(TransactionContext context)
Initializes a new instance.
|
EntitySet(TransactionContext context,
Object owner)
Initializes a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Transaction transaction,
TEntity entity)
Adds an entity.
|
void |
addChanged(EventHandler<EntitySetChangedEventArgs<TEntity>> value)
Adds a handler for an event that is raised when entities are added to or removed from this entity set.
|
void |
clear(Transaction transaction)
Removes all entities from this entity set.
|
void |
ensure(Transaction transaction,
Object id)
Ensures that the entity with a specified
EntityIdentifier (get )
is not removed or replaced with a different entity with the same identifier before
a transaction is committed. |
void |
ensureAll(Transaction transaction)
Ensures that the entity set does not change at all before the transaction is committed.
|
TransactionContext |
getContext()
Gets the context used for transactions on this entity set.
|
int |
getCount(Transaction transaction)
Gets the number of entities in this entity set.
|
Collection<TEntity> |
getEntities(Transaction transaction)
Gets a read-only collection of all the entities in the entity set.
|
TEntity |
getEntityById(Transaction transaction,
Object id)
Gets the entity with the given
EntityIdentifier (get ). |
Object |
getOwner()
Gets the owner of this entity set.
|
void |
remove(Transaction transaction,
Object id)
Removes an entity.
|
void |
remove(Transaction transaction,
TEntity entity)
Removes an entity.
|
void |
removeChanged(EventHandler<EntitySetChangedEventArgs<TEntity>> value)
Removes a handler for an event that is raised when entities are added to or removed from this entity set.
|
public EntitySet(@Nonnull TransactionContext context)
context
- The transaction context that is shared by all entities in this entity set.public EntitySet(@Nonnull TransactionContext context, Object owner)
context
- The transaction context that is shared by all entities in this entity set.owner
- The owner of this entity set.public final void addChanged(EventHandler<EntitySetChangedEventArgs<TEntity>> value)
value
- The handler.public final void removeChanged(EventHandler<EntitySetChangedEventArgs<TEntity>> value)
value
- The handler.public final TEntity getEntityById(@Nonnull Transaction transaction, Object id)
EntityIdentifier
(get
).transaction
- The transaction in which to get the entity.id
- The ID of the entity to retrieve.null
if no entity with
the given ID exists.public final int getCount(@Nonnull Transaction transaction)
transaction
- The transaction in which to retrieve the number of entities.@Nonnull public final Collection<TEntity> getEntities(@Nonnull Transaction transaction)
transaction
- The transaction in which to enumerate the entities.public final void add(@Nonnull Transaction transaction, @Nonnull TEntity entity)
transaction
- The transaction in which to add the entity.entity
- The entity to add.public final void remove(@Nonnull Transaction transaction, Object id)
transaction
- The transaction in which to remove the entity.id
- The ID of the entity to remove.public final void remove(@Nonnull Transaction transaction, @Nonnull TEntity entity)
transaction
- The transaction in which to remove the entity.entity
- The entity to remove.public final void clear(@Nonnull Transaction transaction)
transaction
- The transaction in which to remove all entities.public final void ensure(@Nonnull Transaction transaction, Object id)
EntityIdentifier
(get
)
is not removed or replaced with a different entity with the same identifier before
a transaction is committed. If another transaction commits first and removes or replaces
the entity, the transaction will raise a TransactionConflictException
when it is committed. It is valid to call this method with an id
that is not present in the entity set. In that case, a TransactionConflictException
will be thrown if an entity with id
is added to the entity set in
another transaction.transaction
- The transaction for which to ensure an entity identifier.id
- The entity identifier to ensure.public final void ensureAll(@Nonnull Transaction transaction)
TransactionConflictException
when it
is committed.transaction
- The transaction for which the entity set should not change.public final TransactionContext getContext()
public final Object getOwner()