Project

General

Profile

Revision aa20ae50

IDaa20ae50785ad40cd39bc169e3fecfe1427f343c
Parent a7c45326
Child d173c335

Added by Katja Luther over 1 year ago

ref #8096: move cache updater and service methods return updateResult

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/operation/CacheUpdaterWithNewCacheStrategy.java
1
package eu.etaxonomy.cdm.io.operation;
2

  
3
import java.util.List;
4

  
5
import org.apache.log4j.Logger;
6
import org.springframework.stereotype.Component;
7

  
8
import eu.etaxonomy.cdm.io.common.DefaultImportState;
9
import eu.etaxonomy.cdm.io.operation.config.CacheUpdaterConfigurator;
10
import eu.etaxonomy.cdm.model.agent.AgentBase;
11
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
12
import eu.etaxonomy.cdm.model.description.DescriptionBase;
13
import eu.etaxonomy.cdm.model.description.FeatureTree;
14
import eu.etaxonomy.cdm.model.media.Media;
15
import eu.etaxonomy.cdm.model.molecular.Sequence;
16
import eu.etaxonomy.cdm.model.name.TaxonName;
17
import eu.etaxonomy.cdm.model.occurrence.Collection;
18
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
19
import eu.etaxonomy.cdm.model.reference.Reference;
20
import eu.etaxonomy.cdm.model.taxon.Classification;
21
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
22
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.term.TermVocabulary;
24
import eu.etaxonomy.cdm.strategy.cache.taxon.TaxonBaseShortSecCacheStrategy;
25

  
26
@Component
27
public class CacheUpdaterWithNewCacheStrategy extends CacheUpdater {
28

  
29
    private static final long serialVersionUID = 8720272266844232502L;
30
    private static final Logger logger = Logger.getLogger(CacheUpdaterWithNewCacheStrategy.class);
31

  
32
	@Override
33
	protected void doInvoke(DefaultImportState<CacheUpdaterConfigurator> state) {
34
		CacheUpdaterConfigurator config = state.getConfig();
35

  
36
		//handle class list
37
		handleClassList(config.getClassList());
38

  
39
		return;
40
	}
41

  
42
	private boolean handleClassList(List<Class<? extends IdentifiableEntity>> classList) {
43
		boolean result = true;
44
		for (Class<? extends IdentifiableEntity> clazz : classList){
45
			//WE need to separate classes , because hibernate
46
			//returns multiple values for service.count() for e.g. IdentifableEntity.class
47
			//which leads to an exception
48
			result &= this.handleSingleTableClass(clazz);
49
		}
50
		return result;
51
	}
52

  
53

  
54
	private boolean handleSingleTableClass(Class<? extends IdentifiableEntity> clazz) {
55
		logger.warn("Updating class " + clazz.getSimpleName() + " ...");
56
		try {
57
			//TermBase
58
			if (DefinedTermBase.class.isAssignableFrom(clazz)){
59
				getTermService().updateCaches((Class) clazz, null, null, null);
60
			}else if (FeatureTree.class.isAssignableFrom(clazz)){
61
				getFeatureTreeService().updateCaches((Class) clazz, null, null, null);
62
			}else if (TermVocabulary.class.isAssignableFrom(clazz)){
63
				getVocabularyService().updateCaches((Class) clazz, null, null, null);
64
			}
65
			//DescriptionBase
66
			else if (DescriptionBase.class.isAssignableFrom(clazz)){
67
				getDescriptionService().updateCaches((Class) clazz, null, null, null);
68
			}
69
			//Media
70
			else if (Media.class.isAssignableFrom(clazz)){
71
				getMediaService().updateCaches((Class) clazz, null, null, null);
72
			}//TaxonBase
73
			else if (TaxonBase.class.isAssignableFrom(clazz)){
74
				TaxonBaseShortSecCacheStrategy<TaxonBase> cacheStrategy = new TaxonBaseShortSecCacheStrategy<TaxonBase>();
75
				getTaxonService().updateCaches((Class) clazz, null,cacheStrategy , null);
76
			}
77
			//IdentifiableMediaEntity
78
			else if (AgentBase.class.isAssignableFrom(clazz)){
79
				getAgentService().updateCaches((Class) clazz, null, null, null);
80
			}else if (Collection.class.isAssignableFrom(clazz)){
81
				getCollectionService().updateCaches((Class) clazz, null, null, null);
82
			}else if (Reference.class.isAssignableFrom(clazz)){
83
				getReferenceService().updateCaches((Class) clazz, null, null, null);
84
			}else if (SpecimenOrObservationBase.class.isAssignableFrom(clazz)){
85
				getOccurrenceService().updateCaches((Class) clazz, null, null, null);
86
			}
87
			//Sequence
88
			else if (Sequence.class.isAssignableFrom(clazz)){
89
				//TODO misuse TaxonServic for sequence update, use sequence service when it exists
90
				getTaxonService().updateCaches((Class) clazz, null, null, null);
91
			}
92
			//TaxonName
93
			else if (TaxonName.class.isAssignableFrom(clazz)){
94
				getNameService().updateCaches((Class) clazz, null, null, null);
95
			}
96
			//Classification
97
			else if (Classification.class.isAssignableFrom(clazz)){
98
				getClassificationService().updateCaches((Class) clazz, null, null, null);
99
			}
100
			//unknown class
101
			else {
102
				String warning = "Unknown identifable entity subclass + " + clazz.getName();
103
				logger.error(warning);
104
				return false;
105
				//getTaxonService().updateTitleCache((Class) clazz);
106
			}
107
			return true;
108
		} catch (Exception e) {
109
			String warning = "Exception occurred when trying to update class + " + clazz.getName();
110
			warning += " Exception was: " + e.getMessage();
111
			logger.error(warning);
112
			e.printStackTrace();
113
			return false;
114
		}
115
	}
116

  
117
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/operation/SortIndexUpdaterWrapper.java
1
/**
2
* Copyright (C) 2016 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.io.operation;
10

  
11
import java.sql.SQLException;
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.Map;
15
import java.util.Set;
16

  
17
import org.apache.log4j.Logger;
18
import org.hibernate.SQLQuery;
19
import org.springframework.stereotype.Component;
20
import org.springframework.transaction.TransactionStatus;
21

  
22
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
23
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
24
import eu.etaxonomy.cdm.database.update.SortIndexUpdater;
25
import eu.etaxonomy.cdm.io.common.CdmImportBase;
26
import eu.etaxonomy.cdm.io.common.DefaultImportState;
27
import eu.etaxonomy.cdm.io.operation.config.SortIndexUpdaterConfigurator;
28

  
29
/**
30
 * @author k.luther
31
 * @since 08.07.2016
32
 *
33
 */
34
@Component
35
public class SortIndexUpdaterWrapper extends CdmImportBase<SortIndexUpdaterConfigurator, DefaultImportState<SortIndexUpdaterConfigurator>> {
36

  
37
    private static final long serialVersionUID = 1152526455024556637L;
38
    private static final Logger logger = Logger.getLogger(SortIndexUpdaterWrapper.class);
39

  
40

  
41
    @Override
42
    protected void doInvoke(DefaultImportState<SortIndexUpdaterConfigurator> state) {
43
        SortIndexUpdaterConfigurator config =  state.getConfig();
44
        SortIndexUpdater updater;
45

  
46
       // CaseType caseType = CaseType.caseTypeOfDatasource(config.getDestination());
47
        IProgressMonitor  monitor = DefaultProgressMonitor.NewInstance();
48

  
49
        if (config.isDoTaxonNode()){
50
            updater = SortIndexUpdater.NewInstance("Update taxonnode sortindex", "TaxonNode", "parent_id", "sortIndex", true);
51

  
52
            update(updater, monitor);
53

  
54

  
55
        }
56
        if (config.isDoFeatureNode()){
57
            updater = SortIndexUpdater.NewInstance("Update Feature node sortindex", "FeatureNode", "parent_id", "sortIndex", true);
58
            update(updater, monitor);
59
        }
60
        if (config.isDoPolytomousKeyNode()){
61
            updater = SortIndexUpdater.NewInstance("Update Polytomouskey node sortindex", "PolytomousKeyNode", "parent_id", "sortindex", true);
62
           update(updater, monitor);
63
        }
64
        return;
65

  
66
    }
67

  
68
    private void update(SortIndexUpdater updater,  IProgressMonitor  monitor){
69
        try {
70
            TransactionStatus tx;
71
            tx = startTransaction();
72
            String query = updater.createIndexMapQuery();
73
            SQLQuery sqlQuery = getAgentService().getSession().createSQLQuery(query);
74

  
75
            List data = sqlQuery.list();
76

  
77
           List<Integer[]> result = new ArrayList<Integer[]>();
78
           int id;
79
           int parentId;
80
           Object oId;
81
           Object oParentId;
82
           Integer[] rowArray = new Integer[2];
83
            for(Object object : data)
84
            {
85
               Object[] row = (Object[])object;
86
               oId = row[0];
87

  
88
                if (oId != null){
89
                    id = Integer.valueOf(oId.toString());
90
                    rowArray = new Integer[2];
91
                    oParentId = row[1];
92
                    if (oParentId != null){
93
                        parentId = Integer.valueOf(oParentId.toString());
94
                        rowArray[1]= parentId;
95

  
96
                    }else{
97
                        rowArray[1]= null;
98
                    }
99
                    rowArray[0]= id;
100
                    result.add(rowArray);
101
                }
102
            }
103
            Map<Integer, Set<Integer>> indexMap =  updater.makeIndexMap(result);
104
            for (Map.Entry<Integer, Set<Integer>> entry: indexMap.entrySet()){
105
                String idSet = updater.makeIdSetString(entry.getValue());
106
                query = updater.createUpdateIndicesQuery(null,entry.getKey(), idSet);
107
                sqlQuery = getAgentService().getSession().createSQLQuery(query);
108
                int resultInt = sqlQuery.executeUpdate();
109
                logger.debug("update all indice with index "+entry.getKey()+ " - " + resultInt);
110
            }
111
            //Update childrenCount
112
            if (updater.getTableName().equals("TaxonNode")){
113
                query = updater.getChildrenCountQuery();
114
                sqlQuery = getTaxonNodeService().getSession().createSQLQuery(query);
115
                data = sqlQuery.list();
116
                int realCount;
117
                int countChildren;
118
                for(Object object : data)
119
                {
120
                   Object[] row = (Object[])object;
121
                   realCount =  ((Number) row[0]).intValue();
122
                   countChildren = ((Number) row[1]).intValue();
123
                   id = ((Number) row[2]).intValue();
124

  
125
                   if (realCount != countChildren){
126
                       query = updater.getUpdateChildrenCount(realCount, id);
127
                       sqlQuery = getTaxonNodeService().getSession().createSQLQuery(query);
128
                       int resultInt = sqlQuery.executeUpdate();
129
                       logger.debug("update all childrenCount "+ resultInt);
130
                   }
131
                 }
132
            }
133
              commitTransaction(tx);
134
        } catch (SQLException e) {
135

  
136
            monitor.warning("Stopped sortIndex updater");
137
        }
138
    }
139

  
140
    @Override
141
    protected boolean isIgnore(DefaultImportState<SortIndexUpdaterConfigurator> state) {
142
        return false;
143
    }
144

  
145
    /**
146
     * {@inheritDoc}
147
     */
148
    @Override
149
    protected boolean doCheck(DefaultImportState<SortIndexUpdaterConfigurator> state) {
150
        return true;
151
    }
152

  
153
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/operation/config/CacheUpdaterConfigurator.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.io.operation.config;
10

  
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.List;
14

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.database.ICdmDataSource;
18
import eu.etaxonomy.cdm.io.common.DefaultImportState;
19
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
20
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
21
import eu.etaxonomy.cdm.io.common.ImportStateBase;
22
import eu.etaxonomy.cdm.io.operation.CacheUpdater;
23
import eu.etaxonomy.cdm.io.operation.CacheUpdaterWithNewCacheStrategy;
24
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
25
import eu.etaxonomy.cdm.model.reference.Reference;
26

  
27
/**
28
 * @author a.mueller
29
 * @since 02-Jul-2010 13:06:43
30
 *
31
 */
32
public class CacheUpdaterConfigurator extends ImportConfiguratorBase<DefaultImportState<CacheUpdaterConfigurator>, Object> implements IImportConfigurator{
33
	@SuppressWarnings("unused")
34
	private static final Logger logger = Logger.getLogger(CacheUpdaterConfigurator.class);
35

  
36

  
37
	private boolean updateCacheStrategies = false;
38

  
39
	public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination){
40
		return new CacheUpdaterConfigurator(destination, false);
41
	}
42

  
43
	/**
44
	 * Returns a new Configurator with all boolean values set to false
45
	 * @param allFalse
46
	 * @return
47
	 */
48
	public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, boolean allTrue){
49
		return new CacheUpdaterConfigurator(destination, allTrue);
50
	}
51

  
52
	public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, List<Class<? extends IdentifiableEntity>> classList){
53
		CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(destination, true);
54
		result.setClassList(classList);
55
		return result;
56
	}
