Revision 112ab4f7
Added by Katja Luther about 5 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IdentifiableServiceBase.java | ||
---|---|---|
23 | 23 |
import org.springframework.transaction.annotation.Transactional; |
24 | 24 |
|
25 | 25 |
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator; |
26 |
import eu.etaxonomy.cdm.api.service.dto.CdmEntityIdentifier; |
|
26 | 27 |
import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO; |
27 | 28 |
import eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO; |
28 | 29 |
import eu.etaxonomy.cdm.api.service.pager.Pager; |
... | ... | |
256 | 257 |
|
257 | 258 |
@Override |
258 | 259 |
@Transactional(readOnly = false) |
259 |
public void updateCaches() {
|
|
260 |
updateCaches(null, null, null, null); |
|
260 |
public UpdateResult updateCaches() {
|
|
261 |
return updateCaches(null, null, null, null);
|
|
261 | 262 |
} |
262 | 263 |
|
263 | 264 |
@Transactional(readOnly = false) //TODO check transactional behavior, e.g. what happens with the session if count is very large |
264 |
protected <S extends T > void updateCachesImpl(Class<S> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<T> cacheStrategy, IProgressMonitor monitor) {
|
|
265 |
protected <S extends T > UpdateResult updateCachesImpl(Class<S> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<T> cacheStrategy, IProgressMonitor monitor) {
|
|
265 | 266 |
if (stepSize == null){ |
266 | 267 |
stepSize = UPDATE_TITLE_CACHE_DEFAULT_STEP_SIZE; |
267 | 268 |
} |
268 | 269 |
if (monitor == null){ |
269 | 270 |
monitor = DefaultProgressMonitor.NewInstance(); |
270 | 271 |
} |
271 |
|
|
272 |
UpdateResult result = new UpdateResult(); |
|
272 | 273 |
long count = dao.count(clazz); |
273 | 274 |
long countUpdated = 0; |
274 | 275 |
monitor.beginTask("update titles for " + clazz.getSimpleName(), Long.valueOf(count).intValue()); |
275 | 276 |
int worked = 0; |
277 |
Set<CdmEntityIdentifier> updatedCdmIds = new HashSet(); |
|
276 | 278 |
for(int i = 0 ; i < count ; i = i + stepSize){ |
277 | 279 |
// not sure if such strict ordering is necessary here, but for safety reasons I do it |
278 | 280 |
ArrayList<OrderHint> orderHints = new ArrayList<>(); |
... | ... | |
288 | 290 |
entity = HibernateProxyHelper.deproxy(entity); |
289 | 291 |
if (entity.updateCaches(cacheStrategy)){ |
290 | 292 |
countUpdated++; |
293 |
updatedCdmIds.add(new CdmEntityIdentifier(entity.getId(), clazz)); |
|
291 | 294 |
} |
292 | 295 |
worked++; |
296 |
monitor.internalWorked(1); |
|
293 | 297 |
} |
294 | 298 |
|
295 |
monitor.worked(list.size()); |
|
299 |
|
|
296 | 300 |
if (monitor.isCanceled()){ |
297 | 301 |
break; |
298 | 302 |
} |
299 | 303 |
} |
300 | 304 |
monitor.done(); |
305 |
result.addUpdatedCdmIds(updatedCdmIds); |
|
306 |
return result; |
|
301 | 307 |
} |
302 | 308 |
|
303 | 309 |
/** |
Also available in: Unified diff
ref #8096: move cache updater and service methods return updateResult