1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.test.function;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
import java.sql.ResultSet;
|
14
|
import java.sql.SQLException;
|
15
|
import java.util.ArrayList;
|
16
|
import java.util.Arrays;
|
17
|
import java.util.EnumSet;
|
18
|
import java.util.HashSet;
|
19
|
import java.util.List;
|
20
|
import java.util.Set;
|
21
|
import java.util.UUID;
|
22
|
|
23
|
import org.apache.log4j.Logger;
|
24
|
import org.hibernate.Query;
|
25
|
import org.hibernate.Session;
|
26
|
import org.springframework.transaction.TransactionStatus;
|
27
|
|
28
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
29
|
import eu.etaxonomy.cdm.api.application.CdmApplicationUtils;
|
30
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
31
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
32
|
import eu.etaxonomy.cdm.api.service.TaxaAndNamesSearchMode;
|
33
|
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
|
34
|
import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO;
|
35
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
36
|
import eu.etaxonomy.cdm.api.service.search.SearchResult;
|
37
|
import eu.etaxonomy.cdm.common.AccountStore;
|
38
|
import eu.etaxonomy.cdm.database.CdmDataSource;
|
39
|
import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
|
40
|
import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
|
41
|
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
|
42
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
43
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
44
|
import eu.etaxonomy.cdm.model.agent.Person;
|
45
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
46
|
import eu.etaxonomy.cdm.model.common.init.TermNotFoundException;
|
47
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
48
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
49
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
50
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
51
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
52
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
53
|
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
|
54
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
55
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
56
|
import eu.etaxonomy.cdm.model.name.Rank;
|
57
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
58
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
59
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
60
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
61
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
62
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
63
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
64
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
65
|
|
66
|
/**
|
67
|
* This class is purely for function testing. Not used in production or testing frameworks.
|
68
|
*
|
69
|
* @author a.mueller
|
70
|
*/
|
71
|
public class Datasource {
|
72
|
private static final Logger logger = Logger.getLogger(Datasource.class);
|
73
|
|
74
|
|
75
|
private void testNewConfigControler(){
|
76
|
List<CdmPersistentDataSource> lsDataSources = CdmPersistentDataSource.getAllDataSources();
|
77
|
DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
|
78
|
|
79
|
String server;
|
80
|
String database;
|
81
|
String username;
|
82
|
|
83
|
System.out.println(lsDataSources);
|
84
|
ICdmDataSource dataSource;
|
85
|
|
86
|
dataSource = lsDataSources.get(1);
|
87
|
// DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
88
|
|
89
|
// server = "localhost";
|
90
|
//// database = "cdm36";
|
91
|
// database = "cdm_edaphobase";
|
92
|
// username = "edit";
|
93
|
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
|
94
|
|
95
|
server = "160.45.63.175";
|
96
|
database = "cdm_cyprus";
|
97
|
username = "edit";
|
98
|
dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
|
99
|
|
100
|
|
101
|
// server = "160.45.63.171";
|
102
|
// database = "cdm_production_cichorieae";
|
103
|
// username = "edit";
|
104
|
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
|
105
|
|
106
|
|
107
|
// server = "test.e-taxonomy.eu";
|
108
|
// database = "cdm_test1";
|
109
|
//// String database = "cdm_edit_flora_malesiana";
|
110
|
// username = "edit";
|
111
|
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
|
112
|
|
113
|
// server = "localhost";
|
114
|
// database = "testCDM";
|
115
|
// username = "postgres";
|
116
|
// dataSource = CdmDataSource.NewInstance(DatabaseTypeEnum.PostgreSQL, server, database, DatabaseTypeEnum.PostgreSQL.getDefaultPort(), username, AccountStore.readOrStorePassword(server, database, username, null));
|
117
|
|
118
|
|
119
|
// //SQLServer
|
120
|
// server = "BGBM-PESISQL";
|
121
|
// database = "cdm36";
|
122
|
// int port = 1433;
|
123
|
// username = "cdmupdater";
|
124
|
// dataSource = CdmDataSource.NewSqlServer2012Instance(server, database, port, username, AccountStore.readOrStorePassword(server, database, username, null));
|
125
|
////
|
126
|
// //H2
|
127
|
// String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2";
|
128
|
//// String path = "C:\\Users\\pesiimport\\.cdmLibrary\\writableResources\\h2\\LocalH2";
|
129
|
//// String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib-remote-webapp\\src\\test\\resources\\h2";
|
130
|
// username = "sa";
|
131
|
// dataSource = CdmDataSource.NewH2EmbeddedInstance("cdm", username, "", path);
|
132
|
|
133
|
// dataSource = CdmDataSource.NewH2EmbeddedInstance(database, username, "sa");
|
134
|
|
135
|
|
136
|
// server = "160.45.63.201";
|
137
|
// database = "cdm_integration_cichorieae";
|
138
|
// username = "edit";
|
139
|
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
|
140
|
|
141
|
|
142
|
// try {
|
143
|
// CdmUpdater updater = new CdmUpdater();
|
144
|
// if (schema == DbSchemaValidation.VALIDATE){
|
145
|
// updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
|
146
|
// }
|
147
|
// } catch (Exception e) {
|
148
|
// e.printStackTrace();
|
149
|
// }
|
150
|
|
151
|
//CdmPersistentDataSource.save(dataSource.getName(), dataSource);
|
152
|
CdmApplicationController appCtr;
|
153
|
appCtr = CdmApplicationController.NewInstance(dataSource, schema);
|
154
|
|
155
|
EnumSet<TaxaAndNamesSearchMode> searchModes = EnumSet.noneOf(TaxaAndNamesSearchMode.class);
|
156
|
searchModes.add(TaxaAndNamesSearchMode.doTaxa);
|
157
|
searchModes.add(TaxaAndNamesSearchMode.doSynonyms);
|
158
|
|
159
|
UUID classificationUUID = UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab");
|
160
|
Classification classification = appCtr.getClassificationService().find(classificationUUID);
|
161
|
UUID subtreeUUID = UUID.fromString("e993df74-671c-4a03-9c4c-be4a6447a0f2");
|
162
|
TaxonNode subtree = appCtr.getTaxonNodeService().find(subtreeUUID);
|
163
|
NamedArea area = (NamedArea)appCtr.getTermService().find(UUID.fromString("fbf21230-4a42-4f4c-9af8-5da52123c264"));
|
164
|
|
165
|
Set<NamedArea> namedAreas = new HashSet<>();
|
166
|
namedAreas.add(area);
|
167
|
Set<PresenceAbsenceTerm> distributionStatus = null;
|
168
|
int pageSize = 25;
|
169
|
int pageNumber = 0;
|
170
|
|
171
|
try {
|
172
|
Pager<SearchResult<TaxonBase>> result = appCtr.getTaxonService().findTaxaAndNamesByFullText(searchModes, "Phyla can*",
|
173
|
classification, subtree,
|
174
|
namedAreas, distributionStatus, null, false, pageSize, pageNumber, null, null);
|
175
|
|
176
|
result = appCtr.getTaxonService().findTaxaAndNamesByFullText(searchModes, "Phyla can*",
|
177
|
classification, subtree,
|
178
|
namedAreas, distributionStatus, null, false, pageSize, pageNumber, null, null);
|
179
|
|
180
|
result = appCtr.getTaxonService().findTaxaAndNamesByFullText(searchModes, "Phyla can*",
|
181
|
classification, subtree,
|
182
|
namedAreas, distributionStatus, null, false, pageSize, pageNumber, null, null);
|
183
|
|
184
|
result = appCtr.getTaxonService().findTaxaAndNamesByFullText(searchModes, "Phyla can*",
|
185
|
classification, subtree,
|
186
|
namedAreas, distributionStatus, null, false, pageSize, pageNumber, null, null);
|
187
|
} catch (Exception e) {
|
188
|
// TODO Auto-generated catch block
|
189
|
e.printStackTrace();
|
190
|
}
|
191
|
|
192
|
// List<String> DEFAULT_INIT_STRATEGY = Arrays.asList(new String []{
|
193
|
// "$"
|
194
|
// });
|
195
|
// IFindTaxaAndNamesConfigurator config = FindTaxaAndNamesConfiguratorImpl.NewInstance();
|
196
|
// config.setIncludeUnpublished(false);
|
197
|
// config.setPageNumber(0);
|
198
|
// config.setPageSize(25);
|
199
|
// config.setTitleSearchString("Lapsana communis");
|
200
|
// config.setDoTaxa(true );
|
201
|
// config.setDoSynonyms(true);
|
202
|
// config.setDoMisappliedNames(true);
|
203
|
// config.setDoTaxaByCommonNames(true);
|
204
|
// config.setMatchMode(MatchMode.BEGINNING);
|
205
|
// config.setTaxonPropertyPath(DEFAULT_INIT_STRATEGY);
|
206
|
// config.setNamedAreas(null);
|
207
|
// config.setDoIncludeAuthors(false);
|
208
|
// config.setOrder(null);
|
209
|
// UUID treeUuid = UUID.fromString("534e190f-3339-49ba-95d9-fa27d5493e3e");
|
210
|
// Classification classification = appCtr.getClassificationService().find(treeUuid);
|
211
|
// config.setClassification(classification);
|
212
|
//
|
213
|
// Pager<IdentifiableEntity> result = appCtr.getTaxonService().findTaxaAndNames(config);
|
214
|
// Classification classification = appCtr.getClassificationService().list(null, null, null, null, null).get(0);
|
215
|
// logger.warn(classification.getMicroReference());
|
216
|
// logger.warn(classification.getName());
|
217
|
|
218
|
// TransactionStatus tx = appCtr.startTransaction();
|
219
|
|
220
|
// testGroupedTaxa(appCtr);
|
221
|
|
222
|
|
223
|
// int n = appCtr.getAgentService().count(null);
|
224
|
// logger.warn("End adding " + n + " persons");
|
225
|
|
226
|
// appCtr.getCommonService().createFullSampleData();
|
227
|
|
228
|
// ValidationManager valMan = (ValidationManager)appCtr.getBean("validationManager");
|
229
|
// valMan.registerValidationListeners();
|
230
|
|
231
|
// State state = State.NewInstance();
|
232
|
// Taxon taxon = Taxon.NewInstance(null, null);
|
233
|
// TaxonDescription desc = TaxonDescription.NewInstance(taxon);
|
234
|
//// CategoricalData catData = CategoricalData.NewInstance(state, Feature.HABITAT());
|
235
|
// QuantitativeData quantData = QuantitativeData.NewInstance(Feature.ANATOMY());
|
236
|
// StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.AVERAGE(), 2);
|
237
|
// quantData.addStatisticalValue(statisticalValue);
|
238
|
// desc.addElement(quantData);
|
239
|
|
240
|
// appCtr.getTermService().saveOrUpdate(state);
|
241
|
//
|
242
|
// appCtr.getTaxonService().save(taxon);
|
243
|
|
244
|
// insertSomeData(appCtr);
|
245
|
// deleteHighLevelNode(appCtr); //->problem with Duplicate Key in Classification_TaxonNode
|
246
|
appCtr.close();
|
247
|
System.exit(0);
|
248
|
}
|
249
|
|
250
|
|
251
|
/**
|
252
|
* @param appCtr
|
253
|
*/
|
254
|
private void testGroupedTaxa(CdmApplicationController appCtr) {
|
255
|
UUID classificationUuid = UUID.fromString("91231ebf-1c7a-47b9-a56c-b45b33137244");
|
256
|
UUID taxonUuid1 = UUID.fromString("3bae1c86-1235-4e2e-be63-c7f8c4410527");
|
257
|
UUID taxonUuid2 = UUID.fromString("235d3872-defe-4b92-bf2f-75a7c91510de");
|
258
|
List<UUID> taxonUuids = Arrays.asList(new UUID[]{taxonUuid1, taxonUuid2});
|
259
|
Rank maxRank = DefinedTermBase.getTermByClassAndUUID(Rank.class, UUID.fromString("af5f2481-3192-403f-ae65-7c957a0f02b6"));
|
260
|
Rank minRank = DefinedTermBase.getTermByClassAndUUID(Rank.class, UUID.fromString("78786e16-2a70-48af-a608-494023b91904"));
|
261
|
List<GroupedTaxonDTO> groupedTaxa = appCtr.getClassificationService().groupTaxaByHigherTaxon(taxonUuids, classificationUuid, minRank, maxRank);
|
262
|
System.out.println(groupedTaxa);
|
263
|
}
|
264
|
|
265
|
|
266
|
private void addPerson(CdmApplicationController appCtr) {
|
267
|
TransactionStatus tx = appCtr.startTransaction();
|
268
|
appCtr.getAgentService().save(Person.NewInstance());
|
269
|
appCtr.commitTransaction(tx);
|
270
|
}
|
271
|
|
272
|
|
273
|
private void deleteHighLevelNode(CdmApplicationController appCtr) {
|
274
|
TransactionStatus tx = appCtr.startTransaction();
|
275
|
ITaxonNodeService service = appCtr.getTaxonNodeService();
|
276
|
TaxonNode node = service.find(60554);
|
277
|
// service.delete(node);
|
278
|
ITaxonService taxonService = appCtr.getTaxonService();
|
279
|
Taxon taxon = node.getTaxon();
|
280
|
//try {
|
281
|
taxonService.deleteTaxon(taxon.getUuid(), new TaxonDeletionConfigurator(), node.getClassification().getUuid());
|
282
|
|
283
|
/*} catch (DataChangeNoRollbackException e) {
|
284
|
e.printStackTrace();
|
285
|
}*/
|
286
|
try {
|
287
|
appCtr.commitTransaction(tx);
|
288
|
} catch (Exception e) {
|
289
|
// TODO Auto-generated catch block
|
290
|
e.printStackTrace();
|
291
|
}
|
292
|
TaxonNode node2 = service.find(60554);
|
293
|
|
294
|
|
295
|
}
|
296
|
|
297
|
private void insertSomeData(CdmApplicationController appCtr) {
|
298
|
Classification cl = Classification.NewInstance("myClass");
|
299
|
TaxonNode node1 = cl.addChildTaxon(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(null), null), null, null);
|
300
|
appCtr.getClassificationService().save(cl);
|
301
|
|
302
|
Taxon t2 = Taxon.NewInstance(null, null);
|
303
|
t2.setTitleCache("Taxon2", true);
|
304
|
TaxonNode node2 = node1.addChildTaxon(t2, null, null);
|
305
|
|
306
|
Taxon t3 = Taxon.NewInstance(null, null);
|
307
|
t3.setTitleCache("Taxon3", true);
|
308
|
TaxonNode node3 = node1.addChildTaxon(t3, 0, null, null);
|
309
|
|
310
|
appCtr.getTaxonNodeService().saveOrUpdate(node1);
|
311
|
|
312
|
cl.addChildNode(node3, 0, null, null);
|
313
|
appCtr.getTaxonNodeService().saveOrUpdate(node3);
|
314
|
appCtr.getClassificationService().saveOrUpdate(cl);
|
315
|
|
316
|
FeatureTree ft1 = FeatureTree.NewInstance();
|
317
|
FeatureNode fn1 = FeatureNode.NewInstance(null);
|
318
|
ft1.getRoot().addChild(fn1);
|
319
|
appCtr.getFeatureNodeService().save(fn1);
|
320
|
|
321
|
FeatureNode fn2 = FeatureNode.NewInstance(null);
|
322
|
fn1.addChild(fn2);
|
323
|
|
324
|
FeatureNode fn3 = FeatureNode.NewInstance(null);
|
325
|
fn1.addChild(fn2, 0);
|
326
|
|
327
|
appCtr.getFeatureNodeService().saveOrUpdate(fn1);
|
328
|
|
329
|
ft1.getRoot().addChild(fn3, 0);
|
330
|
appCtr.getFeatureNodeService().saveOrUpdate(fn3);
|
331
|
appCtr.getFeatureTreeService().saveOrUpdate(ft1);
|
332
|
}
|
333
|
|
334
|
private void testDatabaseChange() throws DataSourceNotFoundException{
|
335
|
CdmApplicationController appCtr;
|
336
|
appCtr = CdmApplicationController.NewInstance();
|
337
|
|
338
|
// DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
339
|
// String server = "192.168.2.10";
|
340
|
// String database = "cdm_test_andreas";
|
341
|
// String user = "edit";
|
342
|
// String pwd = "wp5";
|
343
|
//
|
344
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.SqlServer2005;
|
345
|
String server = "LAPTOPHP";
|
346
|
String database = "cdmTest";
|
347
|
String username = "edit";
|
348
|
String password = "";
|
349
|
|
350
|
ICdmDataSource dataSource = CdmDataSource.NewInstance(DatabaseTypeEnum.SqlServer2005, "LAPTOPHP", "cdmTest", DatabaseTypeEnum.SqlServer2005.getDefaultPort(), "edit", "");
|
351
|
|
352
|
appCtr.getDatabaseService().saveDataSource("testSqlServer", dataSource);
|
353
|
try {
|
354
|
appCtr.getDatabaseService().connectToDatabase(dbType, server, database, username, password);
|
355
|
} catch (TermNotFoundException e) {
|
356
|
// TODO Auto-generated catch block
|
357
|
e.printStackTrace();
|
358
|
}
|
359
|
|
360
|
appCtr.close();
|
361
|
}
|
362
|
|
363
|
private void testSqlServer2005(){
|
364
|
DatabaseTypeEnum databaseTypeEnum = DatabaseTypeEnum.SqlServer2005;
|
365
|
String server = "LAPTOPHP";
|
366
|
String database = "cdmTest";
|
367
|
String username = "edit";
|
368
|
String password = "";
|
369
|
|
370
|
ICdmDataSource dataSource = CdmDataSource.NewInstance(databaseTypeEnum, server, database, databaseTypeEnum.getDefaultPort(), username, password);
|
371
|
|
372
|
CdmPersistentDataSource ds = CdmPersistentDataSource.save("testSqlServer", dataSource);
|
373
|
|
374
|
CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds);
|
375
|
Person agent = Person.NewInstance();
|
376
|
appCtr.getAgentService().save(agent);
|
377
|
TaxonName tn = TaxonNameFactory.NewBotanicalInstance(null);
|
378
|
appCtr.getNameService().save(tn);
|
379
|
appCtr.close();
|
380
|
|
381
|
}
|
382
|
|
383
|
|
384
|
private void testLocalHsql(){
|
385
|
CdmApplicationController appCtr = null;
|
386
|
try {
|
387
|
CdmPersistentDataSource ds = CdmPersistentDataSource.NewLocalHsqlInstance();
|
388
|
appCtr = CdmApplicationController.NewInstance(ds);
|
389
|
List<?> l = appCtr.getNameService().list(null,5, 1,null,null);
|
390
|
System.out.println(l);
|
391
|
//Agent agent = new Agent();
|
392
|
//appCtr.getAgentService().saveAgent(agent);
|
393
|
appCtr.close();
|
394
|
} catch (RuntimeException e) {
|
395
|
logger.error("Runtime Exception");
|
396
|
e.printStackTrace();
|
397
|
if (appCtr != null){
|
398
|
appCtr.close();
|
399
|
}
|
400
|
|
401
|
} catch (DataSourceNotFoundException e) {
|
402
|
logger.error("Runtime Exception");
|
403
|
e.printStackTrace();
|
404
|
}
|
405
|
}
|
406
|
|
407
|
private void testLocalH2(){
|
408
|
|
409
|
DbSchemaValidation validation = DbSchemaValidation.CREATE;
|
410
|
ICdmDataSource ds =
|
411
|
CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "", null);
|
412
|
// ds =
|
413
|
// CdmPersistentDataSource.NewInstance("localH2");
|
414
|
CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds, validation);
|
415
|
|
416
|
boolean exists = appCtr.getUserService().userExists("admin");
|
417
|
try {
|
418
|
IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(null);
|
419
|
String nameCache = "testName";
|
420
|
name.setNameCache(nameCache);
|
421
|
name.setTitleCache(nameCache, true);
|
422
|
Reference ref = ReferenceFactory.newGeneric();
|
423
|
ref.setTitleCache("mySec", true);
|
424
|
Taxon taxon = Taxon.NewInstance(name, ref);
|
425
|
TaxonDescription description = TaxonDescription.NewInstance();
|
426
|
taxon.addDescription(description);
|
427
|
NamedArea area1 = appCtr.getTermService().getAreaByTdwgAbbreviation("GER");
|
428
|
Distribution distribution = Distribution.NewInstance(area1, PresenceAbsenceTerm.PRESENT());
|
429
|
description.addElement(distribution);
|
430
|
|
431
|
List<Distribution> distrList = new ArrayList<Distribution>();
|
432
|
distrList.add(distribution);
|
433
|
List<NamedArea> areaList = new ArrayList<NamedArea>();
|
434
|
areaList.add(area1);
|
435
|
|
436
|
// distribution.getInDescription().get
|
437
|
appCtr.getTaxonService().save(taxon);
|
438
|
|
439
|
System.out.println(taxon.getDescriptions().size());
|
440
|
|
441
|
TransactionStatus txStatus = appCtr.startTransaction();
|
442
|
|
443
|
Session session = appCtr.getSessionFactory().getCurrentSession();
|
444
|
|
445
|
//String hqlQuery = "from DescriptionBase d join d.elements as e "
|
446
|
// String hqlQuery = "from Taxon t join t.descriptions as d "+
|
447
|
// " inner join d.elements e on e member of d "
|
448
|
// +
|
449
|
// "";//" where e.area = :namedArea " ;
|
450
|
String hqlQuery = "Select t from Distribution e join e.inDescription d join d.taxon t join t.name n "+
|
451
|
" WHERE e.area in (:namedArea) AND n.nameCache = :nameCache ";
|
452
|
Query query = session.createQuery(hqlQuery);
|
453
|
|
454
|
//query.setEntity("namedArea", area1);
|
455
|
query.setParameter("nameCache", nameCache);
|
456
|
query.setParameterList("namedArea", areaList);
|
457
|
List resultList = query.list();
|
458
|
//List list = appCtr.getCommonService().getHqlResult(hqlQuery);
|
459
|
|
460
|
for (Object o:resultList){
|
461
|
System.out.println(o);
|
462
|
}
|
463
|
appCtr.commitTransaction(txStatus);
|
464
|
|
465
|
//System.out.println(l);
|
466
|
//Agent agent = new Agent();
|
467
|
//appCtr.getAgentService().saveAgent(agent);
|
468
|
appCtr.close();
|
469
|
} catch (RuntimeException e) {
|
470
|
logger.error("Runtime Exception");
|
471
|
e.printStackTrace();
|
472
|
appCtr.close();
|
473
|
|
474
|
}
|
475
|
}
|
476
|
|
477
|
private boolean testWritableResourceDirectory() throws IOException{
|
478
|
CdmApplicationUtils.getWritableResourceDir();
|
479
|
return true;
|
480
|
}
|
481
|
|
482
|
private boolean testH2(){
|
483
|
// testLocalH2();
|
484
|
// if (true)return true;
|
485
|
|
486
|
DbSchemaValidation validation = DbSchemaValidation.CREATE;
|
487
|
ICdmDataSource ds =
|
488
|
CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "", null);
|
489
|
//CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "");
|
490
|
// ds =
|
491
|
// CdmPersistentDataSource.NewInstance("localH2");
|
492
|
CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds, validation);
|
493
|
try {
|
494
|
TaxonName botName1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
495
|
TaxonName botName2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
496
|
IBotanicalName hybridName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
497
|
botName1.addRelationshipToName(botName2, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), null);
|
498
|
UUID uuid1 = botName1.getUuid();
|
499
|
UUID uuid2 = botName2.getUuid();
|
500
|
try {
|
501
|
Logger loggerTrace = Logger.getLogger("org.hibernate.type");
|
502
|
//loggerTrace.setLevel(Level.TRACE);
|
503
|
System.out.println(logger.getName());
|
504
|
|
505
|
appCtr.getNameService().save(botName1);
|
506
|
ResultSet rs = ds.executeQuery("Select count(*) as n FROM NameRelationship");
|
507
|
rs.next();
|
508
|
int c = rs.getInt("n");
|
509
|
System.out.println("Begin :" + c);
|
510
|
|
511
|
botName1.removeRelationToTaxonName(botName2);
|
512
|
botName1.setSpecificEpithet("DELETED");
|
513
|
botName2.addHybridParent(hybridName, HybridRelationshipType.FIRST_PARENT(), null);
|
514
|
|
515
|
TransactionStatus tx = appCtr.startTransaction();
|
516
|
appCtr.getNameService().saveOrUpdate(botName2);
|
517
|
rs = ds.executeQuery("Select count(*) as n FROM NameRelationship");
|
518
|
rs.next();
|
519
|
c = rs.getInt("n");
|
520
|
System.out.println("End: " + c);
|
521
|
|
522
|
appCtr.commitTransaction(tx);
|
523
|
|
524
|
appCtr.getNameService().saveOrUpdate(botName1);
|
525
|
|
526
|
rs = ds.executeQuery("Select count(*) as n FROM NameRelationship");
|
527
|
rs.next();
|
528
|
c = rs.getInt("n");
|
529
|
System.out.println("End: " + c);
|
530
|
|
531
|
} catch (SQLException e) {
|
532
|
// TODO Auto-generated catch block
|
533
|
e.printStackTrace();
|
534
|
}
|
535
|
|
536
|
|
537
|
//Agent agent = new Agent();
|
538
|
//appCtr.getAgentService().saveAgent(agent);
|
539
|
appCtr.close();
|
540
|
return true;
|
541
|
} catch (RuntimeException e) {
|
542
|
logger.error("Runtime Exception");
|
543
|
e.printStackTrace();
|
544
|
appCtr.close();
|
545
|
|
546
|
}
|
547
|
return false;
|
548
|
}
|
549
|
|
550
|
private void test(){
|
551
|
System.out.println("Start Datasource");
|
552
|
testNewConfigControler();
|
553
|
//testDatabaseChange();
|
554
|
|
555
|
//testSqlServer();
|
556
|
|
557
|
//CdmUtils.findLibrary(au.com.bytecode.opencsv.CSVReader.class);
|
558
|
//testPostgreServer();
|
559
|
//testLocalHsql();
|
560
|
//testLocalH2();
|
561
|
//testWritableResourceDirectory();
|
562
|
// testH2();
|
563
|
System.out.println("\nEnd Datasource");
|
564
|
}
|
565
|
|
566
|
/**
|
567
|
* @param args
|
568
|
*/
|
569
|
public static void main(String[] args) {
|
570
|
Datasource cc = new Datasource();
|
571
|
cc.test();
|
572
|
}
|
573
|
|
574
|
}
|