Project

General

Profile

Revision 4bcc10d3

ID4bcc10d398ee51c18b51eb6a676a52da4123f158
Parent 9b7db8db
Child d3752fac

Added by Andreas Kohlbecker almost 3 years ago

TransmissionEngineDistribution avoiding weired exceptions in tests

View differences:

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
            }
......
954 955
    }
955 956

  
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

  
971
    /**
957 972
     * @param taxon
958 973
     * @param logger2
959 974
     * @return

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)