Project

General

Profile

« Previous | Next » 

Revision 8422c0cd

Added by Andreas Müller almost 8 years ago

Remove generics from Reference in cdmlib-app #5830

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/util/TestTransaction.java
1 1
/**
2 2
* Copyright (C) 2008 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5 5
*/
6 6

  
......
28 28
 * @created 27.10.2008
29 29
 */
30 30
public class TestTransaction {
31
	
31

  
32 32
	private static final String dbName = "cdm_test_jaxb";
33 33
    private static final int MAX_ENTRIES = 20;
34
	
34

  
35 35
	private static final ICdmDataSource db = TestDatabase.CDM_DB(dbName);
36 36
    private static final Logger logger = Logger.getLogger(TestTransaction.class);
37 37

  
38
    
38

  
39 39
    /** Modifies disjunct objects within two transactions of one application context.
40 40
     *  Flow:
41 41
     *  Start transaction #1. Modify and save taxon #1.
......
43 43
     *  Commit transaction #1.
44 44
     *  Save taxon #2.
45 45
     *  Commit transaction #2.
46
     *  
46
     *
47 47
     *  It is possible to commit transaction #2 before committing transaction #1
48 48
     *  but it is not possible to modify data after transaction #2 has been committed
49
     *  (LazyInitializationException). However, it is possible to save data after 
49
     *  (LazyInitializationException). However, it is possible to save data after
50 50
     *  transaction #2 has been committed.
51
     */    
51
     */
52 52
	private void modifyDisjunctObjects() {
53
		
53

  
54 54
		CdmApplicationController appCtr = null;
55 55
		logger.info("Test modifying disjunct objects");
56 56

  
......
62 62
			e.printStackTrace();
63 63
			System.exit(1);
64 64
		}
65
		
65

  
66 66
		BotanicalName name1, name2;
67 67
		Rank rankSpecies = Rank.SPECIES();
68 68
		Taxon taxon1, taxon2, child1, child2;
69
		
69

  
70 70
		try {
71 71
			/* ************** Start Transaction #1 ******************************** */
72
			
72

  
73 73
	    	TransactionStatus txStatOne = appCtr.startTransaction();
74
	    	
74

  
75 75
	    	List<? extends AgentBase> agents = appCtr.getAgentService().list(null, MAX_ENTRIES, 0, null, null);
76 76
	    	//List<TeamOrPersonBase> agents = appCtr.getAgentService().getAllAgents(MAX_ENTRIES, 0);
77 77
	    	TeamOrPersonBase author = (TeamOrPersonBase) agents.get(0);
78 78
	    	List<Reference> references = appCtr.getReferenceService().list(null, MAX_ENTRIES, 0, null, null);
79 79
	    	Reference sec = references.get(0);
80
	    	List<Taxon> taxa = (List)appCtr.getTaxonService().list(Taxon.class, MAX_ENTRIES, 0, null, null);
80
	    	List<Taxon> taxa = appCtr.getTaxonService().list(Taxon.class, MAX_ENTRIES, 0, null, null);
81 81

  
82
			name1 = 
82
			name1 =
83 83
				BotanicalName.NewInstance(rankSpecies, "Hyoseris", null, "lucida", null, author, null, "1", null);
84 84
            // Calendula L.
85 85
			taxon1 = taxa.get(0);
86 86
			child1 = Taxon.NewInstance(name1, sec);
87 87
			taxon1.addTaxonomicChild(child1, sec, "D#t1-c1");
88 88
			appCtr.getTaxonService().saveOrUpdate(taxon1);
89
			
89

  
90 90

  
91 91
			/* ************** Start Transaction #2 ******************************** */
92
	    	
92

  
93 93
			TransactionStatus txStatTwo = appCtr.startTransaction();
94 94

  
95
			name2 = 
95
			name2 =
96 96
				BotanicalName.NewInstance(rankSpecies, "Hyoseris", null, "scabra", null, author, null, "2", null);
97 97
            // Sonchus L.
98 98
	    	taxon2 = taxa.get(1);
99 99
			child2 = Taxon.NewInstance(name2, sec);
100 100
			taxon2.addTaxonomicChild(child2, sec, "D#t2-c2");
101
			
101

  
102 102
			/* ************** Commit Transaction #1 ******************************** */
103
			
103

  
104 104
	    	appCtr.commitTransaction(txStatOne);
105
	    	
105

  
106 106
			UUID t2uuid = appCtr.getTaxonService().saveOrUpdate(taxon2);
107
	    	
107

  
108 108
			/* ************** Commit Transaction #2 ******************************** */
109
			
109

  
110 110
	    	appCtr.commitTransaction(txStatTwo);
111
	    	
111

  
112 112
	    	appCtr.close();
113
			logger.info("End test modifying disjunct objects"); 
114
				
113
			logger.info("End test modifying disjunct objects");
114

  
115 115
		} catch (Exception e) {
116 116
    		logger.error("Error");
117 117
    		e.printStackTrace();
118 118
		}
119 119
	}
