Class JPAContainer<T>
- All Implemented Interfaces:
Buffered,Container,Container.Filterable,Container.Hierarchical,Container.Indexed,Container.ItemSetChangeNotifier,Container.Ordered,Container.Sortable,AdvancedFilterable,EntityContainer<T>,EntityProviderChangeListener<T>,HierarchicalEntityContainer<T>,Serializable
EntityContainer). You can use it in your
applications like so:
EntityContainer<MyEntity> container = new JPAContainer<MyEntity>(
MyEntity.class);
container.setEntityProvider(myEntityProvider);
...
myTable.setContainerDataSource(container);
In the example code, myEntityProvider is an
instance of an EntityProvider that, like the name suggests, is
responsible for providing the entities to the container. If the container
should be writable, the entity provider must implement the
MutableEntityProvider interface and if buffering is desired (i.e.
write-through turned off) the BatchableEntityProvider interface as
well. There are ready-made implementations of all these interfaces that can
be used out-of-the-box (check the See Also section of this Javadoc).
All sorting and filtering is handled by the entity provider, which in turn normally delegates it to the database. Therefore, only persistent properties can be filtered and/or sorted by.
It is possible to use JPAContainer as a hierarchical container if the entities in the container can be related to each other by means of a parent property. For example:
@Entity
public class Node {
...
@ManyToOne
private Node parent;
...
}
Note, however, that the implementation of HierarchicalEntityContainer
is still experimental and has some limitations. For example, the data is
always read directly from the entity provider regardless of whether buffering
is used or not. Therefore, this feature should be used with care in
production systems.
Buffering
Here follows some notes on how buffering has been implemented in this class. If you are not going to use buffering, you can skip this section.When using buffered mode, the following rules apply:
- All operations that add, update or remove entities are recorded internally.
- If an item is added and then removed later within the same transaction, the add operation will be removed and no update operation will be recorded.
- If an item is added and then updated later within the same transaction, only the add operation will be recorded.
- If an item is updated and then removed later within the same transaction, only the remove operation will be recorded.
- In the case of an update or edit all changes are applied at once.
- When the changes are committed, all recorded operations are carried out
on the
BatchableEntityProviderin the same order that they were recorded.
Please note, that if an entity is modified twice or more, updates are
"merged". This is something that implementations of
BatchableEntityProvider need to be aware of.
Also note, that it is possible to use buffered mode even if the entities
returned from the entity provider are not explicitly detached (see
EntityProvider.isEntitiesDetached()), but this should be avoided
unless you know what you are doing.
- Since:
- 1.0
- Author:
- Petter Holmström (Vaadin Ltd)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classfinal classEvent indicating that all the items have been removed from the container.final classEvent indicating that the changes have been committed.final classEvent indicating that the changes have been discarded.final classEvent indicating that the container has been resorted.final classEvent indicating that an item has been added to the container.classAbstract base class for events concerning singleEntityItems.final classEvent fired bycontainsId(java.lang.Object)when the result is false andisContainsIdFiresItemSetChangeIfNotFound()is true.final classEvent indicating that an item has been removed from the container.final classEvent indicating that an item has been updated inside the container.final classEvent fired when aEntityProviderChangeEventis received by the container.Nested classes/interfaces inherited from interface com.vaadin.featurepack.data.jpacontainer.AdvancedFilterable
AdvancedFilterable.FiltersAppliedEvent<C extends Container & AdvancedFilterable>Nested classes/interfaces inherited from interface com.vaadin.featurepack.data.Buffered
Buffered.SourceExceptionNested classes/interfaces inherited from interface com.vaadin.featurepack.data.Container
Container.Editor, Container.Filter, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Container.ViewerNested classes/interfaces inherited from interface com.vaadin.featurepack.data.Container.Indexed
Container.Indexed.ItemAddEvent, Container.Indexed.ItemRemoveEvent -
Constructor Summary
ConstructorsConstructorDescriptionJPAContainer(Class<T> entityClass) Creates a newJPAContainerinstance for entities of classentityClass. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddContainerFilter(Container.Filter filter) Adds a filter for the container.voidaddContainerFilter(Object propertyId, String filterString, boolean ignoreCase, boolean onlyMatchPrefix) booleanaddContainerProperty(Object propertyId, Class<?> type, Object defaultValue) This functionality is not supported by this implementation.Adds a new entity to the container.addItem()This functionality is not fully supported by this implementation. The implementation tries to call empty parameter constructor and add entity as such to database.This functionality is not supported by this implementation.addItemAfter(Object previousItemId) This functionality is not supported by this implementation.addItemAfter(Object previousItemId, Object newItemId) This functionality is not supported by this implementation.addItemAt(int index) This functionality is not supported by this implementation.This functionality is not supported by this implementation.voidAdds an Item set change listener for the object.voidaddListener(Container.ItemSetChangeListener listener) voidaddNestedContainerProperty(String nestedProperty) Adds the nested propertynestedPropertyto the set of properties.voidApplies the filters to the data, possibly causing the items in the container to change.booleanareChildrenAllowed(Object itemId) Tests if the Item with given ID can have children.voidcommit()Updates all changes since the previous commit to the data source.booleancontainsId(Object itemId) Tests if the Container contains the specified Item.createEntityItem(T entity) Creates a newEntityItemforentitywithout adding it to the container.voiddiscard()Discards all changes since last commit.protected booleandoContainsId(Object itemId) protected EntityProvider<T> Checks that the entity provider is not null and returns it.voidNotifies the client thateventhas occurred.protected voidPublisheseventto all registeredItemSetChangeListeners.Gets the ID of the first Item in the Container.Gets the list of filters that are currently applied.protected Container.FilterReturns a conjunction (filter1 AND filter2 AND ...Collection<?> getChildren(Object itemId) Gets the IDs of all Items that are children of the specified Item.Returns the filters which have been applied to the containerProperty<?> getContainerProperty(Object itemId, Object propertyId) Gets the Property identified by the given itemId and propertyId from the Container.Gets the ID's of all Properties stored in the Container.Gets the class of the entities that are/can be contained in this container.protected EntityClassMetadata<T> Gets the mapping metadata of the entity class.Gets the entity provider that is used for fetching and storing entities.Gets the IDs of all the properties that are filterable.Gets the list of filters to apply.getIdByIndex(int index) Get the item id for the item at the position given byindex.Gets theItemwith the given Item ID from the Container.This impementation does not use lazy loading and performs bad when the number of items is large!List<?> getItemIds(int startIndex, int numberOfItems) GetnumberOfItemsconsecutive item ids from the container, starting with the item id atstartIndex.Gets the ID of the parent Item of the specified Item.Gets the name of the persistent property that contains the reference to the parent entity.getPropertyKind(Object propertyId) Gets the QueryModifierDelegate set for this container.Gets the container property IDs which can be used to sort the items.Gets all the properties that the items should be sorted by, if any.Class<?> Gets the data type of all Properties identified by the given Property ID.booleanhasChildren(Object itemId) Tests if the Item specified withitemIdhas child Items or if it is a leaf.booleanChecks if there are filters that have not yet been applied, or applied filters that have been removed usingorinvalid reference
#removeAllFilters().invalid reference
#removeFilter(com.vaadin.addon.jpacontainer.Filter)intThis implementation does not use lazy loading and performs extremely bad when the number of items is large!booleanReturns whether the filters should be applied immediately when a filter is added or removed.booleanAlias of.invalid reference
Buffered#isWriteThrough()booleanChecks the buffered modebooleanReturns whether thecontainsId(java.lang.Object)method will fire an item set change event if it returns false.booleanisFilterable(Object propertyId) Checks ifpropertyIdis filterable.booleanTests whether the container should fire an item set change event when it detects a change in the entity provider (such as an entity being added, updated or deleted).protected booleanbooleanTests if the Item corresponding to the given Item ID is the first Item in the Container.booleanTests if the Item corresponding to the given Item ID is the last Item in the Container.booleanTests if the value stored in the object has been modified since it was last updated from the data source.booleanReturns whether the container is read only or writable.booleanbooleanTests if the Item specified withitemIdis a root Item.booleanGets the ID of the last Item in the Container..nextItemId(Object itemId) Gets the ID of the Item following the Item that corresponds toitemId.prevItemId(Object itemId) Gets the ID of the Item preceding the Item that corresponds toitemId.voidrefresh()Refreshes the entire container from the database.voidrefreshItem(Object itemId) Causes all EntityItems created from this container and identified by given entityId to be refreshed.voidRemove all active filters from the container.booleanThis feature is not well optimized.voidRemoves a filter from the container.voidremoveContainerFilters(Object propertyId) booleanremoveContainerProperty(Object propertyId) Removes a Property specified by the given Property ID from the Container.booleanremoveItem(Object itemId) Removes the Item identified byItemIdfrom the Container.voidRemoves the Item set change listener from the object.voidprotected voidChecks that the container is writable, i.e. the entity provider implements theMutableEntityProviderinterface and the container is not marked as read only.Collection<?> Gets the IDs of all Items in the container that don't have a parent.voidsetAdditionalFilterablePropertyIds(String... propertyIds) Sometimes, it may be necessary to filter by properties that do not show up in the container.voidsetApplyFiltersImmediately(boolean applyFiltersImmediately) Sets whether the filters should be applied immediately when a filter is added or removed.voidsetAutoCommit(boolean autoCommit) Alias of.invalid reference
Buffered#setWriteThrough(boolean)voidsetBuffered(boolean buffered) Sets the buffered mode to the specified status.booleansetChildrenAllowed(Object itemId, boolean areChildrenAllowed) This functionality is not supported by this implementation.voidsetContainsIdFiresItemSetChangeIfNotFound(boolean value) voidsetEntityProvider(EntityProvider<T> entityProvider) Sets the entity provider to use for fetching and storing entities.voidsetFireContainerItemSetChangeEvents(boolean value) Specifies whether the container should fire an item set change event when it detects a change in the entity provider (such as an entity being added, updated or deleted).protected voidsetFireItemSetChangeOnProviderChange(boolean fireItemSetChangeOnProviderChange) Specifies whether the container should fire an ItemSetChangeEvent when an EntityProviderChangeEvent is received.booleanThis functionality is not supported by this implementation.voidsetParentProperty(String parentProperty) Sets the persistent property (may be nested) that contains the reference to the parent entity.voidsetQueryModifierDelegate(QueryModifierDelegate queryModifierDelegate) Sets theQueryModifierDelegate, which is called in the different stages that the EntityProvider builds a criteria query.voidsetReadOnly(boolean readOnly) Changes the read only state of the container, if possible.voidsetReadThrough(boolean readThrough) This functionality is not supported by this implementation.voidsetSortProperty(String propertyId, String sortProperty) Configures a property to be sortable based on another property, normally a sub-property of the main property to sort.voidsetWriteThrough(boolean writeThrough) intsize()Gets the number of visible Items in the Container.voidSorts the container items.protected void
-
Constructor Details
-
JPAContainer
Creates a newJPAContainerinstance for entities of classentityClass. An entity provider must be provided using thesetEntityProvider(EntityProvider)before the container can be used.- Parameters:
entityClass- the class of the entities that will reside in this container (must not be null).
-
-
Method Details
-
setAdditionalFilterablePropertyIds
Sometimes, it may be necessary to filter by properties that do not show up in the container. This method can be used to add additional property IDs to thegetFilterablePropertyIds()collection. This method performs no propertyId validation, so it is up to the client to make sure the propertyIds are valid.- Parameters:
propertyIds- an array of additional propertyIds, may be null.
-
updateFilterablePropertyIds
protected void updateFilterablePropertyIds() -
getEntityClassMetadata
Gets the mapping metadata of the entity class.- Returns:
- the metadata (never null).
- See Also:
-
addListener
-
removeListener
-
fireContainerItemSetChange
Publisheseventto all registeredItemSetChangeListeners.- Parameters:
event- the event to publish (must not be null).
-
setFireContainerItemSetChangeEvents
public void setFireContainerItemSetChangeEvents(boolean value) Specifies whether the container should fire an item set change event when it detects a change in the entity provider (such as an entity being added, updated or deleted). -
isFireContainerItemSetChangeEvents
public boolean isFireContainerItemSetChangeEvents()Tests whether the container should fire an item set change event when it detects a change in the entity provider (such as an entity being added, updated or deleted).- Returns:
- true if item set change events should be fired (default), false otherwise.
-
addNestedContainerProperty
Description copied from interface:EntityContainerAdds the nested propertynestedPropertyto the set of properties. An asterisk can be used as a wildcard to indicate all leaf-properties.For example, let's say there is a property named
addressand that this property's type in turn has the propertiesstreet,postalCodeandcity.If we want to be able to access the street property directly, we can add the nested property
address.streetusing this method.However, if we want to add all the address properties, we can also use
address.*. This will cause the nested propertiesaddress.street,address.postalCodeandaddress.cityto be added to the set of properties.Note, that the wildcard cannot be used in the middle of a chain of property names. E.g.
myprop.*.somethingis illegal.Nested properties may be transient, but only persistent nested properties (i.e. embedded properties or ManyToOne references) may be used for filtering or sorting.
- Specified by:
addNestedContainerPropertyin interfaceEntityContainer<T>- Parameters:
nestedProperty- the nested property to add (must not be null).- Throws:
UnsupportedOperationException- if nested properties are not supported by the container.
-
getEntityClass
Description copied from interface:EntityContainerGets the class of the entities that are/can be contained in this container.- Specified by:
getEntityClassin interfaceEntityContainer<T>- Returns:
- the entity class.
-
getEntityProvider
Description copied from interface:EntityContainerGets the entity provider that is used for fetching and storing entities.- Specified by:
getEntityProviderin interfaceEntityContainer<T>- Returns:
- the entity provider, or null if this container has not yet been properly initialized.
-
doGetEntityProvider
Checks that the entity provider is not null and returns it.- Returns:
- the entity provider (never null).
- Throws:
IllegalStateException- if the entity provider was null.
-
isReadOnly
public boolean isReadOnly()Description copied from interface:EntityContainerReturns whether the container is read only or writable.- Specified by:
isReadOnlyin interfaceEntityContainer<T>- Returns:
- true if read only, false if writable.
-
setEntityProvider
Description copied from interface:EntityContainerSets the entity provider to use for fetching and storing entities. The EntityProvider can be changed once set, if necessary.- Specified by:
setEntityProviderin interfaceEntityContainer<T>- Parameters:
entityProvider- the entity provider to use (must not be null).
-
setFireItemSetChangeOnProviderChange
protected void setFireItemSetChangeOnProviderChange(boolean fireItemSetChangeOnProviderChange) Specifies whether the container should fire an ItemSetChangeEvent when an EntityProviderChangeEvent is received. This is used to prevent clients from receiving duplicate ItemSetChangeEvents when the container modifies data and wants to handle ItemSetChangeEvents itself.- Parameters:
fireItemSetChangeOnProviderChange- true fo fire an ItemSetChangeEvent when the provider changes, false not to.
-
isFireItemSetChangeOnProviderChange
protected boolean isFireItemSetChangeOnProviderChange()- Returns:
- true if an ItemSetChangeEvent should be fired when the provider changes, false if it should not.
- See Also:
-
entityProviderChange
Description copied from interface:EntityProviderChangeListenerNotifies the client thateventhas occurred.- Specified by:
entityProviderChangein interfaceEntityProviderChangeListener<T>- Parameters:
event- the occurred event (never null).
-
setReadOnly
Description copied from interface:EntityContainerChanges the read only state of the container, if possible.- Specified by:
setReadOnlyin interfaceEntityContainer<T>- Parameters:
readOnly- true to make the container read only, false to make it writable.- Throws:
UnsupportedOperationException- if the read only state cannot be changed.
-
setSortProperty
Configures a property to be sortable based on another property, normally a sub-property of the main property to sort.For example, let's say there is a property named
addressand that this property's type in turn has the propertystreet. Addresses are not directly sortable as they are not simple properties.If we want to be able to sort addresses based on the street property, we can set the sort property for
addressto beaddress.streetusing this method.Normally the sort property should be of the form
propertyId + "." + subPropertyId. Sort properties must be persistent and usable in JPQL, but need not be registered as separate properties in the container.Note that the sort property is not checked when this method is called. If it is not a valid sort property, an exception will be thrown when trying to sort a container.
- Parameters:
propertyId- property for which sorting should be configuredsortProperty- property or other JPQL string that should be used when sorting by propertyId is requested, typically a sub-property propertyId- Throws:
IllegalArgumentException- if the propertypropertyIdis not in the container- Since:
- 1.2.1
-
getSortableContainerPropertyIds
Description copied from interface:Container.SortableGets the container property IDs which can be used to sort the items.- Specified by:
getSortableContainerPropertyIdsin interfaceContainer.Sortable- Returns:
- the IDs of the properties that can be used for sorting the container
-
sort
Description copied from interface:Container.SortableSorts the container items.Sorting a container can irreversibly change the order of its items or only change the order temporarily, depending on the container.
- Specified by:
sortin interfaceContainer.Sortable- Parameters:
propertyId- Array of container property IDs, whose values are used to sort the items in container as primary, secondary, ... sorting criterion. All of the item IDs must be in the collection returned byContainer.Sortable.getSortableContainerPropertyIds()ascending- Array of sorting order flags corresponding to each property ID used in sorting. If this array is shorter than propertyId array, ascending order is assumed for items where the order is not specified. Usetrueto sort in ascending order,falseto use descending order.
-
getSortByList
Gets all the properties that the items should be sorted by, if any.- Returns:
- an unmodifiable, possible empty list of
SortByinstances (never null).
-
addItemAfter
This functionality is not supported by this implementation.Adds a new item after the given item.
Adding an item after null item adds the item as first item of the ordered container.
- Specified by:
addItemAfterin interfaceContainer.Ordered- Parameters:
previousItemId- Id of the visible item in ordered container after which to insert the new item.- Returns:
- item id the the created new item or null if the operation fails.
- Throws:
UnsupportedOperationException- if the operation is not supported by the container- See Also:
-
addItemAfter
public Item addItemAfter(Object previousItemId, Object newItemId) throws UnsupportedOperationException This functionality is not supported by this implementation.Adds a new item after the given item.
Adding an item after null item adds the item as first item of the ordered container.
- Specified by:
addItemAfterin interfaceContainer.Ordered- Parameters:
previousItemId- Id of the visible item in ordered container after which to insert the new item.newItemId- Id of the new item to be added.- Returns:
- new item or null if the operation fails.
- Throws:
UnsupportedOperationException- if the operation is not supported by the container- See Also:
-
firstItemId
Description copied from interface:Container.OrderedGets the ID of the first Item in the Container.- Specified by:
firstItemIdin interfaceContainer.Ordered- Returns:
- ID of the first visible Item in the Container
-
isFirstId
Description copied from interface:Container.OrderedTests if the Item corresponding to the given Item ID is the first Item in the Container.- Specified by:
isFirstIdin interfaceContainer.Ordered- Parameters:
itemId- ID of an Item in the Container- Returns:
trueif the Item is first visible item in the Container,falseif not
-
isLastId
Description copied from interface:Container.OrderedTests if the Item corresponding to the given Item ID is the last Item in the Container.- Specified by:
isLastIdin interfaceContainer.Ordered- Returns:
trueif the Item is last visible item in the Container,falseif not
-
lastItemId
Description copied from interface:Container.OrderedGets the ID of the last Item in the Container..- Specified by:
lastItemIdin interfaceContainer.Ordered- Returns:
- ID of the last visible Item in the Container
-
nextItemId
Description copied from interface:Container.OrderedGets the ID of the Item following the Item that corresponds toitemId. If the given Item is the last or not found in the Container,nullis returned.- Specified by:
nextItemIdin interfaceContainer.Ordered- Parameters:
itemId- ID of a visible Item in the Container- Returns:
- ID of the next visible Item or
null
-
prevItemId
Description copied from interface:Container.OrderedGets the ID of the Item preceding the Item that corresponds toitemId. If the given Item is the first or not found in the Container,nullis returned.- Specified by:
prevItemIdin interfaceContainer.Ordered- Parameters:
itemId- ID of a visible Item in the Container- Returns:
- ID of the previous visible Item or
null
-
addContainerProperty
public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) throws UnsupportedOperationException This functionality is not supported by this implementation.Adds a new Property to all Items in the Container. The Property ID, data type and default value of the new Property are given as parameters.
This functionality is optional.
- Specified by:
addContainerPropertyin interfaceContainer- Parameters:
propertyId- ID of the Propertytype- Data type of the new PropertydefaultValue- The value all created Properties are initialized to- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support explicitly adding container properties
-
addItem
This functionality is not supported by this implementation.Creates a new Item with the given ID in the Container.
The new Item is returned, and it is ready to have its Properties modified. Returns
nullif the operation fails or the Container already contains a Item with the given ID.This functionality is optional.
- Specified by:
addItemin interfaceContainer- Parameters:
itemId- ID of the Item to be created- Returns:
- Created new Item, or
nullin case of a failure - Throws:
UnsupportedOperationException- if adding an item with an explicit item ID is not supported by the container
-
addItem
This functionality is not fully supported by this implementation. The implementation tries to call empty parameter constructor and add entity as such to database. If identifiers are not autogenerated or empty parameter constructor does not exist, the operation will fail and throw UnSupportedOperationException.Creates a new Item into the Container, and assign it an automatic ID.
The new ID is returned, or
nullif the operation fails. After a successful call you can use themethod to fetch the Item.getItemThis functionality is optional.
- Specified by:
addItemin interfaceContainer- Returns:
- ID of the newly created Item, or
nullin case of a failure - Throws:
UnsupportedOperationException- if adding an item without an explicit item ID is not supported by the container
-
containsId
Description copied from interface:ContainerTests if the Container contains the specified Item.Filtering can hide items so that they will not be visible through the container API, and this method should respect visibility of items (i.e. only indicate visible items as being in the container) if feasible for the container.
- Specified by:
containsIdin interfaceContainer- Parameters:
itemId- ID the of Item to be tested- Returns:
- boolean indicating if the Container holds the specified Item
-
isContainsIdFiresItemSetChangeIfNotFound
public boolean isContainsIdFiresItemSetChangeIfNotFound()Returns whether thecontainsId(java.lang.Object)method will fire an item set change event if it returns false. This may be necessary when using the container together with aand there are multiple users modifying the same data source.invalid reference
com.vaadin.ui.TableWhen a user selects an item in a Table, the table checks with the container if the item exists or not. If it does not exist, nothing happens. Normally, the item should always exist, but if the container has been changed after the initial set of items were fetched and cached by the table, there may be items in the Table that are not present in the container.
By enabling this flag, the Table will repaint itself if it tries to select a nonexistent item, causing the item to dissapear from the table as well.
-
setContainsIdFiresItemSetChangeIfNotFound
public void setContainsIdFiresItemSetChangeIfNotFound(boolean value) - Parameters:
value-
-
doContainsId
- See Also:
-
getContainerProperty
Description copied from interface:ContainerGets the Property identified by the given itemId and propertyId from the Container. If the Container does not contain the item or it is filtered out, or the Container does not have the Property,nullis returned.- Specified by:
getContainerPropertyin interfaceContainer- Parameters:
itemId- ID of the visible Item which contains the PropertypropertyId- ID of the Property to retrieve- Returns:
- Property with the given ID or
null
-
getContainerPropertyIds
Description copied from interface:ContainerGets the ID's of all Properties stored in the Container. The ID's cannot be modified through the returned collection.- Specified by:
getContainerPropertyIdsin interfaceContainer- Returns:
- unmodifiable collection of Property IDs
-
getItem
Gets theItemwith the given Item ID from the Container. If the Container does not contain the requested Item,nullis returned.Containers should not return Items that are filtered out.
Please note, that this method will create a new instance of
EntityItemupon every execution. That is, two subsequent calls to this method with the sameitemIdwill not return the sameEntityIteminstance. The actual entity instance may still be the same though, depending on the implementation of the entity provider. -
getItemIds
This impementation does not use lazy loading and performs bad when the number of items is large! Do not use unless you absolutely have to!Gets the ID's of all visible (after filtering and sorting) Items stored in the Container. The ID's cannot be modified through the returned collection.
If the container is
Container.Ordered, the collection returned by this method should follow that order. If the container isContainer.Sortable, the items should be in the sorted order.Calling this method for large lazy containers can be an expensive operation and should be avoided when practical.
- Specified by:
getItemIdsin interfaceContainer- Returns:
- unmodifiable collection of Item IDs
-
createEntityItem
Description copied from interface:EntityContainerCreates a newEntityItemforentitywithout adding it to the container. This makes it possible to use the samefor editing both new entities and existing entities.invalid reference
com.vaadin.ui.FormTo add the entity to the container,
EntityContainer.addEntity(java.lang.Object)should be used.- Specified by:
createEntityItemin interfaceEntityContainer<T>- Parameters:
entity- the entity for which an item should be created.- Returns:
- the entity item (never null).
- See Also:
-
getType
Description copied from interface:ContainerGets the data type of all Properties identified by the given Property ID. -
removeContainerProperty
Description copied from interface:ContainerRemoves a Property specified by the given Property ID from the Container. Note that the Property will be removed from all Items in the Container.This functionality is optional.
- Specified by:
removeContainerPropertyin interfaceContainer- Parameters:
propertyId- ID of the Property to remove- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support removing container properties
-
size
public int size()Description copied from interface:ContainerGets the number of visible Items in the Container.Filtering can hide items so that they will not be visible through the container API.
-
getAppliedFiltersAsConjunction
Returns a conjunction (filter1 AND filter2 AND ... AND filterN) of all the applied filters. If there are no applied filters, this method returns null.- Returns:
- a conjunction filter or null.
- See Also:
-
getFilterablePropertyIds
Description copied from interface:AdvancedFilterableGets the IDs of all the properties that are filterable.- Specified by:
getFilterablePropertyIdsin interfaceAdvancedFilterable- Returns:
- an unmodifiable collection of property IDs (never null).
-
isFilterable
Description copied from interface:AdvancedFilterableChecks ifpropertyIdis filterable.- Specified by:
isFilterablein interfaceAdvancedFilterable- Parameters:
propertyId- the property ID to check (must not be null).- Returns:
- true if the property is filterable, false otherwise.
-
getFilters
Description copied from interface:AdvancedFilterableGets the list of filters to apply. The filters will be applied as a conjunction (i.e. AND) in the order they appear in.- Specified by:
getFiltersin interfaceAdvancedFilterable- Returns:
- an unmodifiable list of filters (never null).
-
getAppliedFilters
Description copied from interface:AdvancedFilterableGets the list of filters that are currently applied. IfAdvancedFilterable.isApplyFiltersImmediately()returns true, this list will be the same as the one returned byAdvancedFilterable.getFilters().- Specified by:
getAppliedFiltersin interfaceAdvancedFilterable- Returns:
- an unmodifiable list of filters (never null).
-
setApplyFiltersImmediately
public void setApplyFiltersImmediately(boolean applyFiltersImmediately) Description copied from interface:AdvancedFilterableSets whether the filters should be applied immediately when a filter is added or removed.- Specified by:
setApplyFiltersImmediatelyin interfaceAdvancedFilterable- Parameters:
applyFiltersImmediately- true to apply filters immediately, false to apply whenAdvancedFilterable.applyFilters()is called.- See Also:
-
isApplyFiltersImmediately
public boolean isApplyFiltersImmediately()Description copied from interface:AdvancedFilterableReturns whether the filters should be applied immediately when a filter is added or removed. Default is true. If false,AdvancedFilterable.applyFilters()has to be called to apply the filters and update the container.- Specified by:
isApplyFiltersImmediatelyin interfaceAdvancedFilterable- Returns:
- true if the filters are applied immediately, false otherwise.
- See Also:
-
applyFilters
public void applyFilters()Description copied from interface:AdvancedFilterableApplies the filters to the data, possibly causing the items in the container to change.- Specified by:
applyFiltersin interfaceAdvancedFilterable- See Also:
-
hasUnappliedFilters
public boolean hasUnappliedFilters()Description copied from interface:AdvancedFilterableChecks if there are filters that have not yet been applied, or applied filters that have been removed usingorinvalid reference
#removeAllFilters().invalid reference
#removeFilter(com.vaadin.addon.jpacontainer.Filter)If
AdvancedFilterable.isApplyFiltersImmediately()is true, this method always returns false.- Specified by:
hasUnappliedFiltersin interfaceAdvancedFilterable- Returns:
- true if there are unapplied filters, false otherwise.
- See Also:
-
addContainerFilter
public void addContainerFilter(Object propertyId, String filterString, boolean ignoreCase, boolean onlyMatchPrefix) Description copied from interface:EntityContainerThis method creates a new
for the specified parameters and applies the filter immediately, regardless of the state ofinvalid reference
StringComparisonFilterAdvancedFilterable.isApplyFiltersImmediately().- Specified by:
addContainerFilterin interfaceEntityContainer<T>- See Also:
-
removeAllContainerFilters
public void removeAllContainerFilters()Description copied from interface:Container.FilterableRemove all active filters from the container.- Specified by:
removeAllContainerFiltersin interfaceContainer.Filterable
-
removeContainerFilters
Description copied from interface:EntityContainerThe container is updated immediately regardless of the state of
AdvancedFilterable.isApplyFiltersImmediately().- Specified by:
removeContainerFiltersin interfaceEntityContainer<T>
-
addContainerFilter
Adds a filter for the container.If a container has multiple filters, only items accepted by all filters are visible.
Note that JPAContainer don't support custom
Container.Filters as filtering is done on DB level. Only basic Filter implementations are supported. If more complex filtering is needed, developers should tend toQueryModifierDelegatethat allows developers to use JPA Criteria API to modify queries.- Specified by:
addContainerFilterin interfaceContainer.Filterable- Throws:
UnsupportedFilterException- if the filter is not supported by the container- See Also:
-
removeContainerFilter
Description copied from interface:Container.FilterableRemoves a filter from the container.This requires that the equals() method considers the filters as equivalent (same instance or properly implemented equals() method).
- Specified by:
removeContainerFilterin interfaceContainer.Filterable
-
addItemAt
This functionality is not supported by this implementation.Adds a new item at given index (in the filtered view).
The indices of the item currently in the given position and all the following items are incremented.
This method should apply filters to the added item after inserting it, possibly hiding it immediately. If the container is being sorted, the item may be added at the correct sorted position instead of the given position. See
Container.Indexed,Container.Ordered,Container.FilterableandContainer.Sortablefor more information.- Specified by:
addItemAtin interfaceContainer.Indexed- Parameters:
index- Index (in the filtered and sorted view) to add the new item.- Returns:
- item id of the created item or null if the operation fails.
- Throws:
UnsupportedOperationException- if the operation is not supported by the container
-
addItemAt
This functionality is not supported by this implementation.Adds a new item at given index (in the filtered view).
The indexes of the item currently in the given position and all the following items are incremented.
This method should apply filters to the added item after inserting it, possibly hiding it immediately. If the container is being sorted, the item may be added at the correct sorted position instead of the given position. See
Container.Indexed,Container.FilterableandContainer.Sortablefor more information.- Specified by:
addItemAtin interfaceContainer.Indexed- Parameters:
index- Index (in the filtered and sorted view) at which to add the new item.newItemId- Id of the new item to be added.- Returns:
- new
Itemor null if the operation fails. - Throws:
UnsupportedOperationException- if the operation is not supported by the container
-
getIdByIndex
Description copied from interface:Container.IndexedGet the item id for the item at the position given byindex.- Specified by:
getIdByIndexin interfaceContainer.Indexed- Parameters:
index- the index of the requested item id- Returns:
- the item id of the item at the given index
-
indexOfId
This implementation does not use lazy loading and performs extremely bad when the number of items is large! Do not use unless you absolutely have to!Gets the index of the Item corresponding to the itemId. The following is
truefor the returned index: 0 invalid input: '<'= index invalid input: '<' size(), or index = -1 if there is no visible item with that id in the container.- Specified by:
indexOfIdin interfaceContainer.Indexed- Parameters:
itemId- ID of an Item in the Container- Returns:
- index of the Item, or -1 if (the filtered and sorted view of) the Container does not include the Item
-
requireWritableContainer
protected void requireWritableContainer() throws IllegalStateException, UnsupportedOperationExceptionChecks that the container is writable, i.e. the entity provider implements theMutableEntityProviderinterface and the container is not marked as read only.- Throws:
IllegalStateException- if the container is read only.UnsupportedOperationException- if the entity provider does not support editing.
-
addEntity
Description copied from interface:EntityContainerAdds a new entity to the container. The correspondingEntityItemcan then be accessed by callingEntityContainer.getItem(java.lang.Object)using the entity identifier returned by this method.If
EntityContainer.isAutoCommit()is activated, the returned identifier is always the actual entity ID. Otherwise, the returned identifier may, depending on the ID generation strategy, be either the actual entity ID or a temporary ID that is changed to the real ID once the changes have been committed usingBuffered.commit().- Specified by:
addEntityin interfaceEntityContainer<T>- Parameters:
entity- the entity to add (must not be null).- Returns:
- the identifier of the entity (never null).
- Throws:
UnsupportedOperationException- if the container does not support adding new entities at all.IllegalStateException- if the container supports adding entities, but is currently in read only mode.
-
removeAllItems
public boolean removeAllItems()This feature is not well optimized. Using direct access to db is much faster.Removes all Items from the Container.
Note that Property ID and type information is preserved. This functionality is optional.
- Specified by:
removeAllItemsin interfaceContainer- Returns:
trueif the operation succeeded,falseif not
-
removeItem
Description copied from interface:ContainerRemoves the Item identified byItemIdfrom the Container.Containers that support filtering should also allow removing an item that is currently filtered out.
This functionality is optional.
- Specified by:
removeItemin interfaceContainer- Specified by:
removeItemin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item to remove- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- if the container does not support removing individual items
-
commit
Description copied from interface:BufferedUpdates all changes since the previous commit to the data source. The value stored in the object will always be updated into the data source whencommitis called.- Specified by:
commitin interfaceBuffered- Throws:
Buffered.SourceException- if the operation fails because of an exception is thrown by the data source. The cause is included in the exception.Validator.InvalidValueException- if the operation fails because validation is enabled and the values do not validate
-
discard
Description copied from interface:BufferedDiscards all changes since last commit. The object updates its value from the data source.- Specified by:
discardin interfaceBuffered- Throws:
Buffered.SourceException- if the operation fails because of an exception is thrown by the data source. The cause is included in the exception.
-
isModified
public boolean isModified()Description copied from interface:BufferedTests if the value stored in the object has been modified since it was last updated from the data source.- Specified by:
isModifiedin interfaceBuffered- Returns:
trueif the value in the object has been modified since the last data source update,falseif not.
-
isReadThrough
public boolean isReadThrough() -
isWriteThrough
public boolean isWriteThrough() -
setReadThrough
This functionality is not supported by this implementation.- Throws:
Buffered.SourceException
-
setWriteThrough
public void setWriteThrough(boolean writeThrough) throws Buffered.SourceException, Validator.InvalidValueException Note, that write-through mode can only be turned off if the entity provider implements the
BatchableEntityProviderinterface. -
setAutoCommit
public void setAutoCommit(boolean autoCommit) throws Buffered.SourceException, Validator.InvalidValueException Description copied from interface:EntityContainerAlias of.invalid reference
Buffered#setWriteThrough(boolean)- Specified by:
setAutoCommitin interfaceEntityContainer<T>- Throws:
Buffered.SourceExceptionValidator.InvalidValueException
-
isAutoCommit
public boolean isAutoCommit()Description copied from interface:EntityContainerAlias of.invalid reference
Buffered#isWriteThrough()- Specified by:
isAutoCommitin interfaceEntityContainer<T>
-
getParentProperty
Description copied from interface:HierarchicalEntityContainerGets the name of the persistent property that contains the reference to the parent entity.- Specified by:
getParentPropertyin interfaceHierarchicalEntityContainer<T>- Returns:
- the name of the parent property, or null if not specified.
-
setParentProperty
Description copied from interface:HierarchicalEntityContainerSets the persistent property (may be nested) that contains the reference to the parent entity. The parent entity is expected to be of the same type as the child entity.- Specified by:
setParentPropertyin interfaceHierarchicalEntityContainer<T>- Parameters:
parentProperty- the name of the parent property.
-
areChildrenAllowed
Description copied from interface:Container.HierarchicalTests if the Item with given ID can have children.- Specified by:
areChildrenAllowedin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item in the container whose child capability is to be tested- Returns:
trueif the specified Item exists in the Container and it can have children,falseif it's not found from the container or it can't have children.
-
getChildren
Description copied from interface:Container.HierarchicalGets the IDs of all Items that are children of the specified Item. The returned collection is unmodifiable.- Specified by:
getChildrenin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item whose children the caller is interested in- Returns:
- An unmodifiable
collectioncontaining the IDs of all other Items that are children in the container hierarchy;nullif item does not have any children.
-
getParent
Description copied from interface:Container.HierarchicalGets the ID of the parent Item of the specified Item.- Specified by:
getParentin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item whose parent the caller wishes to find out.- Returns:
- the ID of the parent Item. Will be
nullif the specified Item is a root element.
-
hasChildren
Description copied from interface:Container.HierarchicalTests if the Item specified with
itemIdhas child Items or if it is a leaf. TheContainer.Hierarchical.getChildren(Object itemId)method always returnsnullfor leaf Items.Note that being a leaf does not imply whether or not an Item is allowed to have children.
- Specified by:
hasChildrenin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item to be tested- Returns:
trueif the specified Item has children,falseif not (is a leaf)
-
isRoot
Description copied from interface:Container.HierarchicalTests if the Item specified withitemIdis a root Item. The hierarchical container can have more than one root and must have at least one unless it is empty. TheContainer.Hierarchical.getParent(Object itemId)method always returnsnullfor root Items.- Specified by:
isRootin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item whose root status is to be tested- Returns:
trueif the specified Item is a root,falseif not
-
rootItemIds
Description copied from interface:Container.HierarchicalGets the IDs of all Items in the container that don't have a parent. Such items are calledrootItems. The returned collection is unmodifiable.- Specified by:
rootItemIdsin interfaceContainer.Hierarchical- Returns:
- An unmodifiable
collectioncontaining IDs of all root elements of the container
-
setChildrenAllowed
public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed) throws UnsupportedOperationException This functionality is not supported by this implementation.Sets the given Item's capability to have children. If the Item identified with
itemIdalready has children andis false this method fails andContainer.Hierarchical.areChildrenAllowed(Object)falseis returned.The children must be first explicitly removed with
Container.Hierarchical.setParent(Object itemId, Object newParentId)orContainer.removeItem(Object itemId).This operation is optional. If it is not implemented, the method always returns
false.- Specified by:
setChildrenAllowedin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the Item in the container whose child capability is to be setareChildrenAllowed- boolean value specifying if the Item can have children or not- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException
-
setParent
This functionality is not supported by this implementation.Sets the parent of an Item. The new parent item must exist and be able to have children. (
). It is also possible to detach a node from the hierarchy (and thus make it root) by setting the parentContainer.Hierarchical.areChildrenAllowed(Object)== truenull.This operation is optional.
- Specified by:
setParentin interfaceContainer.Hierarchical- Parameters:
itemId- ID of the item to be set as the child of the Item identified withnewParentIdnewParentId- ID of the Item that's to be the new parent of the Item identified withitemId- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException
-
getPropertyKind
- Specified by:
getPropertyKindin interfaceEntityContainer<T>- Parameters:
propertyId-- Returns:
- the type of property indentified by given propertyId
-
refreshItem
Description copied from interface:EntityContainerCauses all EntityItems created from this container and identified by given entityId to be refreshed.- Specified by:
refreshItemin interfaceEntityContainer<T>- Parameters:
itemId-- See Also:
-
refresh
public void refresh()Description copied from interface:EntityContainerRefreshes the entire container from the database. All unsaved data will be lost.- Specified by:
refreshin interfaceEntityContainer<T>
-
getQueryModifierDelegate
Description copied from interface:EntityContainerGets the QueryModifierDelegate set for this container. EntityProviders will the delegate returned by this method in their queries.- Specified by:
getQueryModifierDelegatein interfaceEntityContainer<T>- Returns:
- QueryModifierDelegate to control queries built by this container
-
setQueryModifierDelegate
Sets theQueryModifierDelegate, which is called in the different stages that the EntityProvider builds a criteria query.- Parameters:
queryModifierDelegate- the delegate.
-
setBuffered
public void setBuffered(boolean buffered) Description copied from interface:BufferedSets the buffered mode to the specified status.When in buffered mode, an internal buffer will be used to store changes until
Buffered.commit()is called. CallingBuffered.discard()will revert the internal buffer to the value of the data source.When in non-buffered mode both read and write operations will be done directly on the data source. In this mode the
Buffered.commit()andBuffered.discard()methods serve no purpose.- Specified by:
setBufferedin interfaceBuffered- Parameters:
buffered- true if buffered mode should be turned on, false otherwise
-
isBuffered
public boolean isBuffered()Description copied from interface:BufferedChecks the buffered mode- Specified by:
isBufferedin interfaceBuffered- Returns:
- true if buffered mode is on, false otherwise
-
addItemSetChangeListener
Description copied from interface:Container.ItemSetChangeNotifierAdds an Item set change listener for the object.- Specified by:
addItemSetChangeListenerin interfaceContainer.ItemSetChangeNotifier- Parameters:
listener- listener to be added
-
removeItemSetChangeListener
Description copied from interface:Container.ItemSetChangeNotifierRemoves the Item set change listener from the object.- Specified by:
removeItemSetChangeListenerin interfaceContainer.ItemSetChangeNotifier- Parameters:
listener- listener to be removed
-
getItemIds
Description copied from interface:Container.IndexedGetnumberOfItemsconsecutive item ids from the container, starting with the item id atstartIndex.Implementations should return at most
numberOfItemsitem ids, but can contain less if the container has less items than required to fulfill the request. The returned list must hence contain all of the item ids from the range:startIndextomax(startIndex + (numberOfItems-1), container.size()-1).For quick migration to new API see:
ContainerHelpers.getItemIdsUsingGetIdByIndex(int, int, Indexed)- Specified by:
getItemIdsin interfaceContainer.Indexed- Parameters:
startIndex- the index for the first item which id to includenumberOfItems- the number of consecutive item ids to get from the given start index, must be >= 0- Returns:
- List containing the requested item ids or empty list if
numberOfItems== 0; not null
-
getContainerFilters
Description copied from interface:Container.FilterableReturns the filters which have been applied to the container- Specified by:
getContainerFiltersin interfaceContainer.Filterable- Returns:
- A collection of filters which have been applied to the container. An empty collection if no filters have been applied.
-