Project

General

Profile

Revision 9d0d72ef

ID9d0d72efc1bb886e62820891ce080d84428052b1
Parent ed60b90e
Child 69957587

Added by Patrick Plitzner about 3 years ago

ref #6554 Cache preferred terms in TermManager

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/TermManager.java
11 11

  
12 12
import java.util.ArrayList;
13 13
import java.util.Collection;
14
import java.util.HashMap;
14 15
import java.util.List;
16
import java.util.Map;
15 17
import java.util.UUID;
16 18

  
17 19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
......
35 37
	private static final String CLASS = "class";
36 38
	private static final String UUID_STRING = "uuid";
37 39

  
40

  
41
    private Map<Object, List> cachedTermMap = new HashMap<>();
42

  
38 43
	public TermManager(){
39 44
	}
40 45

  
......
44 49
	 * @return
45 50
	 */
46 51
	public <T extends DefinedTermBase> List<T> getPreferredTerms(TermType termType){
47
	    return getFilteredTerms(TermStore.<T>getTerms(termType, null));
52
	    List terms = cachedTermMap.get(termType);
53
	    if(terms==null){
54
	        terms = getFilteredTerms(TermStore.<T>getTerms(termType, null));
55
	        cachedTermMap.put(termType, terms);
56
	    }
57
        return terms;
48 58
	}
49 59

  
50 60
	/**
......
53 63
	 * @return
54 64
	 */
55 65
	public <T extends DefinedTermBase> List<T> getPreferredTerms(TermVocabulary<T> termVocabulary){
56
	    return getFilteredTerms(new ArrayList<T>(TermStore.getTerms(termVocabulary, null)));
66
	    List terms = cachedTermMap.get(termVocabulary);
67
	    if(terms==null){
68
	        terms = getFilteredTerms(new ArrayList<T>(TermStore.getTerms(termVocabulary, null)));
69
	        cachedTermMap.put(termVocabulary, terms);
70
	    }
71
	    return terms;
57 72
	}
58 73

  
59 74
	/**
......
62 77
	 * @return
63 78
	 */
64 79
	public <T extends DefinedTermBase> List<T> getPreferredTerms(Class<T> clazz){
65
		return getFilteredTerms(TermStore.getTerms(clazz));
80
	    List terms = cachedTermMap.get(clazz);
81
	    if(terms==null){
82
	        terms = getFilteredTerms(TermStore.getTerms(clazz));
83
	        cachedTermMap.put(clazz, terms);
84
	    }
85
	    return terms;
66 86
	}
67 87

  
68 88
	/**

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)