com.vaadin.addon.jpacontainer
Class JPAContainer<T>

java.lang.Object
  extended by com.vaadin.addon.jpacontainer.JPAContainer<T>
All Implemented Interfaces:
AdvancedFilterable, EntityContainer<T>, EntityProviderChangeListener<T>, HierarchicalEntityContainer<T>, com.vaadin.data.Buffered, com.vaadin.data.Container, com.vaadin.data.Container.Filterable, com.vaadin.data.Container.Hierarchical, com.vaadin.data.Container.Indexed, com.vaadin.data.Container.ItemSetChangeNotifier, com.vaadin.data.Container.Ordered, com.vaadin.data.Container.Sortable, Serializable

public class JPAContainer<T>
extends Object
implements EntityContainer<T>, EntityProviderChangeListener<T>, HierarchicalEntityContainer<T>, com.vaadin.data.Container.Indexed

This is the main container class of JPAContainer (and the default implementation of 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:

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:
LocalEntityProvider, CachingLocalEntityProvider, BatchableLocalEntityProvider, Serialized Form

Nested Class Summary
 class JPAContainer.AllItemsRefreshedEvent
           
 class JPAContainer.AllItemsRemovedEvent
          Event indicating that all the items have been removed from the container.
 class JPAContainer.ChangesCommittedEvent
          Event indicating that the changes have been committed.
 class JPAContainer.ChangesDiscardedEvent
          Event indicating that the changes have been discarded.
 class JPAContainer.ContainerSortedEvent
          Event indicating that the container has been resorted.
 class JPAContainer.ItemAddedEvent
          Event indicating that an item has been added to the container.
 class JPAContainer.ItemEvent
          Abstract base class for events concerning single EntityItems.
 class JPAContainer.ItemNotFoundEvent
          Event fired by containsId(java.lang.Object) when the result is false and isContainsIdFiresItemSetChangeIfNotFound() is true.
 class JPAContainer.ItemRemovedEvent
          Event indicating that an item has been removed from the container.
 class JPAContainer.ItemUpdatedEvent
          Event indicating that an item has been updated inside the container.
 class JPAContainer.ProviderChangedEvent
          Event fired when a EntityProviderChangeEvent is received by the container.
 
Nested classes/interfaces inherited from interface com.vaadin.addon.jpacontainer.AdvancedFilterable
AdvancedFilterable.FiltersAppliedEvent<C extends com.vaadin.data.Container & AdvancedFilterable>
 
Nested classes/interfaces inherited from interface com.vaadin.data.Buffered
com.vaadin.data.Buffered.SourceException
 
Constructor Summary
JPAContainer(Class<T> entityClass)
          Creates a new JPAContainer instance for entities of class entityClass.
 
Method Summary
 void addContainerFilter(com.vaadin.data.Container.Filter filter)
          
 void addContainerFilter(Object propertyId, String filterString, boolean ignoreCase, boolean onlyMatchPrefix)
          
 boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue)
          This functionality is not supported by this implementation.
 Object addEntity(T entity)
          Adds a new entity to the container.
 Object 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.
 com.vaadin.data.Item addItem(Object itemId)
          This functionality is not supported by this implementation.
 Object addItemAfter(Object previousItemId)
          This functionality is not supported by this implementation.
 com.vaadin.data.Item addItemAfter(Object previousItemId, Object newItemId)
          This functionality is not supported by this implementation.
 Object addItemAt(int index)
          This functionality is not supported by this implementation.
 com.vaadin.data.Item addItemAt(int index, Object newItemId)
          This functionality is not supported by this implementation.
 void addItemSetChangeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
           
 void addListener(com.vaadin.data.Container.ItemSetChangeListener listener)
           
 void addNestedContainerProperty(String nestedProperty)
          Adds the nested property nestedProperty to the set of properties.
 void applyFilters()
          Applies the filters to the data, possibly causing the items in the container to change.
 boolean areChildrenAllowed(Object itemId)
           
 void commit()
           
 boolean containsId(Object itemId)
           
 EntityItem<T> createEntityItem(T entity)
          Creates a new EntityItem for entity without adding it to the container.
 void discard()
           
