Revision 4bcc10d3
Added by Andreas Kohlbecker over 6 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/description/TransmissionEngineDistribution.java | ||
---|---|---|
43 | 43 |
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor; |
44 | 44 |
import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor; |
45 | 45 |
import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor; |
46 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
46 | 47 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
47 | 48 |
import eu.etaxonomy.cdm.model.common.Extension; |
48 | 49 |
import eu.etaxonomy.cdm.model.common.ExtensionType; |
... | ... | |
942 | 943 |
private List<Distribution> distributionsFor(Taxon taxon) { |
943 | 944 |
List<Distribution> distributions = new ArrayList<Distribution>(); |
944 | 945 |
for(TaxonDescription description: taxon.getDescriptions()) { |
945 |
getSession().setReadOnly(description, true);
|
|
946 |
readOnlyIfInSession(description);
|
|
946 | 947 |
for(DescriptionElementBase deb : description.getElements()) { |
947 | 948 |
if(deb instanceof Distribution) { |
948 |
getSession().setReadOnly(deb, true);
|
|
949 |
readOnlyIfInSession(deb);
|
|
949 | 950 |
distributions.add((Distribution)deb); |
950 | 951 |
} |
951 | 952 |
} |
... | ... | |
953 | 954 |
return distributions; |
954 | 955 |
} |
955 | 956 |
|
957 |
/** |
|
958 |
* This method avoids problems when running the TransmissionEngineDistribution test. |
|
959 |
* For some unknown reason entities are not in the PersitenceContext even if they are |
|
960 |
* loaded by a service method. Setting these entities to readonly would raise a |
|
961 |
* TransientObjectException("Instance was not associated with this persistence context") |
|
962 |
* |
|
963 |
* @param entity |
|
964 |
*/ |
|
965 |
private void readOnlyIfInSession(CdmBase entity) { |
|
966 |
if(getSession().contains(entity)) { |
|
967 |
getSession().setReadOnly(entity, true); |
|
968 |
} |
|
969 |
} |
|
970 |
|
|
956 | 971 |
/** |
957 | 972 |
* @param taxon |
958 | 973 |
* @param logger2 |
Also available in: Unified diff
TransmissionEngineDistribution avoiding weired exceptions in tests