57

  
58
	public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, Collection<String> classListNames) throws ClassNotFoundException{
59
		CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(destination, true);
60
		List<Class<? extends IdentifiableEntity>> classList = new ArrayList<Class<? extends IdentifiableEntity>>();
61
		for (String className : classListNames){
62
			Class clazz = Class.forName(className);
63
			classList.add(clazz);
64
		}
65
		result.setClassList(classList);
66
		return result;
67
	}
68

  
69
	public static CacheUpdaterConfigurator NewInstance(ICdmDataSource destination, Collection<String> classListNames, boolean doUpdateCacheStrategies) throws ClassNotFoundException{
70
		CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(destination, false);
71
		List<Class<? extends IdentifiableEntity>> classList = new ArrayList<Class<? extends IdentifiableEntity>>();
72
		for (String className : classListNames){
73
			Class clazz = Class.forName(className);
74
			classList.add(clazz);
75
		}
76
		result.setClassList(classList);
77
		result.setUpdateCacheStrategy(doUpdateCacheStrategies);
78
		return result;
79
	}
80

  
81

  
82

  
83
//	//DescriptionBase
84
//	private boolean doTaxonDescription = true;
85
//	private boolean doSpecimenDescription = true;
86
//	private boolean doNameDescription = true;
87
//
88
//	//AgentBase
89
//	private boolean doPerson = true;
90
//	private boolean doTeam = true;
91
//	private boolean doInstitution = true;
92
//
93
//	//MediaEntities
94
//	private boolean doCollection = true;
95
//	private boolean doReferenceBase = true;
96
//
97
//	//SpecimenOrObservationBase
98
//	private boolean doFieldUnit = true;
99
//	private boolean doDeriveUnit = true;
100
//	private boolean doDnaSample = true;
101
//
102
//	//Media
103
//	private boolean doMedia = true;
104
//	private boolean doMediaKey = true;
105
//	private boolean doPhylogenticTree = true;
106
//
107
//
108
//	//TaxonBase
109
//	private boolean doTaxon = true;
110
//	private boolean doSynonym = true;
111
//
112
//	private boolean doSequence = true;
113
//
114
//	//Names
115
//	private boolean doTaxonName = true;
116
//
117
//	private boolean doClassification = true;
118
//
119
//	//TermBase
120
//	private boolean doFeatureTree = true;
121
//	private boolean doPolytomousKey = true;
122
//
123
//	private boolean doTermVocabulary = true;
124
//	private boolean doDefinedTermBase = true;
125
	private List<Class<? extends IdentifiableEntity>> classList;
