Project

General

Profile

Revision d2deb7ca

IDd2deb7ca51c4d6e575bbb863ea0205a6ea1eb9c8
Parent 568fb7dc
Child ff628107

Added by Katja Luther over 1 year ago

ref #8096: use subprogressmonitor for cache updater

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/longrunningService/LongRunningTasksServiceImpl.java
150 150
            @Override
151 151
            public Serializable doRun(IRemotingProgressMonitor monitor) {
152 152
                UpdateResult result;
153

  
153 154
                configurator.setMonitor(monitor);
154 155

  
155 156
                result = updater.doInvoke(configurator);
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IdentifiableServiceBase.java
262 262
	}
263 263

  
264 264
	@Transactional(readOnly = false)  //TODO check transactional behavior, e.g. what happens with the session if count is very large
265
	protected <S extends T > UpdateResult 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 subMonitor) {
266 266
		if (stepSize == null){
267 267
			stepSize = UPDATE_TITLE_CACHE_DEFAULT_STEP_SIZE;
268 268
		}
269
		if (monitor == null){
270
			monitor = DefaultProgressMonitor.NewInstance();
269
		if (subMonitor == null){
270
		    subMonitor = DefaultProgressMonitor.NewInstance();
271 271
		}
272 272
		UpdateResult result = new UpdateResult();
273 273
		long count = dao.count(clazz);
274 274
		long countUpdated = 0;
275
		monitor.beginTask("update titles for " + clazz.getSimpleName(), Long.valueOf(count).intValue());
276
		int worked = 0;
277
		Set<CdmEntityIdentifier> updatedCdmIds = new HashSet();
278
		for(int i = 0 ; i < count ; i = i + stepSize){
279
			// not sure if such strict ordering is necessary here, but for safety reasons I do it
280
			ArrayList<OrderHint> orderHints = new ArrayList<>();
281
			orderHints.add( new OrderHint("id", OrderHint.SortOrder.ASCENDING));
282

  
283

  
284
			Map<Class<? extends CdmBase>, AutoPropertyInitializer<CdmBase>> oldAutoInit = switchOfAutoinitializer();
285
			List<S> list = this.list(clazz, stepSize, i, orderHints, null);
286
			switchOnOldAutoInitializer(oldAutoInit);
287

  
288
			List<T> entitiesToUpdate = new ArrayList<>();
289
			for (T entity : list){
290
				entity = HibernateProxyHelper.deproxy(entity);
291
			    if (entity.updateCaches(cacheStrategy)){
292
			        countUpdated++;
293
			        updatedCdmIds.add(new CdmEntityIdentifier(entity.getId(), clazz));
294
			    }
295
				worked++;
296
				monitor.internalWorked(1);
297
			}
298 275

  
276
		try {
277
		    subMonitor.beginTask("update titles for " + clazz.getSimpleName(), Long.valueOf(count).intValue());
278

  
279

  
280
    		//SubProgressMonitor subMonitor = monitor.("update titles for " + clazz.getSimpleName(), Long.valueOf(count).intValue());
281
    		int worked = 0;
282
    		Set<CdmEntityIdentifier> updatedCdmIds = new HashSet();
283
    		for(int i = 0 ; i < count ; i = i + stepSize){
284
    			// not sure if such strict ordering is necessary here, but for safety reasons I do it
285
    			ArrayList<OrderHint> orderHints = new ArrayList<>();
286
    			orderHints.add( new OrderHint("id", OrderHint.SortOrder.ASCENDING));
287

  
288

  
289
    			Map<Class<? extends CdmBase>, AutoPropertyInitializer<CdmBase>> oldAutoInit = switchOfAutoinitializer();
290
    			List<S> list = this.list(clazz, stepSize, i, orderHints, null);
291
    			switchOnOldAutoInitializer(oldAutoInit);
292

  
293
    			List<T> entitiesToUpdate = new ArrayList<>();
294
    			for (T entity : list){
295
    				entity = HibernateProxyHelper.deproxy(entity);
296
    			    if (entity.updateCaches(cacheStrategy)){
297
    			        countUpdated++;
298
    			        updatedCdmIds.add(new CdmEntityIdentifier(entity.getId(), clazz));
299
    			    }
300
    				worked++;
301
    				subMonitor.internalWorked(1);
302
    			}
303

  
304

  
305
    			if (subMonitor.isCanceled()){
306
    				break;
307
    			}
308
    		}
309
    		result.addUpdatedCdmIds(updatedCdmIds);
310
    	} finally {
311
            subMonitor.done();
312
        }
299 313

  
300
			if (monitor.isCanceled()){
301
				break;
302
			}
303
		}
304
		monitor.done();
305
		result.addUpdatedCdmIds(updatedCdmIds);
306 314
		return result;
307 315
	}
308 316

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/util/CacheUpdater.java
25 25
import eu.etaxonomy.cdm.api.service.UpdateResult;
26 26
import eu.etaxonomy.cdm.api.service.config.CacheUpdaterConfigurator;
27 27
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
28
import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor;
28 29
import eu.etaxonomy.cdm.model.agent.AgentBase;
29 30
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
30 31
import eu.etaxonomy.cdm.model.description.DescriptionBase;
......
97 98
			logger.warn("Create class list from boolean values is not yet implemented for cache updater");
98 99
			createClassListFromBoolean();
99 100
		}
100

  
101
		config.getMonitor().beginTask("Update Caches", 100);
101 102
		//handle class list
102 103
		result = handleClassList(config.getClassList(), config.getMonitor());
103

  
104
		config.getMonitor().done();
104 105
		return result;
105 106
	}