protected  boolean doContainsId(Object itemId)
           
protected  EntityProvider<T> doGetEntityProvider()
          Checks that the entity provider is not null and returns it.
 void entityProviderChange(EntityProviderChangeEvent<T> event)
          Notifies the client that event has occurred.
protected  void fireContainerItemSetChange(com.vaadin.data.Container.ItemSetChangeEvent event)
          Publishes event to all registered ItemSetChangeListeners.
 Object firstItemId()
           
 List<com.vaadin.data.Container.Filter> getAppliedFilters()
          Gets the list of filters that are currently applied.
protected  com.vaadin.data.Container.Filter getAppliedFiltersAsConjunction()
          Returns a conjunction (filter1 AND filter2 AND ...
 Collection<?> getChildren(Object itemId)
           
 Collection<com.vaadin.data.Container.Filter> getContainerFilters()
           
 com.vaadin.data.Property getContainerProperty(Object itemId, Object propertyId)
           
 Collection<String> getContainerPropertyIds()
           
 Class<T> getEntityClass()
          Gets the class of the entities that are/can be contained in this container.
protected  EntityClassMetadata<T> getEntityClassMetadata()
          Gets the mapping metadata of the entity class.
 EntityProvider<T> getEntityProvider()
          Gets the entity provider that is used for fetching and storing entities.
 Collection<Object> getFilterablePropertyIds()
          Gets the IDs of all the properties that are filterable.
 List<com.vaadin.data.Container.Filter> getFilters()
          Gets the list of filters to apply.
 Object getIdByIndex(int index)
           
 EntityItem<T> getItem(Object itemId)
          
 Collection<Object> 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!
 List<?> getItemIds(int startIndex, int numberOfItems)
           
 Object getParent(Object itemId)
           
 String getParentProperty()
          Gets the name of the persistent property that contains the reference to the parent entity.
 PropertyKind getPropertyKind(Object propertyId)
           
 QueryModifierDelegate getQueryModifierDelegate()
          Gets the QueryModifierDelegate set for this container.
 Collection<String> getSortableContainerPropertyIds()
           
protected  List<SortBy> getSortByList()
          Gets all the properties that the items should be sorted by, if any.
 Class<?> getType(Object propertyId)
           
 boolean hasChildren(Object itemId)
           
 boolean hasUnappliedFilters()
          Checks if there are filters that have not yet been applied, or applied filters that have been removed using #removeAllFilters() or #removeFilter(com.vaadin.addon.jpacontainer.Filter) .
 int indexOfId(Object itemId)
          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!
 boolean isApplyFiltersImmediately()
          Returns whether the filters should be applied immediately when a filter is added or removed.
 boolean isAutoCommit()
          Alias of Buffered#isWriteThrough() .
 boolean isBuffered()
           
 boolean isContainsIdFiresItemSetChangeIfNotFound()
          Returns whether the containsId(java.lang.Object) method will fire an item set change event if it returns false.
 boolean isFilterable(Object propertyId)
          Checks if propertyId is filterable.
 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).
protected  boolean isFireItemSetChangeOnProviderChange()
           
 boolean isFirstId(Object itemId)
           
 boolean isLastId(Object itemId)
           
 boolean isModified()
           
 boolean isReadOnly()
          Returns whether the container is read only or writable.
 boolean isReadThrough()
           
 boolean isRoot(Object itemId)
           
 boolean isWriteThrough()
           
 Object lastItemId()
           
 Object nextItemId(Object itemId)
           
 Object prevItemId(Object itemId)
           
 void refresh()
          Refreshes the entire container from the database.
 void refreshItem(Object itemId)
          Causes all EntityItems created from this container and identified by given entityId to be refreshed.
 void removeAllContainerFilters()
           
 boolean removeAllItems()
          This feature is not well optimized.
 void removeContainerFilter(com.vaadin.data.Container.Filter filter)
           
 void removeContainerFilters(Object propertyId)
          
 boolean removeContainerProperty(Object propertyId)
           
 boolean removeItem(Object itemId)
           
 void removeItemSetChangeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
           
 void removeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
           