126

  
127
	private CacheUpdaterConfigurator(ICdmDataSource destination, boolean allFalse){
128
		super(null);
129
		this.setDestination(destination);
130
		this.classList = new ArrayList<Class<? extends IdentifiableEntity>>();
131
		if (allFalse){
132
			//DescriptionBase
133
//			doTaxonDescription = false;
134
//			doSpecimenDescription = false;
135
//			doNameDescription = false;
136
//
137
//			//AgentBase
138
//			doPerson = false;
139
//			doTeam = false;
140
//			doInstitution = false;
141
//
142
//			//MediaEntities
143
//			doCollection = false;
144
//			doReferenceBase = false;
145
//
146
//			//SpecimenOrObservationBase
147
//			doFieldUnit = false;
148
//			doDeriveUnit = false;
149
//			doDnaSample = false;
150
//
151
//			//Media
152
//			doMedia = false;
153
//			doMediaKey = false;
154
//			doPhylogenticTree = false;
155
//
156
//
157
//			//TaxonBase
158
//			doTaxon = false;
159
//			doSynonym = false;
160
//
161
//			doSequence = false;
162
//
163
//			//Names
164
//			doTaxonName = false;
165
//
166
//			doClassification = false;
167
//
168
//			//TermBase
169
//			doFeatureTree = false;
170
//			doPolytomousKey = false;
171
//
172
//			doTermVocabulary = false;
173
//			doDefinedTermBase = false;
174
		}
175
	}
176

  
177

  
178

  
179
// **************** GETTER / SETTER ************************************
180

  
181

  
182
	public List<Class<? extends IdentifiableEntity>> getClassList(){
183
//	    classList.sort(new ClassComparator());
184
		return classList;
185
	}
186
	private void setClassList(List<Class<? extends IdentifiableEntity>> classList) {
187
		this.classList = classList;
188
	}
