public class SQLContainer extends Object implements Container, Container.Filterable, Container.Indexed, Container.Sortable, Container.ItemSetChangeNotifier
| Modifier and Type | Class and Description |
|---|---|
static class |
SQLContainer.ItemSetChangeEvent
Simple ItemSetChangeEvent implementation.
|
Container.Indexed.ItemAddEvent, Container.Indexed.ItemRemoveEventContainer.Editor, Container.Filter, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Container.Viewer| Modifier and Type | Field and Description |
|---|---|
static int |
CACHE_RATIO
Number of items to cache = CACHE_RATIO x pageLength
|
static int |
DEFAULT_PAGE_LENGTH |
| Constructor and Description |
|---|
SQLContainer(QueryDelegate delegate)
Creates and initializes SQLContainer using the given QueryDelegate
|
| Modifier and Type | Method and Description |
|---|---|
void |
addContainerFilter(Container.Filter filter)
Adds a filter for the container.
|
void |
addContainerFilter(Object propertyId,
String filterString,
boolean ignoreCase,
boolean onlyMatchPrefix) |
boolean |
addContainerProperty(Object propertyId,
Class<?> type,
Object defaultValue)
Adds a new Property to all Items in the Container.
|
Object |
addItem()
Note! If auto commit mode is enabled, this method will still return the
temporary row ID assigned for the item.
|
Item |
addItem(Object itemId)
Creates a new Item with the given ID in the Container.
|
Object |
addItemAfter(Object previousItemId)
Adds a new item after the given item.
|
Item |
addItemAfter(Object previousItemId,
Object newItemId)
Adds a new item after the given item.
|
Object |
addItemAt(int index)
Adds a new item at given index (in the filtered view).
|
Item |
addItemAt(int index,
Object newItemId)
Adds a new item at given index (in the filtered view).
|
void |
addItemSetChangeListener(Container.ItemSetChangeListener listener)
Adds an Item set change listener for the object.
|
void |
addListener(Container.ItemSetChangeListener listener)
Deprecated.
As of 7.0, replaced by
addItemSetChangeListener(Container.ItemSetChangeListener) |
void |
addListener(QueryDelegate.RowIdChangeListener listener)
Deprecated.
As of 7.0, replaced by
#addRowIdChangeListener(RowIdChangeListener) |
void |
addOrderBy(OrderBy orderBy)
Adds the given OrderBy to this container and refreshes the container
contents with the new sorting rules.
|
void |
addReference(SQLContainer refdCont,
String refingCol,
String refdCol)
Adds a new reference to the given SQLContainer.
|
void |
addRowIdChangeListener(QueryDelegate.RowIdChangeListener listener)
Adds a RowIdChangeListener to the QueryDelegate
|
void |
commit()
Commits all the changes, additions and removals made to the items of this
container.
|
boolean |
containsId(Object itemId)
Tests if the Container contains the specified Item.
|
void |
enableCacheFlushNotifications()
Calling this will enable this SQLContainer to send and receive cache
flush notifications for its lifetime.
|
protected void |
fireContentsChange() |
Object |
firstItemId()
Gets the ID of the first Item in the Container.
|
Collection<Container.Filter> |
getContainerFilters()
Returns the filters which have been applied to the container
|
Property |
getContainerProperty(Object itemId,
Object propertyId)
Gets the Property identified by the given itemId and propertyId from the
Container.
|
Collection<?> |
getContainerPropertyIds()
Gets the ID's of all Properties stored in the Container.
|
Object |
getIdByIndex(int index)
Get the item id for the item at the position given by
index. |
Item |
getItem(Object itemId)
Gets the
Item with the given Item ID from the Container. |
Collection<?> |
getItemIds()
NOTE! Do not use this method if in any way avoidable.
|
List<Object> |
getItemIds(int startIndex,
int numberOfIds)
Get
numberOfItems consecutive item ids from the
container, starting with the item id at startIndex. |
Item |
getItemUnfiltered(Object itemId)
Bypasses in-memory filtering to return items that are cached in memory.
|
int |
getPageLength()
Returns the currently set page length.
|
protected QueryDelegate |
getQueryDelegate()
Returns the QueryDelegate set for this SQLContainer.
|
Item |
getReferencedItem(Object itemId,
SQLContainer refdCont)
Fetches the referenced item from the target SQLContainer.
|
Object |
getReferencedItemId(Object itemId,
SQLContainer refdCont)
Fetches the Item Id of the referenced item from the target SQLContainer.
|
Collection<?> |
getSortableContainerPropertyIds()
Gets the container property IDs which can be used to sort the items.
|
Class<?> |
getType(Object propertyId)
Gets the data type of all Properties identified by the given Property ID.
|
boolean |
hasContainerFilters()
Returns true if any filters have been applied to the container.
|
int |
indexOfId(Object itemId)
Gets the index of the Item corresponding to the itemId.
|
boolean |
isAutoCommit()
Returns status of the auto commit mode.
|
boolean |
isFirstId(Object itemId)
Tests if the Item corresponding to the given Item ID is the first
Item in the Container.
|
boolean |
isLastId(Object itemId)
Tests if the Item corresponding to the given Item ID is the last Item
in the Container.
|
boolean |
isModified()
Returns modify state of the container.
|
Object |
lastItemId()
Gets the ID of the last Item in the Container..
|
Object |
nextItemId(Object itemId)
Gets the ID of the Item following the Item that corresponds to
itemId. |
Object |
prevItemId(Object itemId)
Gets the ID of the Item preceding the Item that corresponds to
itemId. |
void |
refresh()
Refreshes the container - clears all caches and resets size and offset.
|
void |
removeAllContainerFilters()
Remove all active filters from the container.
|
boolean |
removeAllItems()
Removes all Items from the Container.
|
void |
removeContainerFilter(Container.Filter filter)
Removes a filter from the container.
|
void |
removeContainerFilters(Object propertyId) |
boolean |
removeContainerProperty(Object propertyId)
Removes a Property specified by the given Property ID from the Container.
|
boolean |
removeItem(Object itemId)
Removes the Item identified by
ItemId from the Container. |
void |
removeItemSetChangeListener(Container.ItemSetChangeListener listener)
Removes the Item set change listener from the object.
|
void |
removeListener(Container.ItemSetChangeListener listener)
Deprecated.
As of 7.0, replaced by
removeItemSetChangeListener(Container.ItemSetChangeListener) |
void |
removeListener(QueryDelegate.RowIdChangeListener listener)
Deprecated.
As of 7.0, replaced by
#removeRowIdChangeListener(RowIdChangeListener) |
boolean |
removeReference(SQLContainer refdCont)
Removes the reference pointing to the given SQLContainer.
|
void |
removeRowIdChangeListener(QueryDelegate.RowIdChangeListener listener)
Removes a RowIdChangeListener from the QueryDelegate
|
void |
rollback()
Rolls back all the changes, additions and removals made to the items of
this container.
|
void |
setAutoCommit(boolean autoCommitEnabled)
Set auto commit mode enabled or disabled.
|
void |
setPageLength(int pageLength)
Sets the page length used in lazy fetching of items from the data source.
|
boolean |
setReferencedItem(Object itemId,
Object refdItemId,
SQLContainer refdCont)
Sets the referenced item.
|
int |
size()
Gets the number of visible Items in the Container.
|
void |
sort(Object[] propertyId,
boolean[] ascending)
Sorts the container items.
|
public static final int DEFAULT_PAGE_LENGTH
public static final int CACHE_RATIO
public SQLContainer(QueryDelegate delegate) throws SQLException
delegate - QueryDelegate implementationSQLExceptionpublic Object addItem() throws UnsupportedOperationException
The new ID is returned, or null if the operation fails.
After a successful call you can use the method to fetch the Item.
getItem
This functionality is optional.
addItem in interface Containernull in case of a
failureUnsupportedOperationException - if adding an item without an explicit item ID is not
supported by the containerpublic boolean containsId(Object itemId)
ContainerFiltering 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.
containsId in interface ContaineritemId - ID the of Item to be testedpublic Property getContainerProperty(Object itemId, Object propertyId)
Containernull is
returned.getContainerProperty in interface ContaineritemId - ID of the visible Item which contains the PropertypropertyId - ID of the Property to retrievenullpublic Collection<?> getContainerPropertyIds()
ContainergetContainerPropertyIds in interface Containerpublic Item getItem(Object itemId)
ContainerItem with the given Item ID from the Container. If the
Container does not contain the requested Item, null is
returned.
Containers should not return Items that are filtered out.
public Item getItemUnfiltered(Object itemId)
itemId - the id of the item to retrieve.public Collection<?> getItemIds()
If the container is Container.Ordered, the collection returned by this
method should follow that order. If the container is Container.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.
getItemIds in interface Containerpublic Class<?> getType(Object propertyId)
Containerpublic int size()
ContainerFiltering can hide items so that they will not be visible through the container API.
public boolean removeItem(Object itemId) throws UnsupportedOperationException
ContainerItemId from the Container.
Containers that support filtering should also allow removing an item that is currently filtered out.
This functionality is optional.
removeItem in interface ContaineritemId - ID of the Item to removetrue if the operation succeeded, false
if notUnsupportedOperationException - if the container does not support removing individual itemspublic boolean removeAllItems()
throws UnsupportedOperationException
ContainerNote that Property ID and type information is preserved. This functionality is optional.
removeAllItems in interface Containertrue if the operation succeeded, false
if notUnsupportedOperationException - if the container does not support removing all itemspublic void addContainerFilter(Container.Filter filter) throws UnsupportedFilterException
If a container has multiple filters, only items accepted by all filters are visible.
addContainerFilter in interface Container.FilterableUnsupportedFilterException - if the filter is not supported by the containerpublic void removeContainerFilter(Container.Filter filter)
This requires that the equals() method considers the filters as equivalent (same instance or properly implemented equals() method).
removeContainerFilter in interface Container.Filterablepublic void addContainerFilter(Object propertyId, String filterString, boolean ignoreCase, boolean onlyMatchPrefix)
public void removeContainerFilters(Object propertyId)
public void removeAllContainerFilters()
removeAllContainerFilters in interface Container.Filterablepublic boolean hasContainerFilters()
public Collection<Container.Filter> getContainerFilters()
Container.FilterablegetContainerFilters in interface Container.Filterablepublic int indexOfId(Object itemId)
Container.Indexedtrue for the returned index: 0 <= index < size(), or
index = -1 if there is no visible item with that id in the container.indexOfId in interface Container.IndexeditemId - ID of an Item in the Containerpublic Object getIdByIndex(int index)
Container.Indexedindex.
getIdByIndex in interface Container.Indexedindex - the index of the requested item idpublic List<Object> getItemIds(int startIndex, int numberOfIds)
Container.IndexednumberOfItems consecutive item ids from the
container, starting with the item id at startIndex.
Implementations should return at most numberOfItems item
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:
startIndex to
max(startIndex + (numberOfItems-1), container.size()-1).
For quick migration to new API see:
ContainerHelpers#getItemIdsUsingGetIdByIndex(int, int, Indexed)
getItemIds in interface Container.IndexedstartIndex - the index for the first item which id to includenumberOfIds - the number of consecutive item ids to get from the given
start index, must be >= 0numberOfItems == 0; not nullpublic Object nextItemId(Object itemId)
Container.OrdereditemId. If the given Item is the last or not found in
the Container, null is returned.nextItemId in interface Container.OrdereditemId - ID of a visible Item in the Containernullpublic Object prevItemId(Object itemId)
Container.OrdereditemId. If the given Item is the first or not found in
the Container, null is returned.prevItemId in interface Container.OrdereditemId - ID of a visible Item in the Containernullpublic Object firstItemId()
Container.OrderedfirstItemId in interface Container.Orderedpublic Object lastItemId()
Container.OrderedlastItemId in interface Container.Orderedpublic boolean isFirstId(Object itemId)
Container.OrderedisFirstId in interface Container.OrdereditemId - ID of an Item in the Containertrue if the Item is first visible item in the
Container, false if notpublic boolean isLastId(Object itemId)
Container.OrderedisLastId in interface Container.Orderedtrue if the Item is last visible item in the
Container, false if notpublic void sort(Object[] propertyId, boolean[] ascending)
Container.SortableSorting a container can irreversibly change the order of its items or only change the order temporarily, depending on the container.
sort in interface Container.SortablepropertyId - 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 by
Container.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. Use true to
sort in ascending order, false to use
descending order.public Collection<?> getSortableContainerPropertyIds()
Container.SortablegetSortableContainerPropertyIds in interface Container.Sortablepublic void refresh()
public boolean isModified()
public void setAutoCommit(boolean autoCommitEnabled)
autoCommitEnabled - true to enable auto commit modepublic boolean isAutoCommit()
public int getPageLength()
public void setPageLength(int pageLength)
pageLength - new page lengthpublic void addOrderBy(OrderBy orderBy)
orderBy - OrderBy to be added to the container sorting rulespublic void commit()
throws UnsupportedOperationException,
SQLException
public void rollback()
throws UnsupportedOperationException,
SQLException
protected QueryDelegate getQueryDelegate()
public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) throws UnsupportedOperationException
ContainerThis functionality is optional.
addContainerProperty in interface ContainerpropertyId - ID of the Propertytype - Data type of the new PropertydefaultValue - The value all created Properties are initialized totrue if the operation succeeded, false
if notUnsupportedOperationException - if the container does not support explicitly adding container
propertiespublic boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException
ContainerThis functionality is optional.
removeContainerProperty in interface ContainerpropertyId - ID of the Property to removetrue if the operation succeeded, false
if notUnsupportedOperationException - if the container does not support removing container
propertiespublic Item addItem(Object itemId) throws UnsupportedOperationException
Container
The new Item is returned, and it is ready to have its Properties
modified. Returns null if the operation fails or the
Container already contains a Item with the given ID.
This functionality is optional.
addItem in interface ContaineritemId - ID of the Item to be creatednull in case of a failureUnsupportedOperationException - if adding an item with an explicit item ID is not supported
by the containerpublic Item addItemAfter(Object previousItemId, Object newItemId) throws UnsupportedOperationException
Container.OrderedAdding an item after null item adds the item as first item of the ordered container.
addItemAfter in interface Container.OrderedpreviousItemId - Id of the visible item in ordered container after which to
insert the new item.newItemId - Id of the new item to be added.UnsupportedOperationException - if the operation is not supported by the containerOrdered: adding items in filtered or sorted containerspublic Item addItemAt(int index, Object newItemId) throws UnsupportedOperationException
Container.IndexedThe 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.Filterable and
Container.Sortable for more information.
addItemAt in interface Container.Indexedindex - Index (in the filtered and sorted view) at which to add
the new item.newItemId - Id of the new item to be added.Item or null if the operation fails.UnsupportedOperationException - if the operation is not supported by the containerpublic Object addItemAt(int index) throws UnsupportedOperationException
Container.IndexedThe 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.Filterable and Container.Sortable for more information.
addItemAt in interface Container.Indexedindex - Index (in the filtered and sorted view) to add the new
item.UnsupportedOperationException - if the operation is not supported by the containerpublic Object addItemAfter(Object previousItemId) throws UnsupportedOperationException
Container.OrderedAdding an item after null item adds the item as first item of the ordered container.
addItemAfter in interface Container.OrderedpreviousItemId - Id of the visible item in ordered container after which to
insert the new item.UnsupportedOperationException - if the operation is not supported by the containerOrdered: adding items in filtered or sorted containerspublic void addItemSetChangeListener(Container.ItemSetChangeListener listener)
Container.ItemSetChangeNotifieraddItemSetChangeListener in interface Container.ItemSetChangeNotifierlistener - listener to be added@Deprecated public void addListener(Container.ItemSetChangeListener listener)
addItemSetChangeListener(Container.ItemSetChangeListener)addListener in interface Container.ItemSetChangeNotifierpublic void removeItemSetChangeListener(Container.ItemSetChangeListener listener)
Container.ItemSetChangeNotifierremoveItemSetChangeListener in interface Container.ItemSetChangeNotifierlistener - listener to be removed@Deprecated public void removeListener(Container.ItemSetChangeListener listener)
removeItemSetChangeListener(Container.ItemSetChangeListener)removeListener in interface Container.ItemSetChangeNotifierprotected void fireContentsChange()
public void addRowIdChangeListener(QueryDelegate.RowIdChangeListener listener)
listener - @Deprecated public void addListener(QueryDelegate.RowIdChangeListener listener)
#addRowIdChangeListener(RowIdChangeListener)public void removeRowIdChangeListener(QueryDelegate.RowIdChangeListener listener)
listener - @Deprecated public void removeListener(QueryDelegate.RowIdChangeListener listener)
#removeRowIdChangeListener(RowIdChangeListener)public void enableCacheFlushNotifications()
public void addReference(SQLContainer refdCont, String refingCol, String refdCol)
refdCont - Target SQLContainer of the new referencerefingCol - Column (property) name in this container storing the (foreign
key) referencerefdCol - Column (property) name in the referenced container storing the
referenced keypublic boolean removeReference(SQLContainer refdCont)
refdCont - Target SQLContainer of the referencepublic boolean setReferencedItem(Object itemId, Object refdItemId, SQLContainer refdCont)
itemId - Item Id of the reference source (from this container)refdItemId - Item Id of the reference target (from referenced container)refdCont - Target SQLContainer of the referencepublic Object getReferencedItemId(Object itemId, SQLContainer refdCont)
itemId - Item Id of the reference source (from this container)refdCont - Target SQLContainer of the referencepublic Item getReferencedItem(Object itemId, SQLContainer refdCont)
itemId - Item Id of the reference source (from this container)refdCont - Target SQLContainer of the referenceCopyright © 2019 Vaadin Ltd. All rights reserved.