Class JPAContainerItem<T>
- All Implemented Interfaces:
Buffered,Item,EntityItem<T>,Property.ValueChangeNotifier,Serializable
EntityItem-implementation that is used by JPAContainer.
Should not be used directly by clients.- Since:
- 1.0
- Author:
- Petter Holmström (Vaadin Ltd)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.featurepack.data.Buffered
Buffered.SourceExceptionNested classes/interfaces inherited from interface com.vaadin.featurepack.data.Item
Item.Editor, Item.PropertySetChangeEvent, Item.PropertySetChangeListener, Item.PropertySetChangeNotifier, Item.Viewer -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddItemProperty(Object id, Property property) This functionality is not supported.voidaddListener(Property.ValueChangeListener listener) Registers a new value change listener for all the properties of this item.voidaddNestedContainerProperty(String nestedProperty) Originally, all nested properties are inherited from theEntityContainer.voidRegisters a new value change listener for this Property.voidcommit()Updates all changes since the previous commit to the data source.voiddiscard()Discards all changes since last commit.Gets the container that contains this item.Gets the underlying entity instance that contains the actual data being accessed by this item.Gets the item ID of the item.Gets the Property corresponding to the given Property ID stored in the Item.Gets the collection of IDs of all Properties stored in the Item.booleanChecks the buffered modebooleanChecks whether this item has been marked for deletion.booleanisDirty()Checks whether the underlying entity (returned byEntityItem.getEntity()) has been modified after it was fetched from the entity provider.booleanWhen using item-level buffering, this method tests whether there are changes made to the EntityItem that have not yet been committed to the underlying Entity (EntityItem.getEntity()).booleanChecks if the underlying entity (EntityItem.getEntity()) is persistent (i.e. fetched from a persistence storage) or transient (created and buffered by the container).booleanbooleanvoidrefresh()This method refreshes persisted entity from EntityProvider and calls value change listeners for all properties.booleanRemoves a nested property added withEntityItem.addNestedContainerProperty(java.lang.String).voidremoveListener(Property.ValueChangeListener listener) Removes a previously registered value change listener.voidRemoves a previously registered value change listener.voidsetBuffered(boolean buffered) Sets the buffered mode to the specified status.voidsetReadThrough(boolean readThrough) voidsetWriteThrough(boolean writeThrough) toString()
-
Method Details
-
getItemId
Description copied from interface:EntityItemGets the item ID of the item. This ID can be used to uniquely identify the item inside the container. It may not necessarily be the same as the entity ID.If the item ID is null, the entity item was created by a container, but not yet added to it.
- Specified by:
getItemIdin interfaceEntityItem<T>- Returns:
- the item ID or null if the item is not yet inside a container.
- See Also:
-
addItemProperty
Description copied from interface:EntityItemThis functionality is not supported.Tries to add a new Property into the Item.
This functionality is optional.
- Specified by:
addItemPropertyin interfaceEntityItem<T>- Specified by:
addItemPropertyin interfaceItem- Parameters:
id- ID of the new Propertyproperty- the Property to be added and associated with the id- Returns:
trueif the operation succeeded,falseif not- Throws:
UnsupportedOperationException- always thrown.
-
addNestedContainerProperty
Description copied from interface:EntityItemOriginally, all nested properties are inherited from theEntityContainer. However, if additional properties are needed, this method can be used to add the nested propertynestedPropertyto the set of properties for this particular item.Otherwise, this method behaves just like
EntityContainer.addNestedContainerProperty(java.lang.String).- Specified by:
addNestedContainerPropertyin interfaceEntityItem<T>- Parameters:
nestedProperty- the nested property to add (must not be null).- Throws:
UnsupportedOperationException- if nested properties are not supported by the container.
-
getItemProperty
Description copied from interface:EntityItemGets the Property corresponding to the given Property ID stored in the Item. If the Item does not contain the Property,nullis returned.- Specified by:
getItemPropertyin interfaceEntityItem<T>- Specified by:
getItemPropertyin interfaceItem- Parameters:
id- identifier of the Property to get- Returns:
- the Property with the given ID or
null
-
getItemPropertyIds
Description copied from interface:EntityItemGets the collection of IDs of all Properties stored in the Item.In practice, this means all the properties of the underlying entity class, any nested properties defined in the container and any nested properties added using
EntityItem.addNestedContainerProperty(java.lang.String). Any non-nested properties that have been removed from the container will still show up in this collection.- Specified by:
getItemPropertyIdsin interfaceEntityItem<T>- Specified by:
getItemPropertyIdsin interfaceItem- Returns:
- unmodifiable collection containing IDs of the Properties stored the Item
-
removeItemProperty
Description copied from interface:EntityItemRemoves a nested property added withEntityItem.addNestedContainerProperty(java.lang.String). This method cannot be used to remove any other properties.- Specified by:
removeItemPropertyin interfaceEntityItem<T>- Specified by:
removeItemPropertyin interfaceItem- Parameters:
id- the ID (name) of the nested property.- Returns:
- true if a nested property was removed by this method, false otherwise.
- Throws:
UnsupportedOperationException- if the implementation does not support removing nested properties.
-
isModified
public boolean isModified()Description copied from interface:EntityItemWhen using item-level buffering, this method tests whether there are changes made to the EntityItem that have not yet been committed to the underlying Entity (EntityItem.getEntity()). If item-level buffering is not used, this method always returns false.- Specified by:
isModifiedin interfaceBuffered- Specified by:
isModifiedin interfaceEntityItem<T>- Returns:
- true if
returns false and there are changes that have not yet been commited to the underlying Entity, false otherwise.
invalid reference
#isWriteThrough() - See Also:
-
isDirty
public boolean isDirty()Description copied from interface:EntityItemChecks whether the underlying entity (returned byEntityItem.getEntity()) has been modified after it was fetched from the entity provider. When the changes have been persisted, this flag will be reset.This flag is only of relevance when container buffering is used. If the container is in write-through mode, any changes made to the entity will automatically be propagated back to the entity provider and hence, this method will always return false as there are no dirty entities.
However, if container write-through mode is turned off, any changes made to the entity will not be propagated back until explicitly committed. Modified entities that have not yet been propagated back to the entity provider are considered dirty.
Please note, that this is not the same as the
EntityItem.isModified()flag, which is of relevance when item buffering is used.If the item is not persistent, this method always returns false.
- Specified by:
isDirtyin interfaceEntityItem<T>- Returns:
- true if the underlying entity has been modified, false if not.
-
isPersistent
public boolean isPersistent()Description copied from interface:EntityItemChecks if the underlying entity (EntityItem.getEntity()) is persistent (i.e. fetched from a persistence storage) or transient (created and buffered by the container). This method always returns false ifEntityItem.getItemId()is null, even if the underlying entity actually is persistent.- Specified by:
isPersistentin interfaceEntityItem<T>- Returns:
- true if the underlying entity is persistent, false if it is transient.
-
isDeleted
public boolean isDeleted()Description copied from interface:EntityItemChecks whether this item has been marked for deletion. This method can only return true ifEntityItem.isPersistent()is true and the container is running in buffered mode.- Specified by:
isDeletedin interfaceEntityItem<T>- Returns:
- true if the item has been deleted, false otherwise.
-
getContainer
Description copied from interface:EntityItemGets the container that contains this item. IfEntityItem.getItemId()is null, the container created the item but does not yet contain it.- Specified by:
getContainerin interfaceEntityItem<T>- Returns:
- the container (never null).
-
getEntity
Description copied from interface:EntityItemGets the underlying entity instance that contains the actual data being accessed by this item.- Specified by:
getEntityin interfaceEntityItem<T>- Returns:
- the entity (never null).
-
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.
-
isReadThrough
public boolean isReadThrough() -
isWriteThrough
public boolean isWriteThrough() -
setReadThrough
- Throws:
Buffered.SourceException
-
setWriteThrough
public void setWriteThrough(boolean writeThrough) throws Buffered.SourceException, Validator.InvalidValueException -
addListener
Description copied from interface:EntityItemRegisters a new value change listener for all the properties of this item.- Specified by:
addListenerin interfaceEntityItem<T>- Parameters:
listener- the new listener to be registered.
-
removeListener
Description copied from interface:EntityItemRemoves a previously registered value change listener. The listener will be unregistered from all the properties of this item.- Specified by:
removeListenerin interfaceEntityItem<T>- Parameters:
listener- listener to be removed.
-
addValueChangeListener
Description copied from interface:Property.ValueChangeNotifierRegisters a new value change listener for this Property.- Specified by:
addValueChangeListenerin interfaceProperty.ValueChangeNotifier- Parameters:
listener- the new Listener to be registered
-
removeValueChangeListener
Description copied from interface:Property.ValueChangeNotifierRemoves a previously registered value change listener.- Specified by:
removeValueChangeListenerin interfaceProperty.ValueChangeNotifier- Parameters:
listener- listener to be removed
-
toString
-
refresh
public void refresh()Description copied from interface:EntityItemThis method refreshes persisted entity from EntityProvider and calls value change listeners for all properties.The method can be used to update one item if developer know it has been changed either straight to the entity object or to backend.
Note, that in case the write buffering and
EntityItem.isDirty()flag is on, all changes will be lost and property values are overridden from the backend.Also note that the entire container might get reloaded when calling this method when e.g. the entity has been deleted from the database.
- Specified by:
refreshin interfaceEntityItem<T>
-
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
-