106 107

  
107 108

  
108 109
	private UpdateResult handleClassList(List<Class<? extends IdentifiableEntity>> classList, IProgressMonitor monitor) {
109 110
	    UpdateResult result = new UpdateResult();
111
	    int ticksForSubTasks = 100/classList.size();
110 112
		for (Class<? extends IdentifiableEntity> clazz : classList){
111 113
			//WE need to separate classes , because hibernate
112 114
			//returns multiple values for service.count() for e.g. IdentifableEntity.class
......
114 116
		    UpdateResult multipleResult = handleMultiTableClasses(clazz, monitor);
115 117

  
116 118
			if (multipleResult == null){
117
				result.includeResult(this.handleSingleTableClass(clazz, monitor));
119
			    SubProgressMonitor subMonitor= new SubProgressMonitor(monitor, ticksForSubTasks);
120
				result.includeResult(this.handleSingleTableClass(clazz, subMonitor));
118 121
			}else{
119 122
			    result.includeResult(multipleResult);
120 123
			}
......
146 149

  
147 150
	}
148 151

  
149
	private UpdateResult handleSingleTableClass(Class<? extends IdentifiableEntity> clazz, IProgressMonitor monitor) {
152
	private UpdateResult handleSingleTableClass(Class<? extends IdentifiableEntity> clazz, IProgressMonitor subMonitor) {
150 153

  
151 154
		UpdateResult result = new UpdateResult();
152 155
		if (clazz == null){
153 156
            return result;
154 157
        }
155 158
	    logger.info("Updating class " + clazz.getSimpleName() + " ...");
159

  
156 160
		try {
157 161
			//TermBase
158 162
			if (DefinedTermBase.class.isAssignableFrom(clazz)){
159 163

  
160
			    result.includeResult(termService.updateCaches((Class) clazz, null, null, monitor));
164
			    result.includeResult(termService.updateCaches((Class) clazz, null, null, subMonitor));
161 165
			}else if (FeatureTree.class.isAssignableFrom(clazz)){
162
			    result.includeResult(featureTreeService.updateCaches((Class) clazz, null, null, monitor));
166
			    result.includeResult(featureTreeService.updateCaches((Class) clazz, null, null, subMonitor));
163 167
			}else if (TermVocabulary.class.isAssignableFrom(clazz)){
164
			    result.includeResult(vocabularyService.updateCaches((Class) clazz, null, null, monitor));
168
			    result.includeResult(vocabularyService.updateCaches((Class) clazz, null, null, subMonitor));
165 169
			}
166 170
			//DescriptionBase
167 171
			else if (DescriptionBase.class.isAssignableFrom(clazz)){
168
			    result.includeResult(descriptionService.updateCaches((Class) clazz, null, null, monitor));
172
			    result.includeResult(descriptionService.updateCaches((Class) clazz, null, null, subMonitor));
169 173
			}
170 174
			//Media
171 175
			else if (Media.class.isAssignableFrom(clazz)){
172
			    result.includeResult(mediaService.updateCaches((Class) clazz, null, null, monitor));
176
			    result.includeResult(mediaService.updateCaches((Class) clazz, null, null, subMonitor));
173 177
			}//TaxonBase
174 178
			else if (TaxonBase.class.isAssignableFrom(clazz)){
175
			    result.includeResult(taxonService.updateCaches((Class) clazz, null, null, monitor));
179
			    result.includeResult(taxonService.updateCaches((Class) clazz, null, null, subMonitor));
176 180
			}
177 181
			//IdentifiableMediaEntity
178 182
			else if (AgentBase.class.isAssignableFrom(clazz)){
179
			    result.includeResult(agentService.updateCaches((Class) clazz, null, null, monitor));
183
			    result.includeResult(agentService.updateCaches((Class) clazz, null, null, subMonitor));
180 184
			}else if (Collection.class.isAssignableFrom(clazz)){
181
			    result.includeResult(collectionService.updateCaches((Class) clazz, null, null, monitor));
185
			    result.includeResult(collectionService.updateCaches((Class) clazz, null, null, subMonitor));
182 186
			}else if (Reference.class.isAssignableFrom(clazz)){
183
			    result.includeResult(referenceService.updateCaches((Class) clazz, null, null, monitor));
187
			    result.includeResult(referenceService.updateCaches((Class) clazz, null, null, subMonitor));
184 188
			}else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)){
185
			    result.includeResult(occurrenceService.updateCaches((Class) clazz, null, null, monitor));
189
			    result.includeResult(occurrenceService.updateCaches((Class) clazz, null, null, subMonitor));
186 190

  
187 191
			}
188 192
//			//Sequence  //currently not identifiable and therefore has not caches
......
193 197
			//TaxonName
194 198
			else if (TaxonName.class.isAssignableFrom(clazz)){
195 199

  
196
			    result.includeResult(nameService.updateCaches((Class) clazz, null, null, null));
200
			    result.includeResult(nameService.updateCaches((Class) clazz, null, null, subMonitor));
197 201
			}
198 202
			//Classification
199 203
			else if (Classification.class.isAssignableFrom(clazz)){
200
			    result.includeResult(classificationService.updateCaches((Class) clazz, null, null, null));
204
			    result.includeResult(classificationService.updateCaches((Class) clazz, null, null, subMonitor));
201 205
			}
202 206
			//Polytomous Key
203 207
            else if (PolytomousKey.class.isAssignableFrom(clazz)){
204
                result.includeResult(polytomousKeyService.updateCaches((Class) clazz, null, null, null));
208
                result.includeResult(polytomousKeyService.updateCaches((Class) clazz, null, null, subMonitor));
205 209

  
206 210
            }
207 211

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)