189

  
190

  
191
//	public void setDoTaxonDescription(boolean doTaxonDescription) {
192
//		this.doTaxonDescription = doTaxonDescription;
193
//	}
194
//	public boolean isDoTaxonDescription() {
195
//		return doTaxonDescription;
196
//	}
197
//	public void setDoSpecimenDescription(boolean doSpecimenDescription) {
198
//		this.doSpecimenDescription = doSpecimenDescription;
199
//	}
200
//	public boolean isDoSpecimenDescription() {
201
//		return doSpecimenDescription;
202
//	}
203
//	public void setDoNameDescription(boolean doNameDescription) {
204
//		this.doNameDescription = doNameDescription;
205
//	}
206
//	public boolean isDoNameDescription() {
207
//		return doNameDescription;
208
//	}
209
//	public void setDoPerson(boolean doPerson) {
210
//		this.doPerson = doPerson;
211
//	}
212
//	public boolean isDoPerson() {
213
//		return doPerson;
214
//	}
215
//	public void setDoTeam(boolean doTeam) {
216
//		this.doTeam = doTeam;
217
//	}
218
//	public boolean isDoTeam() {
219
//		return doTeam;
220
//	}
221
//	public void setDoInstitution(boolean doInstitution) {
222
//		this.doInstitution = doInstitution;
223
//	}
224
//	public boolean isDoInstitution() {
225
//		return doInstitution;
226
//	}
227
//	public void setDoCollection(boolean doCollection) {
228
//		this.doCollection = doCollection;
229
//	}
230
//	public boolean isDoCollection() {
231
//		return doCollection;
232
//	}
233
//	public void setDoReferenceBase(boolean doReferenceBase) {
234
//		this.doReferenceBase = doReferenceBase;
235
//	}
236
//	public boolean isDoReferenceBase() {
237
//		return doReferenceBase;
238
//	}
239
//	public void setDoFieldUnit(boolean doFieldUnit) {
240
//		this.doFieldUnit = doFieldUnit;
241
//	}
242
//	public boolean isDoFieldUnit() {
243
//		return doFieldUnit;
244
//	}
245
//	public void setDoDeriveUnit(boolean doDeriveUnit) {
246
//		this.doDeriveUnit = doDeriveUnit;
247
//	}
248
//	public boolean isDoDeriveUnit() {
249
//		return doDeriveUnit;
250
//	}
251
//	public void setDoDnaSample(boolean doDnaSample) {
252
//		this.doDnaSample = doDnaSample;
253
//	}
254
//	public boolean isDoDnaSample() {
255
//		return doDnaSample;
256
//	}
257
//	public void setDoMedia(boolean doMedia) {
258
//		this.doMedia = doMedia;
259
//	}
260
//	public boolean isDoMedia() {
261
//		return doMedia;
262
//	}
263
//	public void setDoMediaKey(boolean doMediaKey) {
264
//		this.doMediaKey = doMediaKey;
265
//	}
266
//	public boolean isDoMediaKey() {
267
//		return doMediaKey;
268
//	}
269
//	public void setDoPhylogenticTree(boolean doPhylogenticTree) {
270
//		this.doPhylogenticTree = doPhylogenticTree;
271
//	}
272
//	public boolean isDoPhylogenticTree() {
273
//		return doPhylogenticTree;
274
//	}
275
//	public void setDoTaxon(boolean doTaxon) {
276
//		this.doTaxon = doTaxon;
277
//	}
278
//	public boolean isDoTaxon() {
279
//		return doTaxon;
280
//	}
281
//	public void setDoSynonym(boolean doSynonym) {
282
//		this.doSynonym = doSynonym;
283
//	}
284
//	public boolean isDoSynonym() {
285
//		return doSynonym;
286
//	}
287
//	public void setDoSequence(boolean doSequence) {
288
//		this.doSequence = doSequence;
289
//	}
290
//	public boolean isDoSequence() {
291
//		return doSequence;
292
//	}
293
//	public void setDoClassification(boolean doClassification) {
294
//		this.doClassification = doClassification;
295
//	}
296
//	public boolean isDoClassification() {
297
//		return doClassification;
298
//	}
299
//	public void setDoFeatureTree(boolean doFeatureTree) {
300
//		this.doFeatureTree = doFeatureTree;
301
//	}
302
//	public boolean isDoFeatureTree() {
303
//		return doFeatureTree;
304
//	}
305
//	public void setDoPolytomousKey(boolean doPolytomousKey) {
306
//		this.doPolytomousKey = doPolytomousKey;
307
//	}
308
//	public boolean isDoPolytomousKey() {
309
//		return doPolytomousKey;
310
//	}
311
//	public void setDoTermVocabulary(boolean doTermVocabulary) {
312
//		this.doTermVocabulary = doTermVocabulary;
313
//	}
314
//	public boolean isDoTermVocabulary() {
315
//		return doTermVocabulary;
316
//	}
317
//	public void setDoDefinedTermBase(boolean doDefinedTermBase) {
318
//		this.doDefinedTermBase = doDefinedTermBase;
319
//	}
320
//	public boolean isDoDefinedTermBase() {
321
//		return doDefinedTermBase;
322
//	}
323

  
324
	@Override
325
	public Reference getSourceReference() {
326
		//not needed here
327
		return null;
328
	}
329

  
330
	@Override
331
	protected void makeIoClassList() {
332
		if (this.doUpdateCacheStrategy()){
333
			ioClassList = new Class[]{
334
					 CacheUpdaterWithNewCacheStrategy.class
335
			};
336
		}else{
337
			ioClassList = new Class[]{
338
					 CacheUpdater.class
339
			};
340
			}
341
	}
342

  
343
	@Override
344
	public <STATE extends ImportStateBase> STATE getNewState() {
345
		return (STATE) new DefaultImportState(this);
346
	}
347

  
348
	@Override
349
	public boolean isValid() {
350
		//as no source needs to exist
351
		return true;
352
	}
353

  
354
	@Override
355
	public String getSourceNameString() {
356
		//not needed here
357
		return null;
358
	}
359

  
360
	public boolean doUpdateCacheStrategy() {
361
		return updateCacheStrategies;
362
	}
363

  
364
	public void setUpdateCacheStrategy(boolean doUpdateCacheStrategies){
365
		this.updateCacheStrategies = doUpdateCacheStrategies;
366
	}