120
	
120

  
121 121

  
122 122
    /** Modifies shared objects within two transactions of one application context.
123 123
     *  Flow:
......
126 126
     *  Commit transaction #1.
127 127
     *  Save taxon #1.
128 128
     *  Commit transaction #2.
129
     */    
129
     */
130 130
	private void modifySharedObjects() {
131
		
131

  
132 132
		CdmApplicationController appCtr = null;
133 133
		logger.info("Test modifying shared objects");
134 134

  
......
140 140
			e.printStackTrace();
141 141
			System.exit(1);
142 142
		}
143
		
143

  
144 144
		BotanicalName name1, name2;
145 145
		Rank rankSpecies = Rank.SPECIES();
146 146
		Taxon taxon1, taxon2, child1, child2;
147
		
147

  
148 148
		try {
149 149
			/* ************** Start Transaction #1 ******************************** */
150
			
150

  
151 151
	    	TransactionStatus txStatOne = appCtr.startTransaction();
152
	    	
152

  
153 153
	    	List<TeamOrPersonBase> agents = appCtr.getAgentService().list(TeamOrPersonBase.class, MAX_ENTRIES, 0, null, null);
154 154
	    	//List<TeamOrPersonBase> agents = appCtr.getAgentService().getAllAgents(MAX_ENTRIES, 0);
155 155
	    	TeamOrPersonBase<?> author = agents.get(0);
156 156
	    	List<Reference> references = appCtr.getReferenceService().list(null, MAX_ENTRIES, 0, null, null);
157
	    	Reference<?> sec = references.get(0);
157
	    	Reference sec = references.get(0);
158 158
	    	List<Taxon> taxa = appCtr.getTaxonService().list(Taxon.class, MAX_ENTRIES, 0, null, null);
159 159

  
160
			name1 = 
160
			name1 =
161 161
				BotanicalName.NewInstance(rankSpecies, "Launaea", null, "child1", null, author, null, "1", null);
162 162
			// Cichorium intybus L.
163 163
	    	taxon1 = taxa.get(5);
164 164
			child1 = Taxon.NewInstance(name1, sec);
165 165
			taxon1.addTaxonomicChild(child1, sec, "S#t1-c1");
166 166
			appCtr.getTaxonService().saveOrUpdate(taxon1);
167
			
167

  
168 168

  
169 169
			/* ************** Start Transaction #2 ******************************** */
170
	    	
170

  
171 171
			TransactionStatus txStatTwo = appCtr.startTransaction();
172 172

  
173
			name2 = 
173
			name2 =
174 174
				BotanicalName.NewInstance(rankSpecies, "Reichardia", null, "child2", null, author, null, "2", null);
175 175
			// Cichorium intybus L.
176 176
	    	taxon2 = taxa.get(5);
177 177
			child2 = Taxon.NewInstance(name2, sec);
178 178
			taxon2.addTaxonomicChild(child2, sec, "S#t1-c2");
179
			
179

  
180 180
			/* ************** Commit Transaction #1 ******************************** */
181
			
181

  
182 182
	    	appCtr.commitTransaction(txStatOne);
183
	    	
183

  
184 184
			UUID t2uuid = appCtr.getTaxonService().saveOrUpdate(taxon2);
185
	    	
185

  
186 186
			/* ************** Commit Transaction #2 ******************************** */
187
			
187

  
188 188
	    	appCtr.commitTransaction(txStatTwo);
189
	    	
189

  
190 190
	    	appCtr.close();
191
			logger.info("End test modifying shared objects"); 
192
				
191
			logger.info("End test modifying shared objects");
192

  
193 193
		} catch (Exception e) {
194 194
    		logger.error("Error");
195 195
    		e.printStackTrace();
196 196
		}
197 197
	}
198
	
