Project

General

Profile

« Previous | Next » 

Revision e09f9c40

Added by Cherian Mathew almost 8 years ago

#5031 Update remoting code to be compatible with new common service collection calls

View differences:

eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CachedCommonServiceImpl.java
9 9
*/
10 10
package eu.etaxonomy.taxeditor.service;
11 11

  
12
import org.hibernate.collection.spi.PersistentCollection;
12
import java.util.UUID;
13

  
13 14
import org.springframework.beans.factory.annotation.Autowired;
14 15
import org.springframework.stereotype.Component;
15 16

  
......
60 61
        }
61 62
    }
62 63

  
63
    /* (non-Javadoc)
64
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#initializeCollection(org.hibernate.collection.spi.PersistentCollection)
65
     */
66
    @Override
67
    public PersistentCollection initializeCollection(PersistentCollection col) {
68
           return commonService.initializeCollection(col);
69
    }
70 64

  
71 65
    @Override
72 66
    public void updatePersistentCollection(CollectionField colf) {
73
    	if(cacheEnabled) {
74
    		cdmEntitySessionManager.load(colf.getCollection(), false);
75
    	}
67
        if(cacheEnabled) {
68
            cdmEntitySessionManager.load(colf.getCollection(), false);
69
        }
76 70
    }
77 71

  
78 72
    /* (non-Javadoc)
79
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#isEmpty(org.hibernate.collection.spi.PersistentCollection)
73
     * @see eu.etaxonomy.taxeditor.service.ICachedCommonService#initializeCollection(java.util.UUID, java.lang.String)
80 74
     */
81 75
    @Override