367

  
368
//	private class ClassComparator implements Comparator<Class>{
369
//
370
//        /**
371
//         * {@inheritDoc}
372
//         */
373
//        @Override
374
//        public int compare(Class o1, Class o2) {
375
//            if (o1.equals(o2)){
376
//                return 0;
377
//            }
378
//            if (o1 == null){
379
//                return -1;
380
//            }
381
//            if (o2 == null){
382
//                return 1;
383
//            }
384
//            if (o1.equals(AgentBase.class)){
385
//                return -1;
386
//            }
387
//            if (o1.equals(Reference.class)){
388
//                if (o2.equals(AgentBase.class)){
389
//                    return 1;
390
//                }else{
391
//                    return -1;
392
//                }
393
//            }
394
//            if (o1.equals(TaxonName.class)){
395
//                if (o2.equals(AgentBase.class) || o2.equals(Reference.class)){
396
//                    return 1;
397
//                }else{
398
//                    return -1;
399
//                }
400
//            }
401
//            if (o1.equals(TaxonBase.class)){
402
//                if (o2.equals(AgentBase.class) || o2.equals(Reference.class) || o2.equals(TaxonName.class)){
403
//                    return 1;
404
//                }else{
405
//                    return -1;
406
//                }
407
//            }
408
//            if (o1.equals(SpecimenOrObservationBase.class)){
409
//                if (o2.equals(AgentBase.class) || o2.equals(Reference.class) || o2.equals(TaxonName.class) || o2.equals(TaxonBase.class)){
410
//                    return 1;
411
//                }else{
412
//                    return -1;
413
//                }
414
//            }
415
//            return 0;
416
//
417
//        }
418
//
419
//	}
420

  
421
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/operation/config/DeleteNonReferencedReferencesConfigurator.java
2 2

  
3 3
import org.apache.log4j.Logger;
4 4

  
5
import eu.etaxonomy.cdm.api.service.config.CacheUpdaterConfigurator;
5 6
import eu.etaxonomy.cdm.database.DbSchemaValidation;
6 7
import eu.etaxonomy.cdm.database.ICdmDataSource;
7 8
import eu.etaxonomy.cdm.io.common.DefaultImportState;
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/operation/config/SortIndexUpdaterConfigurator.java
1
/**
2
* Copyright (C) 2016 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.io.operation.config;
10

  
11
import eu.etaxonomy.cdm.database.ICdmDataSource;
12
import eu.etaxonomy.cdm.io.common.DefaultImportState;
13
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
14
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
15
import eu.etaxonomy.cdm.io.common.ImportStateBase;
16
import eu.etaxonomy.cdm.io.operation.SortIndexUpdaterWrapper;
17
import eu.etaxonomy.cdm.model.reference.Reference;
18

  
19
/**
20
 * @author k.luther
21
 * @since 08.07.2016
22
 *
23
 */
24
public class SortIndexUpdaterConfigurator
25
        extends ImportConfiguratorBase<DefaultImportState<SortIndexUpdaterConfigurator>, Object>
26
        implements IImportConfigurator{
27

  
28

  
29
    private boolean doTaxonNode = true;
30
    private boolean doFeatureNode = true;
31
    private boolean doPolytomousKeyNode = true;
32

  
33
    private SortIndexUpdaterConfigurator(ICdmDataSource destination){
34
        super(null);
35
        this.setDestination(destination);
36
    }
37

  
38
    /**
39
     * @param destination
40
     * @return
41
     */
42
    public static SortIndexUpdaterConfigurator NewInstance(ICdmDataSource destination) {
43
        SortIndexUpdaterConfigurator result = new SortIndexUpdaterConfigurator(destination);
44
        return result;
45
    }
46

  
47
    /**
48
     * @param destination
49
     * @return
50
     */
51
    public static SortIndexUpdaterConfigurator NewInstance(ICdmDataSource destination, boolean doTaxonNode, boolean doFeatureNode, boolean doPolytomousKeyNode) {
52
        SortIndexUpdaterConfigurator result = new SortIndexUpdaterConfigurator(destination);
53
        result.doFeatureNode = doFeatureNode;
54
        result.doTaxonNode = doTaxonNode;
55
        result.doPolytomousKeyNode = doPolytomousKeyNode;
56
        return result;
57
    }
58

  
59

  
60
 // **************** GETTER / SETTER ************************************
61

  
62

  
63
    /**
64
     * @return the doTaxonNode
65
     */
66
    public boolean isDoTaxonNode() {
67
        return doTaxonNode;
68
    }
69
    /**
70
     * @param doTaxonNode the doTaxonNode to set
71
     */
72
    public void setDoTaxonNode(boolean doTaxonNode) {
73
        this.doTaxonNode = doTaxonNode;
74
    }
75
    /**
76
     * @return the doPolytomousKeyNode
77
     */
78
    public boolean isDoPolytomousKeyNode() {
79
        return doPolytomousKeyNode;
80
    }
81
    /**
82
     * @param doPolytomousKeyNode the doPolytomousKeyNode to set
83
     */
84
    public void setDoPolytomousKeyNode(boolean doPolytomousKeyNode) {
85
        this.doPolytomousKeyNode = doPolytomousKeyNode;
86
    }
87
    /**
88
     * @return the doFeatureNode
89
     */
90
    public boolean isDoFeatureNode() {
91
        return doFeatureNode;
92
    }
93
    /**
94
     * @param doFeatureNode the doFeatureNode to set
95
     */
96
    public void setDoFeatureNode(boolean doFeatureNode) {
97
        this.doFeatureNode = doFeatureNode;
98
    }
99

  
100
    @Override
101
    public <STATE extends ImportStateBase> STATE getNewState() {
102
        return (STATE) new DefaultImportState(this);
103
    }
104

  
105

  
106
    @Override
107
    protected void makeIoClassList() {
108
        ioClassList = new Class[]{
109
                SortIndexUpdaterWrapper.class
110
        };
111
    }
112

  
113

  
114
    @Override
115
    public Reference getSourceReference() {
116
        return null;
117
    }
118

  
119

  
120
    @Override
121
    public boolean isValid() {
122
        //as no source needs to exist
123
        return true;
124
    }
125

  
126

  
127
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/service/IIOService.java
17 17
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
18 18
import eu.etaxonomy.cdm.io.common.ImportResult;
19 19
import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
20
import eu.etaxonomy.cdm.io.operation.config.CacheUpdaterConfigurator;
21
import eu.etaxonomy.cdm.io.operation.config.SortIndexUpdaterConfigurator;
22 20
import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
23 21
import eu.etaxonomy.cdm.io.specimen.SpecimenImportConfiguratorBase;
24 22
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
......
77 75
     */
78 76
    ImportResult importDataFromStream(List<Abcd206ImportConfigurator> configurators);
79 77

  
80
    /**
81
     * @param configurators
82
     * @return
83
     */
84
    ImportResult updateSortIndex(SortIndexUpdaterConfigurator config);
78
//    /**
79
//     * @param configurators
80
//     * @return
81
//     */
82
//    ImportResult updateSortIndex(SortIndexUpdaterConfigurator config);
85 83

  
86 84

  
87
    /**
88
     * @param config
89
     * @return
90
     */
91
    ImportResult updateCaches(CacheUpdaterConfigurator config);
85
//    /**
86
//     * @param config
87
//     * @return
88
//     */
89
//    ImportResult updateCaches(CacheUpdaterConfigurator config);
92 90

  
93 91

  
94 92
//    /**
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/service/IOServiceImpl.java
36 36
import eu.etaxonomy.cdm.io.common.ImportResult;
37 37
import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
38 38
import eu.etaxonomy.cdm.io.excel.common.ExcelImportConfiguratorBase;
39
import eu.etaxonomy.cdm.io.operation.config.CacheUpdaterConfigurator;
40
import eu.etaxonomy.cdm.io.operation.config.SortIndexUpdaterConfigurator;
41 39
import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
42 40
import eu.etaxonomy.cdm.io.specimen.SpecimenImportConfiguratorBase;
43 41
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
......
224 222
    }