198

  
199 199

  
200 200
	private void checkTransactionFacets() {
201
		
201

  
202 202
		CdmApplicationController appCtr = null;
203 203
		logger.info("Test checking transaction facets");
204
		
204

  
205 205
		try {
206 206
			appCtr = CdmApplicationController.NewInstance(db, DbSchemaValidation.VALIDATE, true);
207 207

  
......
213 213

  
214 214
		try {
215 215
			/* ************** Start Transaction #1 ******************************** */
216
			
216

  
217 217
	    	TransactionStatus txStatOne = appCtr.startTransaction();
218 218
	    	appCtr.commitTransaction(txStatOne);
219 219
	    	// set CdmApplicationController = debug in log4j.properties to see the transaction properties
220 220
	    	appCtr.close();
221
			logger.info("End test ask session for objects"); 
222
			
221
			logger.info("End test ask session for objects");
222

  
223 223
		} catch (Exception e) {
224 224
    		logger.error("Error");
225 225
    		e.printStackTrace();
226 226
		}
227 227
	}
228
		
228

  
229 229
	private void askSessionForObjects() {
230
		
230

  
231 231
		CdmApplicationController appCtr = null;
232 232
		logger.info("Test asking session for objects");
233 233

  
......
239 239
			e.printStackTrace();
240 240
			System.exit(1);
241 241
		}
242
		
242

  
243 243
		BotanicalName name1, name1_;
244 244
		Rank rankSpecies = Rank.SPECIES();
245 245
		Taxon taxon1;
246 246
		TaxonBase taxon1_;
247 247
		UUID t1uuid;
248
		
248

  
249 249
		try {
250 250
			/* ************** Start Transaction #1 ******************************** */
251
			
251

  
252 252
	    	TransactionStatus txStatOne = appCtr.startTransaction();
253
	    	
253

  
254 254
	    	List<TeamOrPersonBase> agents = appCtr.getAgentService().list(TeamOrPersonBase.class, MAX_ENTRIES, 0, null, null);
255 255
	    	TeamOrPersonBase author = agents.get(0);
256 256
	    	List<Reference> references = appCtr.getReferenceService().list(null, MAX_ENTRIES, 0, null, null);
257
	    	Reference<?> sec = references.get(0);
257
	    	Reference sec = references.get(0);
258 258

  
259
			name1 = 
259
			name1 =
260 260
				BotanicalName.NewInstance(rankSpecies, "NewTaxon1", null, "taxon1", null, author, null, "1", null);
261 261
	    	taxon1 = Taxon.NewInstance(name1, sec);
262 262
			t1uuid = appCtr.getTaxonService().saveOrUpdate(taxon1);
263 263
			//t1uuid = appCtr.getTaxonService().saveTaxon(taxon1, txStatOne);
264 264

  
265 265
			/* ************** Start Transaction #2 ******************************** */
266
	    	
266

  
267 267
			TransactionStatus txStatTwo = appCtr.startTransaction();
268 268

  
269 269
			// ask whether object taxon1 is known
270 270
			//getSession().
271
			
272
			name1_ = 
271

  
272
			name1_ =
273 273
				BotanicalName.NewInstance(rankSpecies, "NewTaxon1_", null, "taxon1_", null, author, null, "1_", null);
274 274
	    	taxon1_ = appCtr.getTaxonService().find(t1uuid);
275
			
275

  
276 276
			/* ************** Commit Transaction #1 ******************************** */
277
			
277

  
278 278
	    	appCtr.commitTransaction(txStatOne);
279
	    	
279

  
280 280
			//UUID t2uuid = appCtr.getTaxonService().saveTaxon(taxon2);
281
	    	
281

  
282 282
			/* ************** Commit Transaction #2 ******************************** */
283
			
283

  
284 284
	    	appCtr.commitTransaction(txStatTwo);
285
	    	
285

  
286 286
	    	appCtr.close();
287
			logger.info("End test ask session for objects"); 
288
				
287
			logger.info("End test ask session for objects");
288

  
289 289
		} catch (Exception e) {
290 290
    		logger.error("Error");
291 291
    		e.printStackTrace();
292 292
		}
293 293
	}
294
	
295 294

  
296
	private void test() { 
297
		
295

  
296
	private void test() {
297

  
298 298
    	/* Init DB */
299 299
		// initDb(ICdmDataSource db, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading)
300 300
		CdmApplicationController appCtrInit = TestDatabase.initDb(db, DbSchemaValidation.CREATE, false);
......
306 306
//		modifyDisjunctObjects();
307 307
//		modifySharedObjects();
308 308
	}
309
	
309

  
310 310
	/**
311 311
	 * @param args
312 312
	 */

Also available in: Unified diff