Project

General

Profile

Download (21 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2008 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
*/
6

    
7
package eu.etaxonomy.cdm.test.integration;
8

    
9
import java.sql.ResultSet;
10
import java.sql.SQLException;
11
import java.util.ArrayList;
12
import java.util.HashMap;
13
import java.util.List;
14
import java.util.Map;
15

    
16
import org.apache.log4j.Logger;
17
import org.springframework.transaction.TransactionStatus;
18

    
19
import eu.etaxonomy.cdm.api.application.CdmApplicationDefaultController;
20
import eu.etaxonomy.cdm.common.AccountStore;
21
import eu.etaxonomy.cdm.database.CdmDataSource;
22
import eu.etaxonomy.cdm.database.DbSchemaValidation;
23
import eu.etaxonomy.cdm.database.ICdmDataSource;
24
import eu.etaxonomy.cdm.io.common.Source;
25
import eu.etaxonomy.cdm.model.agent.AgentBase;
26
import eu.etaxonomy.cdm.model.common.CdmBase;
27
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
28
import eu.etaxonomy.cdm.model.common.LanguageString;
29
import eu.etaxonomy.cdm.model.common.Representation;
30
import eu.etaxonomy.cdm.model.common.TermVocabulary;
31
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
32
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
33
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
34
import eu.etaxonomy.cdm.model.reference.Reference;
35

    
36
/**
37
 * @author a.babadshanjan
38
 * @created 15.09.2008
39
 */
40
public class TestCdmDbComparator {
41
	
42
	private static final String sourceDbOne = "cdm_test_jaxb";
43
	private static final String sourceDbTwo = "cdm_test_jaxb2";
44
	
45
	private static final ICdmDataSource sourceOne = TestCdmDbComparator.CDM_DB(sourceDbOne);
46
	private static final ICdmDataSource sourceTwo = TestCdmDbComparator.CDM_DB(sourceDbTwo);
47
	
48
	private static final String server = "192.168.2.10";
49
	private static final String username = "edit";
50

    
51
	public static ICdmDataSource CDM_DB(String dbname) {
52
		
53
	String password = AccountStore.readOrStorePassword(dbname, server, username, null);
54
	ICdmDataSource datasource = CdmDataSource.NewMySqlInstance(server, dbname, username, password);
55
	return datasource;
56
	}
57
	
58
    private final int MAX_ROWS = 60000;
59
    private final int MAX_TABLES = 150;
60

    
61
    private static final Logger logger = Logger.getLogger(TestCdmDbComparator.class);
62
	
63
	private static final String[] table_list = {
64
//			"Address",
65
			"Agent",
66
//			"Agent_Agent",
67
//			"Agent_Annotation",
68
//			"Agent_DefinedTermBase", 
69
//			"Agent_Extension", 
70
//			"Agent_InstitutionalMembership", 
71
//			"Agent_Marker", 
72
//			"Agent_Media", 
73
//			"Agent_OriginalSource", 
74
//			"Agent_Rights", 
75
			"Annotation", 
76
//			"CDM_VIEW", 
77
//			"CDM_VIEW_CDM_VIEW", 
78
//			"Collection", 
79
//			"Collection_Annotation", 
80
//			"Collection_Extension", 
81
//			"Collection_Marker", 
82
//			"Collection_Media", 
83
//			"Collection_OriginalSource", 
84
//			"Collection_Rights", 
85
//			"Contact", 
86
			"DefinedTermBase", 
87
//			"DefinedTermBase_DefinedTermBase",
88
//			"DefinedTermBase_Media", 
89
//			"DefinedTermBase_Representation", 
90
//			"DefinedTermBase_TermVocabulary", 
91
//			"DerivationEvent", 
92
//			"DerivationEvent_Annotation", 
93
//			"DerivationEvent_Marker", 
94
			"DescriptionBase", 
95
//			"DescriptionBase_Annotation", 
96
//			"DescriptionBase_DefinedTermBase",
97
//			"DescriptionBase_DescriptionElementBase",
98
//			"DescriptionBase_Extension", 
99
//			"DescriptionBase_Marker", 
100
//			"DescriptionBase_OriginalSource", 
101
//			"DescriptionBase_Rights", 
102
			"DescriptionElementBase", 
103
//			"DescriptionElementBase_Annotation",
104
//			"DescriptionElementBase_DefinedTermBase",
105
//			"DescriptionElementBase_LanguageString",
106
//			"DescriptionElementBase_Marker", 
107
//			"DescriptionElementBase_Media", 
108
//			"DescriptionElementBase_StatisticalMeasurementValue",
109
//			"DeterminationEvent", 
110
//			"DeterminationEvent_Annotation", 
111
//			"DeterminationEvent_Marker", 
112
//			"Extension", 
113
			"FeatureNode", 
114
			"FeatureTree", 
115
//			"FeatureTree_Representation", 
116
//			"GatheringEvent", 
117
//			"GatheringEvent_Annotation", 
118
//			"GatheringEvent_Marker", 
119
			"HomotypicalGroup", 
120
//			"HomotypicalGroup_Annotation", 
121
//			"HomotypicalGroup_Marker", 
122
//			"HybridRelationship", 
123
//			"HybridRelationship_Annotation", 
124
//			"HybridRelationship_Marker", 
125
//			"InstitutionalMembership", 
126
			"LanguageString", 
127
//			"Locus", 
128
			"Marker", 
129
			"Media", 
130
			"MediaRepresentation", 
131
			"MediaRepresentationPart", 
132
//			"Media_Annotation", 
133
//			"Media_Marker", 
134
//			"Media_Rights", 
135
//			"Media_Sequence", 
136
//			"Media_TaxonBase", 
137
			"NameRelationship", 
138
//			"NameRelationship_Annotation", 
139
//			"NameRelationship_Marker", 
140
			"NomenclaturalStatus", 
141
//			"NomenclaturalStatus_Annotation", 
142
//			"NomenclaturalStatus_Marker", 
143
			"OriginalSource", 
144
//			"OriginalSource_Annotation", 
145
//			"OriginalSource_Marker", 
146
//			"Person_Keyword", 
147
			"Reference", 
148
//			"ReferenceBase_Annotation", 
149
//			"ReferenceBase_Extension", 
150
//			"ReferenceBase_Marker", 
151
//			"ReferenceBase_Media", 
152
//			"ReferenceBase_OriginalSource", 
153
//			"ReferenceBase_Rights", 
154
//			"RelationshipTermBase_inverseRepresentation",
155
			"Representation",
156
//			"Rights",
157
//			"Sequence",
158
//			"Sequence_Annotation", 
159
//			"Sequence_Extension", 
160
//			"Sequence_Marker", 
161
//			"Sequence_Media", 
162
//			"Sequence_OriginalSource", 
163
//			"Sequence_ReferenceBase", 
164
//			"Sequence_Rights", 
165
			"SpecimenOrObservationBase", 
166
//			"SpecimenOrObservationBase_Annotation",
167
//			"SpecimenOrObservationBase_DerivationEvent",
168
//			"SpecimenOrObservationBase_Extension",
169
//			"SpecimenOrObservationBase_Marker",
170
//			"SpecimenOrObservationBase_Media",
171
//			"SpecimenOrObservationBase_OriginalSource",
172
//			"SpecimenOrObservationBase_Rights",
173
//			"SpecimenOrObservationBase_Sequence",
174
//			"StateData",
175
//			"StateData_DefinedTermBase", 
176
//			"StatisticalMeasurementValue", 
177
//			"StatisticalMeasurementValue_DefinedTermBase",
178
			"SynonymRelationship", 
179
//			"SynonymRelationship_Annotation", 
180
//			"SynonymRelationship_Marker", 
181
			"TaxonBase", 
182
//			"TaxonBase_Annotation", 
183
//			"TaxonBase_Extension", 
184
//			"TaxonBase_Marker", 
185
//			"TaxonBase_OriginalSource", 
186
//			"TaxonBase_Rights", 
187
			"TaxonNameBase", 
188
//			"TaxonNameBase_Annotation", 
189
//			"TaxonNameBase_Extension", 
190
//			"TaxonNameBase_HybridRelationship",
191
//			"TaxonNameBase_Marker", 
192
//			"TaxonNameBase_NomenclaturalStatus",
193
//			"TaxonNameBase_OriginalSource", 
194
//			"TaxonNameBase_Rights", 
195
//			"TaxonNameBase_TypeDesignationBase",
196
			"TaxonRelationship", 
197
//			"TaxonRelationship_Annotation", 
198
//			"TaxonRelationship_Marker", 
199
			"TermVocabulary", 
200
//			"TermVocabulary_Representation", 
201
			"TypeDesignationBase", 
202
//			"TypeDesignationBase_Annotation", 
203
//			"TypeDesignationBase_Marker", 
204
	};
205

    
206
//	@Autowired
207
//	@Qualifier("cdmDao")
208
//	private ICdmEntityDao cdmDao;
209
	
210
//	@Autowired
211
//	protected void setDao(ICdmEntityDao dao) {
212
//		logger.debug("setting DAO");
213
//		this.cdmDao = dao;
214
//	}
215
	
216
//	@Autowired
217
//	private SessionFactory factory;
218
//	
219
//	protected Session getSession(){
220
//	Session session = factory.getCurrentSession();
221
//	return session;
222
//}
223

    
224
//    public ResultSet getResultSet (String query){
225
//    	ResultSet rs;
226
//    	try {
227
//            this.getConnection(); //establish connection
228
//        	if (query == null){
229
//        		return null;
230
//        	}
231
//            mStmt = mConn.createStatement();
232
//            rs = mStmt.executeQuery(query);
233
//            return rs;
234
//        }catch(SQLException e){
235
//            logger.error("Problems when creating Resultset for query \n  " + query + " \n" + "Exception: " + e);
236
//            return null;
237
//        }
238
//    }
239
    
240
	private Map<String, List<String>> doLoadDataFromDb(String dbname, Source source) {
241
    	
242
		Map<String, List<String>> dbTables = new HashMap<String, List<String>>();
243
		
244
		logger.info("Loading data from DB " + dbname);
245

    
246
		CdmApplicationDefaultController appCtr = null;
247

    
248

    
249
		String password = AccountStore.readOrStorePassword(dbname, server, username, null);
250
		
251
		DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
252
		ICdmDataSource datasource = CdmDataSource.NewMySqlInstance(server, dbname, username, password);
253
		appCtr = CdmApplicationDefaultController.NewInstance(datasource, dbSchemaValidation, true);
254

    
255
    	
256
    	TransactionStatus txStatus = appCtr.startTransaction(true);
257

    
258
    	// get data from DB
259

    
260
    	try {
261

    
262
    		dbTables = retrieveAllTables(appCtr);
263
    		
264
    	} catch (Exception e) {
265
    		logger.error("error setting data");
266
    		e.printStackTrace();
267
    	}
268
    	appCtr.commitTransaction(txStatus);
269
    	appCtr.close();
270
    	
271
    	return dbTables;
272
    	
273
    }
274
	
275
	private Map<String, List<CdmBase>> doLoadDataFromDb_(String dbname) {
276
    	
277
		Map<String, List<CdmBase>> dbTables = new HashMap<String, List<CdmBase>>();
278
		
279
		logger.info("Loading data from DB " + dbname);
280

    
281
		CdmApplicationDefaultController appCtr = null;
282

    
283

    
284
		String password = AccountStore.readOrStorePassword(dbname, server, username, null);
285
		
286
		DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
287
		ICdmDataSource datasource = CdmDataSource.NewMySqlInstance(server, dbname, username, password);
288
		appCtr = CdmApplicationDefaultController.NewInstance(datasource, dbSchemaValidation, true);
289

    
290
    	
291
    	TransactionStatus txStatus = appCtr.startTransaction(true);
292

    
293
    	// get data from DB
294

    
295
    	try {
296

    
297
    		dbTables = retrieveAllTables_(appCtr);
298
    		
299
    	} catch (Exception e) {
300
    		logger.error("error setting data");
301
    		e.printStackTrace();
302
    	}
303
    	appCtr.commitTransaction(txStatus);
304
    	appCtr.close();
305
    	
306
    	return dbTables;
307
    	
308
    }
309
	
310
	private Map<String, List<String>> doLoadDataFromDb__(String dbname, Source source) {
311
    	
312
		Map<String, List<String>> dbTables = new HashMap<String, List<String>>();
313
		
314
		logger.info("Loading data from DB " + dbname);
315

    
316
    	try {
317

    
318
    		dbTables = retrieveAllTables__(source);
319
    		
320
    	} catch (Exception e) {
321
    		logger.error("error setting data");
322
    		e.printStackTrace();
323
    	}
324
    	return dbTables;
325
    	
326
    }
327
	
328
    private Map<String, List<CdmBase>> retrieveAllTables_(CdmApplicationDefaultController appCtr) {
329
    	
330
		Map<String, List<CdmBase>> tables_ = new HashMap<String, List<CdmBase>>(table_list.length);
331
		
332
		List<String> tableRows = new ArrayList<String>(MAX_ROWS);
333
			
334
		//List<Agent> agents = appCtr.getAgentService().getAllAgents(MAX_ROWS, 0);
335
		
336
		try {
337
			//get data from database
338
			for (int i = 0; i < table_list.length; i++) {
339

    
340
	    		logger.debug("Retrieving table '" + table_list[i] + "'");
341
	    		System.out.println("Retrieving table '" + table_list[i] + "'");
342
	    		
343
				List<CdmBase> rows = new ArrayList<CdmBase>(MAX_ROWS);
344

    
345
				rows = appCtr.getMainService().rows(table_list[i], MAX_ROWS, 0);	
346
				
347
    			tables_.put(table_list[i], rows);
348

    
349
			}
350
				
351
		} catch (Exception e) {
352
    		logger.error("error retrieving data");
353
    		e.printStackTrace();
354
		}
355
//		return tables;
356
		return tables_;
357
    }
358

    
359
    private Map<String, List<String>> retrieveAllTables___(Source source) {
360
    	
361
		Map<String, List<String>> tables = new HashMap<String, List<String>>(table_list.length);
362
		List<String> tableRows = new ArrayList<String>(MAX_ROWS);
363
			
364
		try {
365
			//get data from database
366
			for (int i = 0; i < table_list.length; i++) {
367
				
368
				List<String> rows = new ArrayList<String>(MAX_ROWS);
369

    
370
//					Session session = factory.getCurrentSession();
371
					
372
//					if ( sessionObject != null ) {
373
//						session.update(sessionObject);
374
//					}
375
//					Query query = session.createQuery("select term from DefinedTermBase term join fetch term.representations representation where representation.label = :label");
376
//					query.setParameter("label", queryString);
377
					
378
//					Query query = session.createQuery("select from " + table_list[i]);
379
//				    rows = query.list();
380
				
381
				//FIXME: NullPointerException (cdmDao is null)
382
				    //rows = cdmDao.list(MAX_ROWS, 0);
383
					tables.put(table_list[i], rows);
384

    
385
				}
386
				
387
		} catch (Exception e) {
388
    		logger.error("error retrieving data");
389
    		e.printStackTrace();
390
		}
391
		return tables;
392
    }
393

    
394
    private Map<String, List<String>> retrieveAllTables__(Source source) {
395
    	
396
//		IImportConfigurator config = new BerlinModelImportConfigurator;
397
//		BerlinModelImportConfigurator bmiConfig = (BerlinModelImportConfigurator)config;
398
//		Source source = bmiConfig.getSource();
399
//		ResultSet rs = berlinModelSource.getResultSet();
400

    
401
		Map<String, List<String>> tables = new HashMap<String, List<String>>(table_list.length);
402
		List<String> tableRows = new ArrayList<String>(MAX_ROWS);
403
			
404
		try {
405
			//get data from database
406
			for (int i = 0; i < table_list.length; i++) {
407
				String strQuery = 
408
					" SELECT * FROM " + table_list[i];
409
				logger.debug("SQL Statement: " +  strQuery);
410
				//ResultSet rs = berlinModelSource.getResultSet();
411
				//ResultSet rs = source.getResultSet(strQuery) ;
412
				ResultSet rs = source.getResultSet(strQuery) ;
413
				List<String> rows = new ArrayList<String>(MAX_ROWS);
414

    
415
				while (rs.next()) {
416
					rows.add(rs.toString());
417
				}
418
				tables.put(table_list[i], rows);
419
			}
420
		} catch (SQLException e) {
421
			logger.error("SQLException:" +  e);
422
		}
423
		return tables;
424
    }
425
    
426
    private Map<String, List<String>> retrieveAllTables(CdmApplicationDefaultController appCtr) {
427
		
428
		Map<String, List<String>> tables = new HashMap<String, List<String>>(table_list.length);
429
		
430
		List<String> agentTableContent = new ArrayList<String>(MAX_ROWS);
431
		List<? extends AgentBase> agents = appCtr.getAgentService().list(null,MAX_ROWS, 0,null,null);
432
		for (AgentBase agent: agents ) {
433
			//TODO: Want the entire row as string not just toString() of the object.
434
			agentTableContent.add(agent.toString());
435
		}
436
		tables.put("agents", agentTableContent);
437

    
438
		//List<Annotation> annotations = appCtr.getTermService().getAllAnnotations(MAX_ROWS, 0);
439
		
440
		List<String> definedTermBaseTableContent = new ArrayList<String>(MAX_ROWS);
441
		List<DefinedTermBase> definedTermBases = appCtr.getTermService().list(null,MAX_ROWS, 0,null,null);
442
		for (DefinedTermBase definedTermBase: definedTermBases ) {
443
			definedTermBaseTableContent.add(definedTermBase.toString());
444
		}
445
		tables.put("definedTermBases", definedTermBaseTableContent);
446

    
447
		//List<DescriptionBase> descriptionBases = appCtr.getDescriptionService().getAllDescriptionBases(MAX_ROWS, 0);
448
		//List<DescriptionElementBase> descriptionElementBases = appCtr.getDescriptionService().getAllDescriptionElementBases(MAX_ROWS, 0);
449
		//List<HomotypicalGroup> homotypicalGroups = appCtr.getNameService().getAllHomotypicalGroups(MAX_ROWS, 0);
450
		List<LanguageString> languageStrings = appCtr.getTermService().getAllLanguageStrings(MAX_ROWS, 0);
451
		//List<Marker> markers = appCtr.getTermService().getAllMarkers(MAX_ROWS, 0);
452
		//List<NameRelationship> nameRelationships = appCtr.getNameService().getAllNameRelationships(MAX_ROWS, 0);
453
		List<NomenclaturalStatus> nomenclaturalStatus = appCtr.getNameService().getAllNomenclaturalStatus(MAX_ROWS, 0);
454
		//List<OriginalSource> originalSources = appCtr.getNameService().getAllOriginalSources(MAX_ROWS, 0);
455
		List<Reference> references = appCtr.getReferenceService().list(null,MAX_ROWS, 0,null,null);
456
		List<Representation> representations = appCtr.getTermService().getAllRepresentations(MAX_ROWS, 0);
457
		List<SpecimenOrObservationBase> specimenOrObservationBases = appCtr.getOccurrenceService().list(null,MAX_ROWS, 0,null,null);
458
		//List<SynonymRelationship> synonymRelationships = appCtr.getTaxonService().getAllSynonymRelationships(MAX_ROWS, 0);
459
//		List<TaxonBase> taxonBases = appCtr.getTaxonService().getAllTaxa(MAX_ROWS, 0);
460
//		List<TaxonNameBase> taxonNameBases = appCtr.getNameService().getAllNames(MAX_ROWS, 0);
461
		//List<TaxonRelationship> taxonRelationships = appCtr.getTaxonService().getAllTaxonRelationships(MAX_ROWS, 0);
462
		List<TermVocabulary> termVocabularies = appCtr.getVocabularyService().list(null,MAX_ROWS, 0,null,null);
463
		List<TypeDesignationBase> typeDesignationBases = appCtr.getNameService().getAllTypeDesignations(MAX_ROWS, 0);
464
		
465
		return tables;
466
	}
467
	
468
     private void compareTables(String tableName, List<CdmBase> tablesDbOne, List<CdmBase> tablesDbTwo) {
469
    	
470
		int tableOneSize = tablesDbOne.size();
471
		int tableTwoSize = tablesDbTwo.size();
472
		int tableMinSize = 0;
473
		int tableMaxSize = 0;
474
	
475
		if (tableOneSize != tableTwoSize) {
476
			logger.warn("Table '" + tableName + "', Rows differ: " + tablesDbOne.size() + ", " + tablesDbTwo.size());
477
            tableMinSize = Math.min(tableOneSize, tableTwoSize);
478
            tableMaxSize = Math.max(tableOneSize, tableTwoSize);
479
		} else {
480
			logger.info("Table '" + tableName + "': " + tablesDbOne.size());
481
		}
482
		
483
		int different = 0;
484
		
485
		try {
486
		for (int i = 0; i < tableMinSize; i++) {
487

    
488
			CdmBase obj1 = tablesDbOne.get(i);
489
			CdmBase obj2 = tablesDbTwo.get(i);
490

    
491
			// This compares only whether both tables contain the same objects.
492
			// It doesn't check whether all field values are the same.
493
			logger.debug("Row # " + i + ":");
494
			if (obj1.equals(obj2) != true) {
495
				different++;
496
				logger.debug("Table 1 = " + obj1); 
497
				logger.debug("Table 2 = " + obj2); 
498
			} else {
499
				logger.debug("Entry = " + obj1); 
500
			}
501
		}
502
		if (different > 0) {
503
			logger.info("# Rows identical: " + (tableMaxSize - different)); 
504
			logger.warn("# Rows different: " + different); 
505
		} 
506
		} catch (org.hibernate.LazyInitializationException e){
507
			logger.error("LazyInitializationException");
508
		}
509
	}
510

    
511
    	private void doCompareDatabases(Map<String, List<CdmBase>> tablesDbOne, Map<String, List<CdmBase>> tablesDbTwo) {
512
//        public void doCompareDatabases(Map<String, List<String>> tablesDbOne, Map<String, List<String>> tablesDbTwo) {
513
		
514
		logger.debug("# Tables in DB 1: " + tablesDbOne.size());
515
		logger.debug("# Tables in DB 2: " + tablesDbTwo.size());
516
		
517
		for (String tableName: tablesDbOne.keySet()) {
518

    
519
			logger.info("Comparing table '" + tableName + "'");
520
			
521
//			List<String> dbOneTableRows = new ArrayList<String>();
522
//			List<String> dbTwoTableRows = new ArrayList<String>();
523
			List<CdmBase> dbOneTableRows = new ArrayList<CdmBase>();
524
			List<CdmBase> dbTwoTableRows = new ArrayList<CdmBase>();
525
			
526
			dbOneTableRows = tablesDbOne.get(tableName);
527
			dbTwoTableRows = tablesDbTwo.get(tableName);
528
			
529
//			Collections.sort(dbOneTableRows);
530
//			Collections.sort(dbTwoTableRows);
531

    
532
			int different = 0;
533
			int tableSize = dbOneTableRows.size();
534
			
535
			for (int i = 0; i < tableSize; i++) {
536

    
537
//				String str1 = dbOneTableRows.get(i);
538
//				String str2 = dbTwoTableRows.get(i);
539
				CdmBase str1 = dbOneTableRows.get(i);
540
				CdmBase str2 = dbTwoTableRows.get(i);
541

    
542
				if (str1.equals(str2) != true) {
543

    
544
					different++;
545
					logger.debug("Rows differ:");
546
					logger.debug("Table 1 Row = " + str1); 
547
					logger.debug("Table 2 Row = " + str2); 
548

    
549
				}
550
				i++;
551
			}
552
			if (different > 0) {
553
				logger.info("Compared table '" + tableName + "':");
554
				logger.info("# Rows total: " + tableSize);
555
				logger.info("# Rows identical: " + (tableSize - different)); 
556
				logger.warn("# Rows different: " + different); 
557
			}
558
		}
559
		logger.info("End database comparison"); 
560
	}
561

    
562
//	private void test_(){
563
//		
564
//		Map<String, List<CdmBase>> tablesDbOne = doLoadDataFromDb_(sourceDbOne);
565
//		Map<String, List<CdmBase>> tablesDbTwo = doLoadDataFromDb_(sourceDbTwo);
566
//	    doCompareDatabases(tablesDbOne, tablesDbTwo);
567
//
568
//	}
569
	
570
	private void test(){
571
		
572
		CdmApplicationDefaultController appCtrOne = null;
573
		CdmApplicationDefaultController appCtrTwo = null;
574
		logger.info("Comparing '" + sourceDbOne + "' and '" + sourceDbTwo + "'");
575

    
576
		try {
577
			appCtrOne = CdmApplicationDefaultController.NewInstance(sourceOne, DbSchemaValidation.VALIDATE, true);
578
			appCtrTwo = CdmApplicationDefaultController.NewInstance(sourceTwo, DbSchemaValidation.VALIDATE, true);
579

    
580
		} catch (Exception e) {
581
			logger.error("Error creating application controller");
582
			e.printStackTrace();
583
			System.exit(1);
584
		}
585
		
586
		try {
587
			//get data from database
588
	    	TransactionStatus txStatOne = appCtrOne.startTransaction(true);
589
	    	TransactionStatus txStatTwo = appCtrTwo.startTransaction(true);
590
			for (int i = 0; i < table_list.length; i++) {
591

    
592
				List<CdmBase> rowsDbOne = new ArrayList<CdmBase>(MAX_ROWS);
593
				List<CdmBase> rowsDbTwo = new ArrayList<CdmBase>(MAX_ROWS);
594
				rowsDbOne = appCtrOne.getMainService().rows(table_list[i], MAX_ROWS, 0);
595
				rowsDbTwo = appCtrTwo.getMainService().rows(table_list[i], MAX_ROWS, 0);	
596
				compareTables(table_list[i], rowsDbOne, rowsDbTwo);
597
			}
598
	    	appCtrTwo.commitTransaction(txStatTwo);
599
	    	appCtrOne.commitTransaction(txStatOne);
600
	    	//java.lang.IllegalStateException: Cannot deactivate transaction synchronization - not active
601
	    	appCtrOne.close();
602
	    	appCtrTwo.close();
603
			logger.info("End database comparison"); 
604
				
605
		} catch (Exception e) {
606
    		logger.error("Error retrieving or comparing data");
607
    		e.printStackTrace();
608
		}
609
	}
610
	
611
	/**
612
	 * @param args
613
	 */
614
	public static void  main(String[] args) {
615
		TestCdmDbComparator diff = new TestCdmDbComparator();
616
    	diff.test();
617
	}
618
}
    (1-1/1)