import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
import eu.etaxonomy.cdm.api.service.pager.Pager;
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
-import eu.etaxonomy.cdm.common.IProgressMonitor;
+import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
+import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.ISourceable;
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
import eu.etaxonomy.cdm.model.common.LSID;
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
import eu.etaxonomy.cdm.model.media.Rights;
+import eu.etaxonomy.cdm.model.name.NonViralName;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
import eu.etaxonomy.cdm.persistence.dao.common.IIdentifiableDao;
return new DefaultPagerImpl<IdentifiableSource>(pageNumber, numberOfResults, pageSize, results);
}
- @Transactional(readOnly = true)
- protected List<T> findByTitle(IIdentifiableEntityServiceConfigurator config){
- return ((IIdentifiableDao)dao).findByTitle(config.getTitleSearchString(),
- config.getMatchMode(), 0, -1, null);
- // TODO: Implement parameters pageSize, pageNumber, and criteria
- }
@Transactional(readOnly = false)
public T replace(T x, T y) {
return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);\r
}
+ @Transactional(readOnly = true)
+ public Pager<T> findByTitle(IIdentifiableEntityServiceConfigurator<T> config){
+ return findByTitle(config.getClazz(), config.getTitleSearchStringSqlized(), config.getMatchMode(), config.getCriteria(), config.getPageSize(), config.getPageNumber(), config.getOrderHints(), config.getPropertyPaths());
+ }
+
@Transactional(readOnly = true)
public List<T> listByTitle(Class<? extends T> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
Integer numberOfResults = dao.countByTitle(clazz, queryString, matchmode, criteria);
}
return results;
}
+
+ @Transactional(readOnly = true)
+ public Pager<T> findTitleCache(Class<? extends T> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, MatchMode matchMode){
+ long numberOfResults = dao.countTitleCache(clazz, queryString, matchMode);
+
+ List<T> results = new ArrayList<T>();
+ if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
+ results = dao.findTitleCache(clazz, queryString, pageSize, pageNumber, orderHints, matchMode);
+ }
+ int r = 0;
+ r += numberOfResults;
+
+ return new DefaultPagerImpl<T>(pageNumber, r , pageSize, results);
+ }
@Transactional(readOnly = true)
public List<T> listByReferenceTitle(Class<? extends T> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
* @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache()
*/
@Override
+ @Transactional(readOnly = false)
public void updateTitleCache() {
updateTitleCache(null, null, null, null);
}
if (stepSize == null){
stepSize = UPDATE_TITLE_CACHE_DEFAULT_STEP_SIZE;
}
-
+ if (monitor == null){
+ monitor = DefaultProgressMonitor.NewInstance();
+ }
+
int count = dao.count(clazz);
+ monitor.beginTask("update titles", count);
+ int worked = 0;
for(int i = 0 ; i < count ; i = i + stepSize){
// not sure if such strict ordering is necessary here, but for safety reasons I do it
ArrayList<OrderHint> orderHints = new ArrayList<OrderHint>();
List<T> entitiesToUpdate = new ArrayList<T>();
for (T entity : list){
if (entity.isProtectedTitleCache() == false){
- IIdentifiableEntityCacheStrategy entityCacheStrategy = cacheStrategy;
- if (entityCacheStrategy == null){
- entityCacheStrategy = entity.getCacheStrategy();
- //FIXME find out why the wrong cache strategy is loaded here, see #1876
- if (entity instanceof Reference){
- entityCacheStrategy = ReferenceFactory.newReference(((Reference)entity).getType()).getCacheStrategy();
- }
- }
- entity.setCacheStrategy(entityCacheStrategy);
- //TODO this won't work for those classes that always generate the title cache new
- String titleCache = entity.getTitleCache();
- setOtherCachesNull(entity); //TODO find better solution
- String newTitleCache = entityCacheStrategy.getTitleCache(entity);
- if (titleCache == null || titleCache != null && ! titleCache.equals(newTitleCache)){
- entity.setTitleCache(null, false);
- entity.getTitleCache();
- entitiesToUpdate.add(entity);
- }
+ updateTitleCacheForSingleEntity(cacheStrategy, entitiesToUpdate, entity);
+ }
+ worked++;
+ }
+ for (T entity: entitiesToUpdate){
+ if (entity.getTitleCache() != null){
+ //System.err.println(entity.getTitleCache());
+ }else{
+ //System.err.println("no titleCache" + ((NonViralName)entity).getNameCache());
}
}
saveOrUpdate(entitiesToUpdate);
-
+ monitor.worked(list.size());
+ if (monitor.isCanceled()){
+ monitor.done();
+ return;
+ }
+ }
+ monitor.done();
+ }
+
+ /**
+ * @param cacheStrategy
+ * @param entitiesToUpdate
+ * @param entity
+ */
+ /**
+ * @param cacheStrategy
+ * @param entitiesToUpdate
+ * @param entity
+ */
+ private void updateTitleCacheForSingleEntity(
+ IIdentifiableEntityCacheStrategy<T> cacheStrategy,
+ List<T> entitiesToUpdate, T entity) {
+
+ assert (entity.isProtectedTitleCache() == false );
+
+ //exclude recursive inreferences
+ if (entity.isInstanceOf(Reference.class)){
+ Reference<?> ref = CdmBase.deproxy(entity, Reference.class);
+ if (ref.getInReference() != null && ref.getInReference().equals(ref)){
+ return;
+ }
+ }
+
+
+ //define the correct cache strategy
+ IIdentifiableEntityCacheStrategy entityCacheStrategy = cacheStrategy;
+ if (entityCacheStrategy == null){
+ entityCacheStrategy = entity.getCacheStrategy();
+ //FIXME find out why the wrong cache strategy is loaded here, see #1876
+ if (entity instanceof Reference){
+ entityCacheStrategy = ReferenceFactory.newReference(((Reference)entity).getType()).getCacheStrategy();
+ }
+ }
+ entity.setCacheStrategy(entityCacheStrategy);
+
+
+ //old titleCache
+ entity.setProtectedTitleCache(true);
+ String oldTitleCache = entity.getTitleCache();
+ entity.setProtectedTitleCache(false);
+
+ //NonViralNames have more caches //TODO handle in NameService
+ String oldNameCache = null;
+ String oldFullTitleCache = null;
+ if (entity instanceof NonViralName ){
+ NonViralName<?> nvn = (NonViralName) entity;
+ if (!nvn.isProtectedNameCache()){
+ nvn.setProtectedNameCache(true);
+ oldNameCache = nvn.getNameCache();
+ nvn.setProtectedNameCache(false);
+ }
+ if (!nvn.isProtectedFullTitleCache()){
+ nvn.setProtectedFullTitleCache(true);
+ oldFullTitleCache = nvn.getFullTitleCache();
+ nvn.setProtectedFullTitleCache(false);
+ }
+ }
+ setOtherCachesNull(entity); //TODO find better solution
+
+ String newTitleCache = entityCacheStrategy.getTitleCache(entity);
+ if (oldTitleCache == null || oldTitleCache != null && ! oldTitleCache.equals(newTitleCache) ){
+ entity.setTitleCache(null, false);
+ entity.getTitleCache();
+ if (entity instanceof NonViralName){
+ NonViralName<?> nvn = (NonViralName) entity;
+ nvn.getNameCache();
+ nvn.getFullTitleCache();
+ }
+ entitiesToUpdate.add(entity);
+ }else if (entity instanceof NonViralName){
+ NonViralName<?> nvn = (NonViralName) entity;
+ String newnameCache = nvn.getNameCache();
+ String newFullTitleCache = nvn.getFullTitleCache();
+ if (oldNameCache == null || (oldNameCache != null && !oldNameCache.equals(newnameCache))){
+ entitiesToUpdate.add(entity);
+ }else if (oldFullTitleCache == null || (oldFullTitleCache != null && !oldFullTitleCache.equals(newFullTitleCache))){
+ entitiesToUpdate.add(entity);
+ }
}
}
* @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#deduplicate(java.lang.Class, eu.etaxonomy.cdm.strategy.match.IMatchStrategy, eu.etaxonomy.cdm.strategy.merge.IMergeStrategy)
*/
@Override
- @Transactional(propagation = Propagation.SUPPORTS, readOnly = false)
+ @Transactional(readOnly = false)
public int deduplicate(Class<? extends T> clazz, IMatchStrategy matchStrategy, IMergeStrategy mergeStrategy) {
DeduplicateState dedupState = new DeduplicateState();
}
return result;
}
+
+ public Integer countByTitle(Class<? extends T> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria){
+ Integer numberOfResults = dao.countByTitle(clazz, queryString, matchmode, criteria);
+
+ return numberOfResults;
+ }
+
+ @Transactional(readOnly = true)
+ public Integer countByTitle(IIdentifiableEntityServiceConfigurator<T> config){
+ return countByTitle(config.getClazz(), config.getTitleSearchStringSqlized(),
+ config.getMatchMode(), config.getCriteria());
+
+ }
}\r