82
    public boolean isEmpty(PersistentCollection col) {
83
            return commonService.isEmpty(col);
84

  
76
    public Object initializeCollection(UUID ownerUuid, String fieldName) {
77
        return commonService.initializeCollection(ownerUuid, fieldName);
85 78
    }
86 79

  
87 80

  
88 81
    /* (non-Javadoc)
89
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#size(org.hibernate.collection.spi.PersistentCollection)
82
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#isEmpty(org.hibernate.collection.spi.PersistentCollection)
90 83
     */
91 84
    @Override
92
    public int size(PersistentCollection col) {
93
        return commonService.size(col);
85
    public boolean isEmpty(UUID ownerUuid, String fieldName) {
86
            return commonService.isEmpty(ownerUuid, fieldName);
87

  
94 88
    }
95 89

  
96 90

  
97 91
    /* (non-Javadoc)
98
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#get(org.hibernate.collection.spi.PersistentCollection, int)
92
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#size(org.hibernate.collection.spi.PersistentCollection)
99 93
     */
100 94
    @Override
101
    public Object get(PersistentCollection col, int index) {
102
        return commonService.get(col, index);
95
    public int size(UUID ownerUuid, String fieldName) {
96
        return commonService.size(ownerUuid, fieldName);
103 97
    }
104 98

  
105 99

  
100

  
106 101
    /* (non-Javadoc)
107 102
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#contains(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
108 103
     */
109 104
    @Override
110
    public boolean contains(PersistentCollection col, Object element) {
111
        return commonService.contains(col, element);
105
    public boolean contains(UUID ownerUuid, String fieldName, Object element) {
106
        return commonService.contains(ownerUuid, fieldName, element);
112 107
    }
113 108

  
114 109

  
......
116 111
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsKey(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
117 112
     */
118 113
    @Override
119
    public boolean containsKey(PersistentCollection col, Object key) {
120
        return commonService.containsKey(col, key);
114
    public boolean containsKey(UUID ownerUuid, String fieldName, Object key) {
115
        return commonService.containsKey(ownerUuid, fieldName, key);
121 116
    }
122 117

  
123 118

  
......
125 120
     * @see eu.etaxonomy.taxeditor.remoting.service.ICachedCommonService#containsValue(org.hibernate.collection.spi.PersistentCollection, java.lang.Object)
126 121
     */
127 122
    @Override
128
    public boolean containsValue(PersistentCollection col, Object element) {
129
        return commonService.containsValue(col, element);
123
    public boolean containsValue(UUID ownerUuid, String fieldName, Object element) {
124
        return commonService.containsValue(ownerUuid, fieldName, element);
130 125
    }
131 126

  
132 127

  
133 128

  
134 129

  
135 130

  
131

  
136 132
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/ICachedCommonService.java
9 9
 */
10 10
package eu.etaxonomy.taxeditor.service;
11 11

  
12
import org.hibernate.collection.spi.PersistentCollection;
12
import java.util.UUID;
13 13

  
14 14
import eu.etaxonomy.cdm.model.common.CdmBase;
15 15
import eu.etaxonomy.taxeditor.remoting.cache.ProxyUtils.CollectionField;
......
23 23

  
24 24
    public CdmBase find(Class<? extends CdmBase> clazz, int id);
25 25

  
26
    public PersistentCollection initializeCollection(PersistentCollection col);
27

  
28 26
	public void updatePersistentCollection(CollectionField colf);
29 27

  
30
    public boolean isEmpty(PersistentCollection col);
31

  
32
    public int size(PersistentCollection col);
33

  
34
    public Object get(PersistentCollection col, int index);
35

  
36
    public boolean contains(PersistentCollection col, Object element);
37

  
38
    public boolean containsKey(PersistentCollection col, Object key);
39

  
40
    public boolean containsValue(PersistentCollection col, Object element);
28
    /**
29
     * Initializes a collection or map.
30
     *
31
     * @param ownerUuid uuid of owner cdm entity
32
     * @param fieldName field name of collection or map
33
     * @return initialised collection or map
34
     */
35
    public Object initializeCollection(UUID ownerUuid, String fieldName);
36

  
37
    /**
38
     * Checks if a collection or map is empty.
39
     *
40
     * @param ownerUuid uuid of owner cdm entity
41
     * @param fieldName field name of collection or map
42
     * @return true if the collection of map is empty, else false
43
     */
44
    public boolean isEmpty(UUID ownerUuid, String fieldName);
45

  
46
    /**
47
     * Returns the size of requested collection or map.
48
     *
49
     * @param ownerUuid uuid of owner cdm entity
50
     * @param fieldName field name of collection or map
51
     * @return the size of the persistent collection
52
     */
53
    public int size(UUID ownerUuid, String fieldName);
54

  
55
    /**
56
     * Checks whether an object is contained within a persistent collection.
57
     *
58
     * @param ownerUuid uuid of owner cdm entity
59
     * @param fieldName field name of collection or map
60
     * @param element the element to check for
61
     * @return true if the element exists in the collection, false o/w
62
     */
63
    public boolean contains(UUID ownerUuid, String fieldName, Object element);
64

  
65
    /**
66
     * Checks whether an index object exists within a persistent collection
67
     * (usually a map)
68
     *
69
     * @param ownerUuid uuid of owner cdm entity
70
     * @param fieldName field name of map
71
     * @param key the index object to look for.
72
     * @return true if the index object exists in the collection, false o/w
73
     */
74
    public boolean containsKey(UUID ownerUuid, String fieldName, Object key);
75

  
76
    /**
77
     * checks whether an value object exists within a persistent collection
78
     * (usually a map)
79
     *
80
     * @param ownerUuid uuid of owner cdm entity
81
     * @param fieldName field name of map
82
     * @param key the value object to look for.
83
     * @return true if the value object exists in the collection, false o/w
84
     */
85
    public boolean containsValue(UUID ownerUuid, String fieldName, Object element);
41 86

  
42 87

  
43 88

  
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java
60 60
import org.jboss.logging.Logger;
61 61

  
62 62
import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
63
import eu.etaxonomy.cdm.model.common.CdmBase;
63 64
import eu.etaxonomy.taxeditor.remoting.CdmEagerLoadingException;
64 65
import eu.etaxonomy.taxeditor.remoting.cache.ProxyUtils;
65 66
import eu.etaxonomy.taxeditor.service.ICachedCommonService;
......
1297 1298
				String fieldName = role.substring(role.lastIndexOf(".") + 1);
1298 1299
				log.info("--> Remote Lazy Initializing Collection " + getRole() + " , key : " + getKey() + " , field : " + fieldName);
1299 1300
				Object owner = getOwner();
1300

  
1301
				CdmBase cdmBase;
1302
				if(owner instanceof CdmBase) {
1303
				    cdmBase = (CdmBase)owner;
1304
				} else {
1305
				    throw new HibernateException("Owner of persistent collection is not a cdm entity");
1306
				}
1301 1307
				if(configuration == null) {
1302 1308
					throw new HibernateException("CdmApplicationRemoteConfiguration not initialized (null)");
1303 1309
				}
......
1306 1312
					throw new HibernateException("commonService not initialized (null)");
1307 1313
				}
1308 1314

  
1309
				Object obj = ProxyUtils.deproxy(cachedCommonService.initializeCollection(this));
1315
				//Object obj = ProxyUtils.deproxy(cachedCommonService.initializeCollection(this));
1316
				Object obj = ProxyUtils.deproxy(cachedCommonService.initializeCollection(cdmBase.getUuid(), fieldName));
1310 1317
				afterInitialize();
1311 1318

  
1312 1319
				Class<?> clazz = getClass();
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/model/PolytomousKeyTest.java
255 255
        PolytomousKeyNode pkeynode = pkey.getRoot();
256 256

  
257 257
        PersistentCollection children = (PersistentCollection) pkeynode.getChildren();
258
        PolytomousKeyNode childNode0 = (PolytomousKeyNode)commonService.get(children, 0);
258
        PolytomousKeyNode childNode0 = (PolytomousKeyNode)commonService.get(pkeynode.getUuid(), "children", 0);
259 259
        PolytomousKey subkey1 = CdmBase.deproxy(childNode0.getSubkey(),PolytomousKey.class);
260 260
        String subkey1title = subkey1.getTitleCache();
261 261
        subkey1.setTitleCache(subkey1title + "test", true);
262 262

  
263
        PolytomousKeyNode childNode1 = (PolytomousKeyNode)commonService.get(children, 1);
263
        PolytomousKeyNode childNode1 = (PolytomousKeyNode)commonService.get(pkeynode.getUuid(), "children", 1);
264 264
        PolytomousKey subkey2 = CdmBase.deproxy(childNode1.getSubkey(),PolytomousKey.class);
265 265
        String subkey2title = subkey2.getTitleCache();
266 266
        subkey2.setTitleCache(subkey2title + "test", true);
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/RemotePersistentCollectionTest.java
14 14
import java.util.Set;
15 15

  
16 16
import org.apache.log4j.Logger;
17
import org.hibernate.collection.spi.PersistentCollection;
18 17
import org.junit.Assert;
19 18
import org.junit.BeforeClass;
20 19
import org.junit.Ignore;
......
80 79

  
81 80
			// this size call will initialise the list remotely and only return the
82 81
			// size of the list
83
			int remoteChildCount = commonService.size((PersistentCollection)childNodes);
82
			int remoteChildCount = commonService.size(taxonNode.getUuid(), "childNodes");
84 83
			Assert.assertEquals(childCount, remoteChildCount);
85 84

  
86 85
			String firstNodeTaxonTitle = taxonNode.getTaxon().getTitleCache();
......
94 93

  
95 94
				// this get call will initialise the list remotely and only return the
96 95
				// 0th element from the list
97
				TaxonNode remoteTaxonNode = (TaxonNode)commonService.get((PersistentCollection)childNodes,0);
96
				TaxonNode remoteTaxonNode = (TaxonNode)commonService.get(taxonNode.getUuid(), "childNodes",0);
98 97

  
99 98
				// the locally and remotely retrieved taxon node should exist in the
100 99
				// (local and remote) child nodes list, should be not-null and should be equal to each other
101 100
				Assert.assertTrue(taxonNode.getChildNodes().contains(localTaxonNode));
102 101
				Assert.assertTrue(taxonNode.getChildNodes().contains(remoteTaxonNode));
103
				Assert.assertTrue(commonService.contains((PersistentCollection)childNodes, localTaxonNode));
104
				Assert.assertTrue(commonService.contains((PersistentCollection)childNodes, remoteTaxonNode));
102
				Assert.assertTrue(commonService.contains(taxonNode.getUuid(), "childNodes", localTaxonNode));
103
				Assert.assertTrue(commonService.contains(taxonNode.getUuid(), "childNodes", remoteTaxonNode));
105 104
				Assert.assertNotNull(remoteTaxonNode);
106 105
				Assert.assertNotNull(localTaxonNode);
107 106
				Assert.assertEquals(remoteTaxonNode,localTaxonNode);
......
188 187
								if(!multilanguagetextMap.isEmpty()) {
189 188
									// found a map whcih we can test!
190 189
									logger.info("Found Non-empty multilanguagetextMap");
191
									boolean empty = commonService.isEmpty((PersistentCollection)multilanguagetextMap);
190
									boolean empty = commonService.isEmpty(element.getUuid(), "multilanguageText");
192 191
									Assert.assertFalse(empty);
193 192
									// test retrieval of key set, which should already by initialised
194 193
									Set<Language> langKeySet = multilanguagetextMap.keySet();
......
200 199
										Assert.assertTrue(localContainsKey);
201 200
										// testing 'containsKey' on remotely initialised collection
202 201
										boolean remoteContainsKey =
203
												commonService.containsKey((PersistentCollection)multilanguagetextMap, key);
202
												commonService.containsKey(element.getUuid(), "multilanguageText", key);
204 203
										Assert.assertTrue(remoteContainsKey);
205 204

  
206 205
										LanguageString value = multilanguagetextMap.get(key);
......
209 208
										Assert.assertTrue(localContainsValue);
210 209
										// testing 'containsValue' on remotely initialised collection
211 210
										boolean remoteContainsValue =
212
												commonService.containsValue((PersistentCollection)multilanguagetextMap, value);
211
												commonService.containsValue(element.getUuid(), "multilanguageText", value);
213 212
										Assert.assertTrue(remoteContainsValue);
214 213

  
215 214
									}

Also available in: Unified diff