
com.vaadin.addon.jpacontainer.provider.CachingMutableLocalEntityProvider Maven / Gradle / Ivy
/*
JPAContainer
Copyright (C) 2009-2011 Oy Vaadin Ltd
This program is available under GNU Affero General Public License (version
3 or later at your option).
See the file licensing.txt distributed with this software for more
information about licensing.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
package com.vaadin.addon.jpacontainer.provider;
import com.vaadin.addon.jpacontainer.CachingEntityProvider;
import com.vaadin.addon.jpacontainer.Filter;
import com.vaadin.addon.jpacontainer.SortBy;
import java.util.List;
import javax.persistence.EntityManager;
/**
* En extended version of {@link MutableLocalEntityProvider} that also implements the {@link CachingEntityProvider} interface.
*
* This provider can be used in applications in the same manner as {@link MutableLocalEntityProvider}, with a few exceptions. By default,
* the cache is turned off which means that this provider effectively works as a {@link MutableLocalEntityProvider}. The cache
* can be turned on using {@link #setCacheInUse(boolean) }.
*
* If you are going to edit the entities returned by the container, you should check the {@link #setCloneCachedEntities(boolean) } before
* continuing.
*
* @author Petter Holmström (Vaadin Ltd)
* @since 1.0
*/
public class CachingMutableLocalEntityProvider extends MutableLocalEntityProvider implements CachingEntityProvider {
private CachingSupport cachingSupport = new CachingSupport(this);
/**
* Creates a new CachingMutableLocalEntityProvider
.
*
* @param entityClass
* the entity class (must not be null).
* @param entityManager
* the entity manager to use (must not be null).
*/
public CachingMutableLocalEntityProvider(Class entityClass, EntityManager entityManager) {
super(entityClass, entityManager);
}
/**
* Creates a new CachingLocalEntityProvider
. The entity manager must
* be set using {@link #setEntityManager(javax.persistence.EntityManager) }.
*
* @param entityClass
* the entity class (must not be null).
*/
public CachingMutableLocalEntityProvider(Class entityClass) {
super(entityClass);
}
public void flush() {
cachingSupport.flush();
}
public int getEntityCacheMaxSize() {
return cachingSupport.getMaxCacheSize();
}
public boolean isCacheInUse() {
return cachingSupport.isCacheInUse();
}
public void setCacheInUse(boolean cacheInUse) {
cachingSupport.setCacheInUse(cacheInUse);
}
public void setEntityCacheMaxSize(int maxSize) {
cachingSupport.setMaxCacheSize(maxSize);
}
@Override
public boolean containsEntity(Object entityId, Filter filter) {
return cachingSupport.containsEntity(entityId, filter);
}
@Override
public List