protected  void requireWritableContainer()
          Checks that the container is writable, i.e.
 Collection<?> rootItemIds()
           
 void setAdditionalFilterablePropertyIds(String... propertyIds)
          Sometimes, it may be necessary to filter by properties that do not show up in the container.
 void setApplyFiltersImmediately(boolean applyFiltersImmediately)
          Sets whether the filters should be applied immediately when a filter is added or removed.
 void setAutoCommit(boolean autoCommit)
          Alias of Buffered#setWriteThrough(boolean) .
 void setBuffered(boolean buffered)
           
 boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed)
          This functionality is not supported by this implementation.
 void setContainsIdFiresItemSetChangeIfNotFound(boolean value)
          See isContainsIdFiresItemSetChangeIfNotFound().
 void setEntityProvider(EntityProvider<T> entityProvider)
          Sets the entity provider to use for fetching and storing entities.
 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).
protected  void setFireItemSetChangeOnProviderChange(boolean fireItemSetChangeOnProviderChange)
          Specifies whether the container should fire an ItemSetChangeEvent when an EntityProviderChangeEvent is received.
 boolean setParent(Object itemId, Object newParentId)
          This functionality is not supported by this implementation.
 void setParentProperty(String parentProperty)
          Sets the persistent property (may be nested) that contains the reference to the parent entity.
 void setQueryModifierDelegate(QueryModifierDelegate queryModifierDelegate)
          Sets the QueryModifierDelegate, which is called in the different stages that the EntityProvider builds a criteria query.
 void setReadOnly(boolean readOnly)
          Changes the read only state of the container, if possible.
 void setReadThrough(boolean readThrough)
          This functionality is not supported by this implementation.
 void setSortProperty(String propertyId, String sortProperty)
          Configures a property to be sortable based on another property, normally a sub-property of the main property to sort.
 void setWriteThrough(boolean writeThrough)
          
 int size()
           
 void sort(Object[] propertyId, boolean[] ascending)
           
protected  void updateFilterablePropertyIds()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JPAContainer

