1
|
/**
|
2
|
* Copyright (C) 2007 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.io.redlist.gefaesspflanzen;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.springframework.stereotype.Component;
|
21
|
|
22
|
import eu.etaxonomy.cdm.io.common.DbImportBase;
|
23
|
import eu.etaxonomy.cdm.io.common.IPartitionedIO;
|
24
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
25
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
28
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
29
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
30
|
|
31
|
/**
|
32
|
*
|
33
|
* @author pplitzner
|
34
|
* @date Mar 1, 2016
|
35
|
*
|
36
|
*/
|
37
|
|
38
|
@Component
|
39
|
@SuppressWarnings("serial")
|
40
|
public class RedListGefaesspflanzenImportTaxa extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
|
41
|
|
42
|
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportTaxa.class);
|
43
|
|
44
|
private static final String tableName = "Rote Liste Gefäßpflanzen";
|
45
|
|
46
|
private static final String pluralString = "taxa";
|
47
|
|
48
|
public RedListGefaesspflanzenImportTaxa() {
|
49
|
super(tableName, pluralString);
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
protected String getIdQuery(RedListGefaesspflanzenImportState state) {
|
54
|
return "SELECT NAMNR "
|
55
|
+ "FROM V_TAXATLAS_D20_EXPORT t "
|
56
|
+ " ORDER BY NAMNR";
|
57
|
}
|
58
|
|
59
|
@Override
|
60
|
protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
|
61
|
String result = " SELECT * "
|
62
|
+ " FROM V_TAXATLAS_D20_EXPORT t "
|
63
|
+ " WHERE t.NAMNR IN (@IDSET)";
|
64
|
result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
|
65
|
return result;
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
protected void doInvoke(RedListGefaesspflanzenImportState state) {
|
70
|
super.doInvoke(state);
|
71
|
}
|
72
|
|
73
|
|
74
|
@Override
|
75
|
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
|
76
|
ResultSet rs = partitioner.getResultSet();
|
77
|
Set<TaxonBase> taxaToSave = new HashSet<>();
|
78
|
try {
|
79
|
while (rs.next()){
|
80
|
makeSingleTaxon(state, rs, taxaToSave);
|
81
|
|
82
|
}
|
83
|
} catch (SQLException e) {
|
84
|
e.printStackTrace();
|
85
|
}
|
86
|
|
87
|
getTaxonService().saveOrUpdate(taxaToSave);
|
88
|
return true;
|
89
|
}
|
90
|
|
91
|
private void makeSingleTaxon(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonBase> taxaToSave)
|
92
|
throws SQLException {
|
93
|
long id = rs.getLong("NAMNR");
|
94
|
String gueltString = rs.getString("GUELT");
|
95
|
|
96
|
BotanicalName name = state.getRelatedObject(Namespace.NAME_NAMESPACE,String.valueOf(id), BotanicalName.class);
|
97
|
TaxonBase taxon = Taxon.NewInstance(name, null);
|
98
|
|
99
|
taxaToSave.add(taxon);
|
100
|
|
101
|
//id
|
102
|
ImportHelper.setOriginalSource(taxon, state.getTransactionalSourceReference(), id, Namespace.TAXON_NAMESPACE);
|
103
|
}
|
104
|
|
105
|
@Override
|
106
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
|
107
|
RedListGefaesspflanzenImportState state) {
|
108
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
109
|
Map<String, BotanicalName> nameMap = new HashMap<String, BotanicalName>();
|
110
|
try {
|
111
|
while (rs.next()){
|
112
|
long id = rs.getLong("NAMNR");
|
113
|
nameMap.put(String.valueOf(id), (BotanicalName) getNameService().load(state.getNameMap().get(id)));
|
114
|
}
|
115
|
} catch (SQLException e) {
|
116
|
e.printStackTrace();
|
117
|
}
|
118
|
result.put(Namespace.NAME_NAMESPACE, nameMap);
|
119
|
|
120
|
return result;
|
121
|
}
|
122
|
|
123
|
@Override
|
124
|
protected boolean doCheck(RedListGefaesspflanzenImportState state) {
|
125
|
return false;
|
126
|
}
|
127
|
|
128
|
@Override
|
129
|
protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
|
130
|
return false;
|
131
|
}
|
132
|
|
133
|
}
|