com.vaadin.addon.jpacontainer.provider
Class CachingBatchableLocalEntityProvider<T>

java.lang.Object
  extended by com.vaadin.addon.jpacontainer.provider.LocalEntityProvider<T>
      extended by com.vaadin.addon.jpacontainer.provider.MutableLocalEntityProvider<T>
          extended by com.vaadin.addon.jpacontainer.provider.CachingMutableLocalEntityProvider<T>
              extended by com.vaadin.addon.jpacontainer.provider.CachingBatchableLocalEntityProvider<T>
All Implemented Interfaces:
BatchableEntityProvider<T>, CachingEntityProvider<T>, EntityProvider<T>, EntityProviderChangeNotifier<T>, MutableEntityProvider<T>, Serializable
Direct Known Subclasses:
CachingBatchableEntityProvider

public class CachingBatchableLocalEntityProvider<T>
extends CachingMutableLocalEntityProvider<T>
implements BatchableEntityProvider<T>

A very simple implementation of BatchableEntityProvider with caching support that simply passes itself to the BatchUpdateCallback. No data consistency checks are performed.

Since:
1.0
Author:
Petter Holmström (Vaadin Ltd)
See Also:
CachingMutableLocalEntityProvider, BatchableLocalEntityProvider, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.addon.jpacontainer.BatchableEntityProvider
BatchableEntityProvider.BatchUpdateCallback<T>
 
Constructor Summary
CachingBatchableLocalEntityProvider(Class<T> entityClass)
          Creates a new CachingBatchableLocalEntityProvider.
CachingBatchableLocalEntityProvider(Class<T> entityClass, javax.persistence.EntityManager entityManager)
          Creates a new CachingBatchableLocalEntityProvider.
 
Method Summary
 void batchUpdate(BatchableEntityProvider.BatchUpdateCallback<T> callback)
          Executes a batch update using the specified callback parameter.
 
Methods inherited from class com.vaadin.addon.jpacontainer.provider.CachingMutableLocalEntityProvider
addEntity, containsEntity, flush, getAllEntityIdentifiers, getEntity, getEntityCacheMaxSize, getEntityCount, getEntityIdentifierAt, getFirstEntityIdentifier, getLastEntityIdentifier, getNextEntityIdentifier, getPreviousEntityIdentifier, isCacheEnabled, isCloneCachedEntities, isEntitiesDetached, refresh, refreshEntity, removeEntity, setCacheEnabled, setCloneCachedEntities, setEntityCacheMaxSize, updateEntity, updateEntityProperty, usesCache
 
Methods inherited from class com.vaadin.addon.jpacontainer.provider.MutableLocalEntityProvider
addListener, fireEntityProviderChangeEvent, isFireEntityProviderChangeEvent, isTransactionsHandledByProvider, removeListener, runInTransaction, setFireEntityProviderChangeEvents, setTransactionsHandledByProvider
 
Methods inherited from class com.vaadin.addon.jpacontainer.provider.LocalEntityProvider
addPrimaryKeyToSortList, createFilteredQuery, createSiblingQuery, createUnsortedFilteredQuery, detachEntity, doContainsEntity, doGetAllEntityIdentifiers, doGetEntity, doGetEntityCount, doGetEntityIdentifierAt, doGetEntityManager, doGetFirstEntityIdentifier, doGetLastEntityIdentifier, doGetNextEntityIdentifier, doGetPreviousEntityIdentifier, getEntityClassMetadata, getEntityManager, getEntityManagerProvider, getIdentifier, getLazyLoadingDelegate, getQueryModifierDelegate, getSibling, readResolve, setEntitiesDetached, setEntityManager, setEntityManagerProvider, setLazyLoadingDelegate, setQueryModifierDelegate, translateSortBy, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.addon.jpacontainer.MutableEntityProvider
addEntity, removeEntity, updateEntity, updateEntityProperty
 
Methods inherited from interface com.vaadin.addon.jpacontainer.EntityProvider
containsEntity, getAllEntityIdentifiers, getEntity, getEntityCount, getEntityIdentifierAt, getEntityManager, getEntityManagerProvider, getFirstEntityIdentifier, getIdentifier, getLastEntityIdentifier, getLazyLoadingDelegate, getNextEntityIdentifier, getPreviousEntityIdentifier, getQueryModifierDelegate, isEntitiesDetached, refresh, refreshEntity, setEntitiesDetached, setEntityManager, setEntityManagerProvider, setLazyLoadingDelegate, setQueryModifierDelegate
 
Methods inherited from interface com.vaadin.addon.jpacontainer.CachingEntityProvider
setEntitiesDetached
 

Constructor Detail

CachingBatchableLocalEntityProvider

public CachingBatchableLocalEntityProvider(Class<T> entityClass)
Creates a new CachingBatchableLocalEntityProvider. The entity manager must be set using LocalEntityProvider.setEntityManager(javax.persistence.EntityManager).

Parameters:
entityClass - the entity class (must not be null).

CachingBatchableLocalEntityProvider

public CachingBatchableLocalEntityProvider(Class<T> entityClass,
                                           javax.persistence.EntityManager entityManager)
Creates a new CachingBatchableLocalEntityProvider.

Parameters:
entityClass - the entity class (must not be null).
entityManager - the entity manager to use (must not be null).
Method Detail

batchUpdate

public void batchUpdate(BatchableEntityProvider.BatchUpdateCallback<T> callback)
                 throws UnsupportedOperationException
Description copied from interface: BatchableEntityProvider
Executes a batch update using the specified callback parameter. The batch update should be run inside a single transaction. The implementation may either handle the transaction itself, or rely on external transaction handling provided by a container such as Spring or EJB. If the batch update fails, the entire transaction should be rolled back and an exception thrown. Otherwise, it should be committed.

Clients should instantiate BatchableEntityProvider.BatchUpdateCallback, implement the BatchableEntityProvider.BatchUpdateCallback.batchUpdate(MutableEntityProvider) method and execute the updates as if they were using an ordinary MutableEntityProvider. The following example saves a list of transient entities:

  provider.batchUpdate(new BatchUpdateCallback() {
      public void batchUpdate(MutableEntityProvider batchEnabledEntityProvider) {
          for (Entity e : myListOfEntitiesToAdd) {
              batchEnabledEntityProvider.addEntity(e);
          }
      }
  });
 

Specified by:
batchUpdate in interface BatchableEntityProvider<T>
Parameters:
callback - the callback that will be used to run the batch update.
Throws:
UnsupportedOperationException - if this entity provider does not support batch updates.


Copyright © 2013 Vaadin Ltd. All rights reserved.