public JPAContainer(Class<T> entityClass)
Creates a new JPAContainer instance for entities of class entityClass. An entity provider must be provided using the setEntityProvider(com.vaadin.addon.jpacontainer.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 Detail

setAdditionalFilterablePropertyIds

public void setAdditionalFilterablePropertyIds(String... propertyIds)
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 the getFilterablePropertyIds() 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

protected EntityClassMetadata<T> getEntityClassMetadata()
Gets the mapping metadata of the entity class.

Returns:
the metadata (never null).
See Also:
EntityClassMetadata

addListener

public void addListener(com.vaadin.data.Container.ItemSetChangeListener listener)
Specified by:
addListener in interface com.vaadin.data.Container.ItemSetChangeNotifier

removeListener

public void removeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
Specified by:
removeListener in interface com.vaadin.data.Container.ItemSetChangeNotifier

fireContainerItemSetChange

protected void fireContainerItemSetChange(com.vaadin.data.Container.ItemSetChangeEvent event)
Publishes event to all registered ItemSetChangeListeners.

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

public void addNestedContainerProperty(String nestedProperty)
                                throws UnsupportedOperationException
Description copied from interface: EntityContainer
Adds the nested property nestedProperty to 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 address and that this property's type in turn has the properties street, postalCode and city.

If we want to be able to access the street property directly, we can add the nested property address.street using this method.

However, if we want to add all the address properties, we can also use address.*. This will cause the nested properties address.street, address.postalCode and address.city to 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.*.something is 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:
addNestedContainerProperty in interface EntityContainer<T>
Parameters:
nestedProperty - the nested property to add (must not be null).
Throws:
UnsupportedOperationException - if nested properties are not supported by the container.

getEntityClass

public Class<T> getEntityClass()
Description copied from interface: EntityContainer
Gets the class of the entities that are/can be contained in this container.

Specified by:
getEntityClass in interface EntityContainer<T>
Returns:
the entity class.

getEntityProvider

public EntityProvider<T> getEntityProvider()
Description copied from interface: EntityContainer
Gets the entity provider that is used for fetching and storing entities.

Specified by:
getEntityProvider in interface EntityContainer<T>
Returns:
the entity provider, or null if this container has not yet been properly initialized.

doGetEntityProvider

protected EntityProvider<T> doGetEntityProvider()
                                         throws IllegalStateException
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: EntityContainer
Returns whether the container is read only or writable.

Specified by:
isReadOnly in interface EntityContainer<T>
Returns:
true if read only, false if writable.

setEntityProvider

public void setEntityProvider(EntityProvider<T> entityProvider)
Description copied from interface: EntityContainer
Sets the entity provider to use for fetching and storing entities. The EntityProvider can be changed once set, if necessary.

Specified by:
setEntityProvider in interface EntityContainer<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:
setFireItemSetChangeOnProviderChange(boolean)

entityProviderChange

public void entityProviderChange(EntityProviderChangeEvent<T> event)
Description copied from interface: EntityProviderChangeListener
Notifies the client that event has occurred.

Specified by:
entityProviderChange in interface EntityProviderChangeListener<T>
Parameters:
event - the occurred event (never null).

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws UnsupportedOperationException
Description copied from interface: EntityContainer
Changes the read only state of the container, if possible.

Specified by:
setReadOnly in interface EntityContainer<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

public void setSortProperty(String propertyId,
                            String sortProperty)
                     throws IllegalArgumentException
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 address and that this property's type in turn has the property street. 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 address to be address.street using 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 configured
sortProperty - property or other JPQL string that should be used when sorting by propertyId is requested, typically a sub-property propertyId
Throws:
IllegalArgumentException - if the property propertyId is not in the container
Since:
1.2.1

getSortableContainerPropertyIds

public Collection<String> getSortableContainerPropertyIds()
Specified by:
getSortableContainerPropertyIds in interface com.vaadin.data.Container.Sortable

sort

public void sort(Object[] propertyId,
                 boolean[] ascending)
Specified by:
sort in interface com.vaadin.data.Container.Sortable

getSortByList

protected List<SortBy> getSortByList()
Gets all the properties that the items should be sorted by, if any.

Returns:
an unmodifiable, possible empty list of SortBy instances (never null).

addItemAfter

public Object addItemAfter(Object previousItemId)
                    throws UnsupportedOperationException
This functionality is not supported by this implementation.

Specified by:
addItemAfter in interface com.vaadin.data.Container.Ordered
Throws:
UnsupportedOperationException

addItemAfter

public com.vaadin.data.Item addItemAfter(Object previousItemId,
                                         Object newItemId)
                                  throws UnsupportedOperationException
This functionality is not supported by this implementation.

Specified by:
addItemAfter in interface com.vaadin.data.Container.Ordered
Throws:
UnsupportedOperationException

firstItemId

public Object firstItemId()
Specified by:
firstItemId in interface com.vaadin.data.Container.Ordered

isFirstId

public boolean isFirstId(Object itemId)
Specified by:
isFirstId in interface com.vaadin.data.Container.Ordered

isLastId

public boolean isLastId(Object itemId)
Specified by:
isLastId in interface com.vaadin.data.Container.Ordered

lastItemId

public Object lastItemId()
Specified by:
lastItemId in interface com.vaadin.data.Container.Ordered

nextItemId

public Object nextItemId(Object itemId)
Specified by:
nextItemId in interface com.vaadin.data.Container.Ordered

prevItemId

public Object prevItemId(Object itemId)
Specified by:
prevItemId in interface com.vaadin.data.Container.Ordered

addContainerProperty

public boolean addContainerProperty(Object propertyId,
                                    Class<?> type,
                                    Object defaultValue)
                             throws UnsupportedOperationException
This functionality is not supported by this implementation.

Specified by:
addContainerProperty in interface com.vaadin.data.Container
Throws:
UnsupportedOperationException

addItem

public com.vaadin.data.Item addItem(Object itemId)
                             throws UnsupportedOperationException
This functionality is not supported by this implementation.

Specified by:
addItem in interface com.vaadin.data.Container
Throws:
UnsupportedOperationException

addItem

public Object addItem()
               throws UnsupportedOperationException
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.

Specified by:
addItem in interface com.vaadin.data.Container
Throws:
UnsupportedOperationException

containsId

public boolean containsId(Object itemId)
Specified by:
containsId in interface com.vaadin.data.Container

isContainsIdFiresItemSetChangeIfNotFound

public boolean isContainsIdFiresItemSetChangeIfNotFound()
Returns whether the containsId(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 a Table and there are multiple users modifying the same data source.

When 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)
See isContainsIdFiresItemSetChangeIfNotFound().

Parameters:
value -

doContainsId

protected boolean doContainsId(Object itemId)
See Also:
Container.containsId(java.lang.Object)

getContainerProperty

public com.vaadin.data.Property getContainerProperty(Object itemId,
                                                     Object propertyId)
Specified by:
getContainerProperty in interface com.vaadin.data.Container

getContainerPropertyIds

public Collection<String> getContainerPropertyIds()
Specified by:
getContainerPropertyIds in interface com.vaadin.data.Container

getItem

public EntityItem<T> getItem(Object itemId)

Please note, that this method will create a new instance of EntityItem upon every execution. That is, two subsequent calls to this method with the same itemId will not return the same EntityItem instance. The actual entity instance may still be the same though, depending on the implementation of the entity provider.

Specified by:
getItem in interface EntityContainer<T>
Specified by:
getItem in interface com.vaadin.data.Container

getItemIds

public Collection<Object> 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!

Specified by:
getItemIds in interface com.vaadin.data.Container

createEntityItem

public EntityItem<T> createEntityItem(T entity)
Description copied from interface: EntityContainer
Creates a new EntityItem for entity without adding it to the container. This makes it possible to use the same Form for editing both new entities and existing entities.

To add the entity to the container, EntityContainer.addEntity(java.lang.Object) should be used.

Specified by:
createEntityItem in interface EntityContainer<T>
Parameters:
entity - the entity for which an item should be created.
Returns:
the entity item (never null).
See Also:
EntityItem.getItemId()

getType

public Class<?> getType(Object propertyId)
Specified by:
getType in interface com.vaadin.data.Container

removeContainerProperty

public boolean removeContainerProperty(Object propertyId)
                                throws UnsupportedOperationException
Specified by:
removeContainerProperty in interface com.vaadin.data.Container
Throws:
UnsupportedOperationException

size

public int size()
Specified by:
size in interface com.vaadin.data.Container

getAppliedFiltersAsConjunction

protected com.vaadin.data.Container.Filter 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:
getAppliedFilters()

getFilterablePropertyIds

public Collection<Object> getFilterablePropertyIds()
Description copied from interface: AdvancedFilterable
Gets the IDs of all the properties that are filterable.

Specified by:
getFilterablePropertyIds in interface AdvancedFilterable
Returns:
an unmodifiable collection of property IDs (never null).

isFilterable

public boolean isFilterable(Object propertyId)
Description copied from interface: AdvancedFilterable
Checks if propertyId is filterable.

Specified by:
isFilterable in interface AdvancedFilterable
Parameters:
propertyId - the property ID to check (must not be null).
Returns:
true if the property is filterable, false otherwise.

getFilters

public List<com.vaadin.data.Container.Filter> getFilters()
Description copied from interface: AdvancedFilterable
Gets 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:
getFilters in interface AdvancedFilterable
Returns:
an unmodifiable list of filters (never null).

getAppliedFilters

public List<com.vaadin.data.Container.Filter> getAppliedFilters()
Description copied from interface: AdvancedFilterable
Gets the list of filters that are currently applied. If AdvancedFilterable.isApplyFiltersImmediately() returns true, this list will be the same as the one returned by AdvancedFilterable.getFilters().

Specified by:
getAppliedFilters in interface AdvancedFilterable
Returns:
an unmodifiable list of filters (never null).

setApplyFiltersImmediately

public void setApplyFiltersImmediately(boolean applyFiltersImmediately)
Description copied from interface: AdvancedFilterable
Sets whether the filters should be applied immediately when a filter is added or removed.

Specified by:
setApplyFiltersImmediately in interface AdvancedFilterable
Parameters:
applyFiltersImmediately - true to apply filters immediately, false to apply when AdvancedFilterable.applyFilters() is called.
See Also:
AdvancedFilterable.isApplyFiltersImmediately()

isApplyFiltersImmediately

public boolean isApplyFiltersImmediately()
Description copied from interface: AdvancedFilterable
Returns 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:
isApplyFiltersImmediately in interface AdvancedFilterable
Returns:
true if the filters are applied immediately, false otherwise.
See Also:
AdvancedFilterable.setApplyFiltersImmediately(boolean)

applyFilters

public void applyFilters()
Description copied from interface: AdvancedFilterable
Applies the filters to the data, possibly causing the items in the container to change.

Specified by:
applyFilters in interface AdvancedFilterable
See Also:
AdvancedFilterable.FiltersAppliedEvent

hasUnappliedFilters

public boolean hasUnappliedFilters()
Description copied from interface: AdvancedFilterable
Checks if there are filters that have not yet been applied, or applied filters that have been removed using #removeAllFilters() or #removeFilter(com.vaadin.addon.jpacontainer.Filter) .

If AdvancedFilterable.isApplyFiltersImmediately() is true, this method always returns false.

Specified by:
hasUnappliedFilters in interface AdvancedFilterable
Returns:
true if there are unapplied filters, false otherwise.
See Also:
AdvancedFilterable.applyFilters()

addContainerFilter

public void addContainerFilter(Object propertyId,
                               String filterString,
                               boolean ignoreCase,
                               boolean onlyMatchPrefix)
Description copied from interface: EntityContainer

This method creates a new StringComparisonFilter for the specified parameters and applies the filter immediately, regardless of the state of AdvancedFilterable.isApplyFiltersImmediately().

Specified by:
addContainerFilter in interface EntityContainer<T>
See Also:
AdvancedFilterable.applyFilters()

removeAllContainerFilters

public void removeAllContainerFilters()
Specified by:
removeAllContainerFilters in interface com.vaadin.data.Container.Filterable

removeContainerFilters

public void removeContainerFilters(Object propertyId)
Description copied from interface: EntityContainer

The container is updated immediately regardless of the state of AdvancedFilterable.isApplyFiltersImmediately().

Specified by:
removeContainerFilters in interface EntityContainer<T>

addContainerFilter

public void addContainerFilter(com.vaadin.data.Container.Filter filter)
                        throws com.vaadin.data.util.filter.UnsupportedFilterException

Note that JPAContainer don't support custom Filters as filtering is done on DB level. Only basic Filter implementations are supported. If more complex filtering is needed, developers should tend to QueryModifierDelegate that allows developers to use JPA Criteria API to modify queries.

Specified by:
addContainerFilter in interface com.vaadin.data.Container.Filterable
Throws:
com.vaadin.data.util.filter.UnsupportedFilterException
See Also:
Container.Filterable.addContainerFilter(com.vaadin.data.Container.Filter)

removeContainerFilter

public void removeContainerFilter(com.vaadin.data.Container.Filter filter)
Specified by:
removeContainerFilter in interface com.vaadin.data.Container.Filterable

addItemAt

public Object addItemAt(int index)
                 throws UnsupportedOperationException
This functionality is not supported by this implementation.

Specified by:
addItemAt in interface com.vaadin.data.Container.Indexed
Throws:
UnsupportedOperationException

addItemAt

public com.vaadin.data.Item addItemAt(int index,
                                      Object newItemId)
                               throws UnsupportedOperationException
This functionality is not supported by this implementation.

Specified by:
addItemAt in interface com.vaadin.data.Container.Indexed
Throws:
UnsupportedOperationException

getIdByIndex

public Object getIdByIndex(int index)
Specified by:
getIdByIndex in interface com.vaadin.data.Container.Indexed

indexOfId

public int indexOfId(Object itemId)
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!

Specified by:
indexOfId in interface com.vaadin.data.Container.Indexed

requireWritableContainer

protected void requireWritableContainer()
                                 throws IllegalStateException,
                                        UnsupportedOperationException
Checks that the container is writable, i.e. the entity provider implements the MutableEntityProvider interface 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

public Object addEntity(T entity)
                 throws UnsupportedOperationException,
                        IllegalStateException
Description copied from interface: EntityContainer
Adds a new entity to the container. The corresponding EntityItem can then be accessed by calling EntityContainer.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 using Buffered.commit().

Specified by:
addEntity in interface EntityContainer<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.

Specified by:
removeAllItems in interface com.vaadin.data.Container

removeItem

public boolean removeItem(Object itemId)
                   throws UnsupportedOperationException
Specified by:
removeItem in interface com.vaadin.data.Container
Specified by:
removeItem in interface com.vaadin.data.Container.Hierarchical
Throws:
UnsupportedOperationException

commit

public void commit()
            throws com.vaadin.data.Buffered.SourceException,
                   com.vaadin.data.Validator.InvalidValueException
Specified by:
commit in interface com.vaadin.data.Buffered
Throws:
com.vaadin.data.Buffered.SourceException
com.vaadin.data.Validator.InvalidValueException

discard

public void discard()
             throws com.vaadin.data.Buffered.SourceException
Specified by:
discard in interface com.vaadin.data.Buffered
Throws:
com.vaadin.data.Buffered.SourceException

isModified

public boolean isModified()
Specified by:
isModified in interface com.vaadin.data.Buffered

isReadThrough

public boolean isReadThrough()

isWriteThrough

public boolean isWriteThrough()

setReadThrough

public void setReadThrough(boolean readThrough)
                    throws com.vaadin.data.Buffered.SourceException
This functionality is not supported by this implementation.

Throws:
com.vaadin.data.Buffered.SourceException

setWriteThrough

public void setWriteThrough(boolean writeThrough)
                     throws com.vaadin.data.Buffered.SourceException,
                            com.vaadin.data.Validator.InvalidValueException

Note, that write-through mode can only be turned off if the entity provider implements the BatchableEntityProvider interface.

Throws:
com.vaadin.data.Buffered.SourceException
com.vaadin.data.Validator.InvalidValueException

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws com.vaadin.data.Buffered.SourceException,
                          com.vaadin.data.Validator.InvalidValueException
Description copied from interface: EntityContainer
Alias of Buffered#setWriteThrough(boolean) .

Specified by:
setAutoCommit in interface EntityContainer<T>
Throws:
com.vaadin.data.Buffered.SourceException
com.vaadin.data.Validator.InvalidValueException

isAutoCommit

public boolean isAutoCommit()
Description copied from interface: EntityContainer
Alias of Buffered#isWriteThrough() .

Specified by:
isAutoCommit in interface EntityContainer<T>

getParentProperty

public String getParentProperty()
Description copied from interface: HierarchicalEntityContainer
Gets the name of the persistent property that contains the reference to the parent entity.

Specified by:
getParentProperty in interface HierarchicalEntityContainer<T>
Returns:
the name of the parent property, or null if not specified.

setParentProperty

public void setParentProperty(String parentProperty)
Description copied from interface: HierarchicalEntityContainer
Sets 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:
setParentProperty in interface HierarchicalEntityContainer<T>
Parameters:
parentProperty - the name of the parent property.

areChildrenAllowed

public boolean areChildrenAllowed(Object itemId)
Specified by:
areChildrenAllowed in interface com.vaadin.data.Container.Hierarchical

getChildren

public Collection<?> getChildren(Object itemId)
Specified by:
getChildren in interface com.vaadin.data.Container.Hierarchical

getParent

public Object getParent(Object itemId)
Specified by:
getParent in interface com.vaadin.data.Container.Hierarchical

hasChildren

public boolean hasChildren(Object itemId)
Specified by:
hasChildren in interface com.vaadin.data.Container.Hierarchical

isRoot

public boolean isRoot(Object itemId)
Specified by:
isRoot in interface com.vaadin.data.Container.Hierarchical

rootItemIds

public Collection<?> rootItemIds()
Specified by:
rootItemIds in interface com.vaadin.data.Container.Hierarchical

setChildrenAllowed

public boolean setChildrenAllowed(Object itemId,
                                  boolean areChildrenAllowed)
                           throws UnsupportedOperationException
This functionality is not supported by this implementation.

Specified by:
setChildrenAllowed in interface com.vaadin.data.Container.Hierarchical
Throws:
UnsupportedOperationException

setParent

public boolean setParent(Object itemId,
                         Object newParentId)
                  throws UnsupportedOperationException
This functionality is not supported by this implementation.

Specified by:
setParent in interface com.vaadin.data.Container.Hierarchical
Throws:
UnsupportedOperationException

getPropertyKind

public PropertyKind getPropertyKind(Object propertyId)
Specified by:
getPropertyKind in interface EntityContainer<T>
Returns:
the type of property indentified by given propertyId

refreshItem

public void refreshItem(Object itemId)
Description copied from interface: EntityContainer
Causes all EntityItems created from this container and identified by given entityId to be refreshed.

Specified by:
refreshItem in interface EntityContainer<T>
See Also:
EntityItem.refresh()

refresh

public void refresh()
Description copied from interface: EntityContainer
Refreshes the entire container from the database. All unsaved data will be lost.

Specified by:
refresh in interface EntityContainer<T>

getQueryModifierDelegate

public QueryModifierDelegate getQueryModifierDelegate()
Description copied from interface: EntityContainer
Gets the QueryModifierDelegate set for this container. EntityProviders will the delegate returned by this method in their queries.

Specified by:
getQueryModifierDelegate in interface EntityContainer<T>
Returns:
QueryModifierDelegate to control queries built by this container

setQueryModifierDelegate

public void setQueryModifierDelegate(QueryModifierDelegate queryModifierDelegate)
Sets the QueryModifierDelegate, which is called in the different stages that the EntityProvider builds a criteria query.

Parameters:
queryModifierDelegate - the delegate.

setBuffered

public void setBuffered(boolean buffered)
Specified by:
setBuffered in interface com.vaadin.data.Buffered

isBuffered

public boolean isBuffered()
Specified by:
isBuffered in interface com.vaadin.data.Buffered

addItemSetChangeListener

public void addItemSetChangeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
Specified by:
addItemSetChangeListener in interface com.vaadin.data.Container.ItemSetChangeNotifier

removeItemSetChangeListener

public void removeItemSetChangeListener(com.vaadin.data.Container.ItemSetChangeListener listener)
Specified by:
removeItemSetChangeListener in interface com.vaadin.data.Container.ItemSetChangeNotifier

getItemIds

public List<?> getItemIds(int startIndex,
                          int numberOfItems)
Specified by:
getItemIds in interface com.vaadin.data.Container.Indexed

getContainerFilters

public Collection<com.vaadin.data.Container.Filter> getContainerFilters()
Specified by:
getContainerFilters in interface com.vaadin.data.Container.Filterable


Copyright © 2013 Vaadin Ltd. All rights reserved.