225 223

  
226 224

  
227
    /**
228
     * {@inheritDoc}
229
     */
230
    @Override
231
    public ImportResult updateSortIndex(SortIndexUpdaterConfigurator config) {
232
        ImportResult result = new ImportResult();
233

  
234
        result = cdmImport.invoke(config);
235
        return result;
236
    }
237

  
238
    /**
239
     * {@inheritDoc}
240
     */
241
    @Override
242
    public ImportResult updateCaches(CacheUpdaterConfigurator config) {
243
        ImportResult result = new ImportResult();
225
//    /**
226
//     * {@inheritDoc}
227
//     */
228
//    @Override
229
//    public ImportResult updateSortIndex(SortIndexUpdaterConfigurator config) {
230
//        ImportResult result = new ImportResult();
231
//
232
//        result = cdmImport.invoke(config);
233
//        return result;
234
//    }
244 235

  
245
        result = cdmImport.invoke(config);
246
        return result;
247
    }
236
//    /**
237
//     * {@inheritDoc}
238
//     */
239
//    @Override
240
//    public ImportResult updateCaches(CacheUpdaterConfigurator config) {
241
//        ImportResult result = new ImportResult();
242
//
243
//        result = cdmImport.invoke(config);
244
//        return result;
245
//    }
248 246

  
249 247

  
250 248
    /**
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/longrunningService/ILongRunningTasksService.java
12 12
import java.util.UUID;
13 13

  
14 14
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
15
import eu.etaxonomy.cdm.api.service.config.CacheUpdaterConfigurator;
15 16
import eu.etaxonomy.cdm.api.service.config.ForSubtreeConfiguratorBase;
17
import eu.etaxonomy.cdm.api.service.config.SortIndexUpdaterConfigurator;
16 18
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
17 19
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
18 20

  
......
30 32
     */
31 33
    public UUID monitLongRunningTask(ForSubtreeConfiguratorBase configurator);
32 34

  
35
    /**
36
     * @param configurator
37
     * @return
38
     */
39
    public UUID monitLongRunningTask(CacheUpdaterConfigurator configurator);
33 40

  
34 41

  
35 42
    /**
......
50 57
     * @return the uuid of the monitor
51 58
     */
52 59
    public UUID monitGetRowWrapper(DescriptiveDataSet descriptiveDataSet);
60

  
61
    /**
62
     * @param configurator
63
     * @return
64
     */
65
    UUID monitLongRunningTask(SortIndexUpdaterConfigurator configurator);
53 66
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/longrunningService/LongRunningTasksServiceImpl.java
20 20
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
21 21
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
22 22
import eu.etaxonomy.cdm.api.service.UpdateResult;
23
import eu.etaxonomy.cdm.api.service.config.CacheUpdaterConfigurator;
23 24
import eu.etaxonomy.cdm.api.service.config.ForSubtreeConfiguratorBase;
24 25
import eu.etaxonomy.cdm.api.service.config.PublishForSubtreeConfigurator;
25 26
import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
27
import eu.etaxonomy.cdm.api.service.config.SortIndexUpdaterConfigurator;
28
import eu.etaxonomy.cdm.api.service.util.CacheUpdater;
29
import eu.etaxonomy.cdm.api.service.util.SortIndexUpdaterWrapper;
26 30
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
27 31
import eu.etaxonomy.cdm.common.monitor.RemotingProgressMonitorThread;
28 32
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
......
44 48
    @Autowired
45 49
    IProgressMonitorService progressMonitorService;
46 50

  
51
    @Autowired
52
    CacheUpdater updater;
47 53

  
54
    @Autowired
55
    SortIndexUpdaterWrapper sortIndexUpdater;
48 56

  
49 57
    @Override
50 58
    public UUID monitGetRowWrapper(DescriptiveDataSet descriptiveDataSet) {
......
133 141
        return uuid;
134 142
    }
135 143

  
144
    /**
145
     * {@inheritDoc}
146
     */
147
    @Override
148
    public UUID monitLongRunningTask(CacheUpdaterConfigurator configurator) {
149
        RemotingProgressMonitorThread monitorThread = new RemotingProgressMonitorThread() {
150
            @Override
151
            public Serializable doRun(IRemotingProgressMonitor monitor) {
152
                UpdateResult result;
153
                configurator.setMonitor(monitor);
154

  
155
                result = updater.doInvoke(configurator);
156

  
157
                for(Exception e : result.getExceptions()) {
158
                    monitor.addReport(e.getMessage());
159
                }
160
                monitor.setResult(result);
161
                return result;
162
            }
163
        };
164
        UUID uuid = progressMonitorService.registerNewRemotingMonitor(monitorThread);
165
        monitorThread.setPriority(2);
166
        monitorThread.start();
167
        return uuid;
168
    }
169

  
170
    /**
171
     * {@inheritDoc}
172
     */
