Project

General

Profile

« Previous | Next » 

Revision bcbe5633

Added by Andreas Müller almost 3 years ago

ref #9683 add loadProxy method to services and adapt test to work with current auto initialize settings

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/ICdmEntityDao.java
26 26
import eu.etaxonomy.cdm.persistence.query.Grouping;
27 27
import eu.etaxonomy.cdm.persistence.query.MatchMode;
28 28
import eu.etaxonomy.cdm.persistence.query.OrderHint;
29
import javassist.tools.rmi.ObjectNotFoundException;
29 30

  
30 31
/**
31 32
 * An data access interface that all data access classes implement
......
307 308
     */
308 309
    public T load(int id, List<String> propertyPaths);
309 310

  
311
    /**
312
     * Returns a proxy object for the given id.
313
     * This methods wraps {@link Session#load(Class, java.io.Serializable)}.
314
     * It does not check, if the object really exists but throws an {@link ObjectNotFoundException}
315
     * exception when no record with given id exists in the database.
316
     * @return
317
     *         the proxy object
318
     */
319
    public T loadProxy(int id);
320

  
310 321
    /**
311 322
     * @param ids
312 323
     * @param propertyPaths
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBase.java
775 775
        return bean;
776 776
    }
777 777

  
778
    @Override
779
    public T loadProxy(int id){
780
        return this.getSession().load(type, id);
781
    }
782

  
778 783
    @Override
779 784
    public T load(UUID uuid, List<String> propertyPaths) {
780 785
        return this.load(uuid, INCLUDE_UNPUBLISHED, propertyPaths);
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IService.java
30 30
import eu.etaxonomy.cdm.persistence.query.Grouping;
31 31
import eu.etaxonomy.cdm.persistence.query.MatchMode;
32 32
import eu.etaxonomy.cdm.persistence.query.OrderHint;
33
import javassist.tools.rmi.ObjectNotFoundException;
33 34

  
34 35
/**
35 36
 * @author a.kohlbecker
......
224 225
     */
225 226
    public T load(int id, List<String> propertyPaths);
226 227

  
228
    /**
229
     * Returns a proxy object for the given id.
230
     * This methods wraps {@link Session#load(Class, java.io.Serializable)}.
231
     * It does not check, if the object really exists but throws an {@link ObjectNotFoundException}
232
     * exception when no record with given id exists in the database.
233
     * @return
234
     *         the proxy object
235
     */
236
    public T loadProxy(int id);
237

  
227 238
    /**
228 239
     * Finds the cdm entity specified by the <code>uuid</code> parameter and
229 240
     * recursively initializes all bean properties given in the
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ServiceBase.java
202 202
        return dao.load(id, propertyPaths);
203 203
    }
204 204

  
205
    @Override
206
    @Transactional(readOnly = true)
207
    public T loadProxy(int id){
208
        return dao.loadProxy(id);
209
    }
210

  
205 211
    @Override
206 212
    @Transactional(readOnly = true)
207 213
    public T load(UUID uuid, List<String> propertyPaths){
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/NameServiceImplTest.java
77 77
    private static final Logger logger = Logger.getLogger(NameServiceImplTest.class);
78 78

  
79 79
    private static final UUID NAME1_UUID = UUID.fromString("6dbd41d1-fe13-4d9c-bb58-31f051c2c384");
80
    private static final int NAME1_ID = 10;
80 81
    private static final UUID NAME2_UUID = UUID.fromString("f9e9c13f-5fa5-48d3-88cf-712c921a099e");
82
    private static final int NAME2_ID = 11;
81 83
    private static final UUID NAME3_UUID = UUID.fromString("e1e66264-f16a-4df9-80fd-6ab5028a3c28");
84
    private static final int NAME3_ID = 12;
82 85

  
83 86
    @SpringBeanByType
84 87
    private INameService nameService;
......
1021 1024
        Field fullTitleCacheField = TaxonName.class.getDeclaredField("fullTitleCache");
1022 1025
        fullTitleCacheField.setAccessible(true);
1023 1026

  
1024
        TaxonName name1 = nameService.load(NAME1_UUID);
1025
        TaxonName name2 = nameService.load(NAME2_UUID);
1026
        TaxonName name3 = nameService.load(NAME3_UUID);
1027
        TaxonName name1 = nameService.loadProxy(NAME1_ID);
1028
        TaxonName name2 = nameService.loadProxy(NAME2_ID);
1029
        TaxonName name3 = nameService.loadProxy(NAME3_ID);
1027 1030

  
1031
        name1 = CdmBase.deproxy(name1);
1028 1032
        assertEquals("TitleCache should be the persisted one", "Name1", titleCacheField.get(name1));
1029 1033
        assertEquals("NameCache should be the persisted one", "", nameCacheField.get(name1));
1030 1034
        assertEquals("AuthorCache should be the persisted one", "", authorCacheField.get(name1));
1031 1035
        assertEquals("FullTitleCache should be the persisted one", "", fullTitleCacheField.get(name1));
1032 1036

  
1037
        name2 = CdmBase.deproxy(name2);
1033 1038
        assertEquals("TitleCache should be the persisted one", "Name2", titleCacheField.get(name2));
1034 1039
        assertEquals("NameCache should be the persisted one", "Protected name", nameCacheField.get(name2));
1035 1040
        assertEquals("AuthorCache should be the persisted one", null, authorCacheField.get(name2));
1036 1041
        assertEquals("FullTitleCache should be the persisted one", "", fullTitleCacheField.get(name2));
1037 1042

  
1043
        name3 = CdmBase.deproxy(name3);
1038 1044
        assertEquals("TitleCache should be the persisted one", "Name3", titleCacheField.get(name3));
1039 1045
        assertEquals("NameCache should be the persisted one", "", nameCacheField.get(name3));
1040 1046
        assertEquals("AuthorCache should be the persisted one", "No-author", authorCacheField.get(name3));

Also available in: Unified diff