Revision 09c85ccb
Added by Andreas Kohlbecker about 5 years ago
src/main/java/eu/etaxonomy/cdm/service/CdmBeanItemContainerFactory.java | ||
---|---|---|
13 | 13 |
import java.util.List; |
14 | 14 |
import java.util.UUID; |
15 | 15 |
|
16 |
import org.hibernate.Session; |
|
16 | 17 |
import org.springframework.beans.factory.annotation.Autowired; |
17 | 18 |
import org.springframework.beans.factory.annotation.Qualifier; |
18 | 19 |
import org.springframework.stereotype.Service; |
... | ... | |
38 | 39 |
* |
39 | 40 |
*/ |
40 | 41 |
@Service |
41 |
@Transactional(readOnly=true) |
|
42 | 42 |
public class CdmBeanItemContainerFactory { |
43 | 43 |
|
44 | 44 |
@Autowired |
... | ... | |
59 | 59 |
*/ |
60 | 60 |
@Transactional(readOnly=true) |
61 | 61 |
public BeanItemContainer<DefinedTermBase> buildBeanItemContainer(TermType termType) { |
62 |
|
|
63 |
clearSession(); |
|
62 | 64 |
// TODO use TermCacher? |
63 | 65 |
List<DefinedTermBase> terms = repo.getTermService().listByTermType(termType, null, null, orderHints, INIT_STRATEGY); |
64 | 66 |
BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class); |
... | ... | |
72 | 74 |
@Transactional(readOnly=true) |
73 | 75 |
public BeanItemContainer<DefinedTermBase> buildBeanItemContainer(UUID vocabularyUuid) { |
74 | 76 |
|
77 |
clearSession(); |
|
75 | 78 |
TermVocabulary vocab = repo.getVocabularyService().find(vocabularyUuid); |
76 | 79 |
Pager<DefinedTermBase> terms = repo.getVocabularyService().getTerms(vocab, null, null, orderHints, INIT_STRATEGY); |
77 | 80 |
BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class); |
... | ... | |
82 | 85 |
/** |
83 | 86 |
* @param termType |
84 | 87 |
*/ |
85 |
@Transactional(readOnly=true) |
|
86 | 88 |
public BeanItemContainer<DefinedTermBase> buildTermItemContainer(UUID ... termUuid) { |
87 | 89 |
return buildTermItemContainer(Arrays.asList(termUuid)); |
88 | 90 |
} |
... | ... | |
93 | 95 |
*/ |
94 | 96 |
@Transactional(readOnly=true) |
95 | 97 |
public BeanItemContainer<DefinedTermBase> buildTermItemContainer(List<UUID> termsUuids) { |
98 |
clearSession(); |
|
96 | 99 |
List<DefinedTermBase> terms = repo.getTermService().load(termsUuids, INIT_STRATEGY); |
97 | 100 |
BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class); |
98 | 101 |
termItemContainer.addAll(terms); |
... | ... | |
108 | 111 |
if(orderHints == null){ |
109 | 112 |
orderHints = OrderHint.defaultOrderHintsFor(type); |
110 | 113 |
} |
111 |
|
|
114 |
clearSession(); |
|
112 | 115 |
List<T> terms = repo.getCommonService().list(type, (Integer)null, (Integer)null, |
113 | 116 |
orderHints, |
114 | 117 |
Arrays.asList(new String[]{"$"})); |
... | ... | |
125 | 128 |
* @param values |
126 | 129 |
* @return |
127 | 130 |
*/ |
128 |
@Transactional(readOnly=true) |
|
129 | 131 |
public <T extends IEnumTerm<T>> BeanItemContainer<T> buildBeanItemContainer(Class<T> termType, T ... enumTerms) { |
130 | 132 |
BeanItemContainer<T> termItemContainer = new BeanItemContainer<>(termType); |
131 | 133 |
List<T> termList = Arrays.asList(enumTerms); |
... | ... | |
133 | 135 |
return termItemContainer; |
134 | 136 |
} |
135 | 137 |
|
138 |
public void clearSession() { |
|
139 |
Session session = repo.getSession(); |
|
140 |
if(session.isOpen()){ |
|
141 |
session.clear(); |
|
142 |
} |
|
143 |
} |
|
136 | 144 |
|
137 | 145 |
} |
Also available in: Unified diff
ref #8160 CdmBeanItemContainerFactory @Transactional only where needed and clearing session before each service call