173
    @Override
174
    public UUID monitLongRunningTask(SortIndexUpdaterConfigurator configurator) {
175
        RemotingProgressMonitorThread monitorThread = new RemotingProgressMonitorThread() {
176
            @Override
177
            public Serializable doRun(IRemotingProgressMonitor monitor) {
178
                UpdateResult result;
179
                configurator.setMonitor(monitor);
180

  
181
                result = sortIndexUpdater.doInvoke(configurator);
182

  
183
                for(Exception e : result.getExceptions()) {
184
                    monitor.addReport(e.getMessage());
185
                }
186
                monitor.setResult(result);
187
                return result;
188
            }
189
        };
190
        UUID uuid = progressMonitorService.registerNewRemotingMonitor(monitorThread);
191
        monitorThread.setPriority(2);
192
        monitorThread.start();
193
        return uuid;
194
    }
195

  
136 196

  
137 197
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/AgentServiceImpl.java
72 72

  
73 73
	@Override
74 74
	@Transactional(readOnly = false)
75
    public void updateCaches(Class<? extends AgentBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<AgentBase> cacheStrategy, IProgressMonitor monitor) {
75
    public UpdateResult updateCaches(Class<? extends AgentBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<AgentBase> cacheStrategy, IProgressMonitor monitor) {
76 76
		if (clazz == null){
77 77
			clazz = AgentBase.class;
78 78
		}
79
		super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
79
		return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
80 80
	}
81 81

  
82 82
	@Override
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java
527 527

  
528 528
    @Override
529 529
    @Transactional(readOnly = false)
530
    public void updateCaches(Class<? extends Classification> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Classification> cacheStrategy, IProgressMonitor monitor) {
530
    public UpdateResult updateCaches(Class<? extends Classification> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Classification> cacheStrategy, IProgressMonitor monitor) {
531 531
        if (clazz == null){
532 532
            clazz = Classification.class;
533 533
        }
534
        super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
534
        return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
535 535
    }
536 536

  
537 537
    /**
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/CollectionServiceImpl.java
39 39

  
40 40
	@Override
41 41
	@Transactional(readOnly = false)
42
    public void updateCaches(Class<? extends Collection> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Collection> cacheStrategy, IProgressMonitor monitor) {
42
    public UpdateResult updateCaches(Class<? extends Collection> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Collection> cacheStrategy, IProgressMonitor monitor) {
43 43
		if (clazz == null){
44 44
			clazz = Collection.class;
45 45
		}
46
		super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
46
		return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
47 47
	}
48 48

  
49 49

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptionServiceImpl.java
176 176

  
177 177
    @Override
178 178
    @Transactional(readOnly = false)
179
    public void updateCaches(Class<? extends DescriptionBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<DescriptionBase> cacheStrategy, IProgressMonitor monitor) {
179
    public UpdateResult updateCaches(Class<? extends DescriptionBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<DescriptionBase> cacheStrategy, IProgressMonitor monitor) {
180 180
        if (clazz == null){
181 181
            clazz = DescriptionBase.class;
182 182
        }
183
        super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
183
        return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
184 184
    }
185 185

  
186 186

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
244 244

  
245 245
    @Override
246 246
    @Transactional(readOnly = false)
247
    public void updateCaches(Class<? extends DescriptiveDataSet> clazz, Integer stepSize,
247
    public UpdateResult updateCaches(Class<? extends DescriptiveDataSet> clazz, Integer stepSize,
248 248
            IIdentifiableEntityCacheStrategy<DescriptiveDataSet> cacheStrategy, IProgressMonitor monitor) {
249 249
        if (clazz == null) {
250 250
            clazz = DescriptiveDataSet.class;
251 251
        }
252
        super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
252
        return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
253 253
    }
254 254

  
255 255
    private TaxonDescription findTaxonDescriptionByMarkerType(DescriptiveDataSet dataSet, Taxon taxon, MarkerType markerType){
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/FeatureTreeServiceImpl.java
55 55

  
56 56
    @Override
57 57
    @Transactional(readOnly = false)
58
    public void updateCaches(Class<? extends FeatureTree> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<FeatureTree> cacheStrategy, IProgressMonitor monitor) {
58
    public UpdateResult updateCaches(Class<? extends FeatureTree> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<FeatureTree> cacheStrategy, IProgressMonitor monitor) {
59 59
        if (clazz == null){
60 60
            clazz = FeatureTree.class;
61 61
        }
62
        super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
62
        return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
63 63
    }
64 64

  
65 65
    @Override
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IIdentifiableEntityService.java
45 45
     * Uses default values.
46 46
     * @see #updateCaches(Class, Integer, IIdentifiableEntityCacheStrategy, IProgressMonitor)
47 47
     */
48
    public void updateCaches();
48
    public UpdateResult updateCaches();
49 49

  
50 50
    /**
51 51
     * (Re-)generate the caches for all objects of this concrete IdentifiableEntity class
......
55 55
     * @param cacheStrategy cache strategy used for cache generation. If <code>null</code> use default.
56 56
     * @param monitor progress monitor. If <code>null</code> use default.
57 57
     */
58
    public void updateCaches(Class<? extends T> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<T> cacheStrategy, IProgressMonitor monitor);
58
    public UpdateResult updateCaches(Class<? extends T> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<T> cacheStrategy, IProgressMonitor monitor);
59 59

  
60 60
    /**
61 61
     * Finds an object with a given LSID. If the object does not currently exist in the current view, then
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
	/**
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/MediaServiceImpl.java
89 89

  
90 90
	@Override
91 91
	@Transactional(readOnly = false)
92
    public void updateCaches(Class<? extends Media> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Media> cacheStrategy, IProgressMonitor monitor) {
92
    public UpdateResult updateCaches(Class<? extends Media> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Media> cacheStrategy, IProgressMonitor monitor) {
93 93
		if (clazz == null){
94 94
			clazz = Media.class;
95 95
		}
96
		super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
96
		return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
97 97
	}
98 98

  
99 99
    @Override
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java
173 173

  
174 174
    @Override
175 175
    @Transactional(readOnly = false)
176
    public void updateCaches(Class<? extends SpecimenOrObservationBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<SpecimenOrObservationBase> cacheStrategy, IProgressMonitor monitor) {
176
    public UpdateResult updateCaches(Class<? extends SpecimenOrObservationBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<SpecimenOrObservationBase> cacheStrategy, IProgressMonitor monitor) {
177 177
        if (clazz == null) {
178 178
            clazz = SpecimenOrObservationBase.class;
179 179
        }
180
        super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
180
        return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
181 181
    }
182 182

  
183 183
    /**
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyServiceImpl.java
56 56
	}
57 57

  
58 58
	@Override
59
	public void updateCaches(Class<? extends PolytomousKey> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<PolytomousKey> cacheStrategy, IProgressMonitor monitor) {
59
	public UpdateResult updateCaches(Class<? extends PolytomousKey> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<PolytomousKey> cacheStrategy, IProgressMonitor monitor) {
60 60
		if (clazz == null){
61 61
			clazz = PolytomousKey.class;
62 62
		}
63
		super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
63
		return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
64 64
	}
65 65

  
66 66
	@Override
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ReferenceServiceImpl.java
46 46

  
47 47
    @Override
48 48
    @Transactional(readOnly = false)
49
    public void updateCaches(Class<? extends Reference> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Reference> cacheStrategy, IProgressMonitor monitor) {
49
    public UpdateResult updateCaches(Class<? extends Reference> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Reference> cacheStrategy, IProgressMonitor monitor) {
50 50
        if (clazz == null){
51 51
            clazz = Reference.class;
52 52
        }
53
        super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
53
        return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
54 54
    }
55 55

  
56 56
    @Override
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
396 396

  
397 397
    @Override
398 398
    @Transactional(readOnly = false)
399
    public void updateCaches(Class<? extends TaxonBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TaxonBase> cacheStrategy, IProgressMonitor monitor) {
399
    public UpdateResult updateCaches(Class<? extends TaxonBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TaxonBase> cacheStrategy, IProgressMonitor monitor) {
400 400
        if (clazz == null){
401 401
            clazz = TaxonBase.class;
402 402
        }
403
        super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
403
        return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
404 404
    }
405 405

  
406 406
    @Override
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/UpdateResult.java
184 184
        this.setMaxStatus(includedResult.getStatus());
185 185
        this.addExceptions(includedResult.getExceptions());
186 186
        this.addUpdatedObjects(includedResult.getUpdatedObjects());
187
        this.addUpdatedCdmIds(includedResult.getUpdatedCdmIds());
187 188
        //also add cdm entity of included result to updated objects
188 189
        if(includedResult.getCdmEntity()!=null){
189 190
            this.getUpdatedObjects().add(includedResult.getCdmEntity());
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/VocabularyServiceImpl.java
48 48

  
49 49
	@Override
50 50
	@Transactional(readOnly = false)
51
    public void updateCaches(Class<? extends TermVocabulary> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TermVocabulary> cacheStrategy, IProgressMonitor monitor) {
51
    public UpdateResult updateCaches(Class<? extends TermVocabulary> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TermVocabulary> cacheStrategy, IProgressMonitor monitor) {
52 52
		if (clazz == null){
53 53
			clazz = TermVocabulary.class;
54 54
		}
55
		super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
55
		return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
56 56
	}
57 57

  
58 58

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/config/CacheUpdaterConfigurator.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.api.service.config;
10

  
11
import java.io.Serializable;
12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.List;
15

  
16
import org.apache.log4j.Logger;
17

  
18
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
19
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
20

  
21
/**
22
 * @author a.mueller
23
 * @since 02-Jul-2010 13:06:43
24
 *
25
 */
26
public class CacheUpdaterConfigurator implements Serializable{
27
	@SuppressWarnings("unused")
28
	private static final Logger logger = Logger.getLogger(CacheUpdaterConfigurator.class);
29

  
30

  
31
	private boolean updateCacheStrategies = false;
32

  
33
	private IProgressMonitor monitor;
34

  
35

  
36

  
37
    public static CacheUpdaterConfigurator NewInstance(){
38
		return new CacheUpdaterConfigurator(false);
39
	}
40

  
41
	/**
42
	 * Returns a new Configurator with all boolean values set to false
43
	 * @param allFalse
44
	 * @return
45
	 */
46
	public static CacheUpdaterConfigurator NewInstance(boolean allTrue){
47
		return new CacheUpdaterConfigurator(allTrue);
48
	}
49

  
50
	public static CacheUpdaterConfigurator NewInstance(List<Class<? extends IdentifiableEntity>> classList){
51
		CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(true);
52
		result.setClassList(classList);
53
		return result;
54
	}
55

  
56
	public static CacheUpdaterConfigurator NewInstance(Collection<String> classListNames) throws ClassNotFoundException{
57
		CacheUpdaterConfigurator result = new CacheUpdaterConfigurator(true);
58
		List<Class<? extends IdentifiableEntity>> classList = new ArrayList<Class<? extends IdentifiableEntity>>();
59
		for (String className : classListNames){
60
			Class clazz = Class.forName(className);
61
			classList.add(clazz);
62
		}
63
		result.setClassList(classList);
64
		return result;
65
	}
66

  
67
	public static CacheUpdaterConfigurator NewInstance(Collection<String> classListNames, boolean doUpdateCacheStrategies) throws ClassNotFoundException{
68
		CacheUpdaterConfigurator result = new CacheUpdaterConfigurator( false);
69
		List<Class<? extends IdentifiableEntity>> classList = new ArrayList<Class<? extends IdentifiableEntity>>();
70
		for (String className : classListNames){
71
			Class clazz = Class.forName(className);
72
			classList.add(clazz);
73
		}
74
		result.setClassList(classList);
75
		result.setUpdateCacheStrategy(doUpdateCacheStrategies);
76
		return result;
77
	}
78

  
79
	/**
80
     * @return the monitor
81
     */
82
    public IProgressMonitor getMonitor() {
83
        return monitor;
84
    }
85

  
86
    /**
87
     * @param monitor the monitor to set
88
     */
89
    public void setMonitor(IProgressMonitor monitor) {
90
        this.monitor = monitor;
91
    }
92

  
93

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)