Revision ab4cc1fb
Added by Andreas Müller about 14 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/erms/ErmsImportBase.java | ||
---|---|---|
15 | 15 |
import java.sql.SQLException; |
16 | 16 |
import java.sql.Timestamp; |
17 | 17 |
import java.util.HashMap; |
18 |
import java.util.HashSet; |
|
18 | 19 |
import java.util.Map; |
19 | 20 |
import java.util.Set; |
20 | 21 |
import java.util.UUID; |
... | ... | |
30 | 31 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
31 | 32 |
import eu.etaxonomy.cdm.io.common.Source; |
32 | 33 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR; |
34 |
import eu.etaxonomy.cdm.io.common.mapping.DbImportMapping; |
|
33 | 35 |
import eu.etaxonomy.cdm.model.common.AnnotatableEntity; |
34 | 36 |
import eu.etaxonomy.cdm.model.common.Annotation; |
35 | 37 |
import eu.etaxonomy.cdm.model.common.AnnotationType; |
... | ... | |
63 | 65 |
protected static final String TAXON_NAMESPACE = "Taxon"; |
64 | 66 |
protected static final String NAME_NAMESPACE = "TaxonName"; |
65 | 67 |
protected static final String VERNACULAR_NAMESPACE = "Vernaculars"; |
68 |
protected static final String FEATURE_NAMESPACE = "note.type"; |
|
66 | 69 |
|
67 | 70 |
//UUIDS |
68 | 71 |
public static final UUID GAZETTEER_UUID = UUID.fromString("dcfa124a-1028-49cd-aea5-fdf9bd396c1a"); |
... | ... | |
70 | 73 |
public static final UUID TNS_EXT_UUID = UUID.fromString("41cb0450-ac84-4d73-905e-9c7773c23b05"); |
71 | 74 |
|
72 | 75 |
|
73 |
|
|
74 |
|
|
75 | 76 |
private String pluralString; |
76 | 77 |
private String dbTableName; |
78 |
//TODO needed? |
|
79 |
private Class cdmTargetClass; |
|
80 |
|
|
77 | 81 |
|
78 | 82 |
|
79 | 83 |
/** |
80 | 84 |
* @param dbTableName |
81 | 85 |
* @param dbTableName2 |
82 | 86 |
*/ |
83 |
public ErmsImportBase(String pluralString, String dbTableName) { |
|
87 |
public ErmsImportBase(String pluralString, String dbTableName, Class cdmTargetClass) {
|
|
84 | 88 |
this.pluralString = pluralString; |
85 | 89 |
this.dbTableName = dbTableName; |
90 |
this.cdmTargetClass = cdmTargetClass; |
|
86 | 91 |
} |
87 | 92 |
|
88 | 93 |
protected boolean doInvoke(ErmsImportState state){ |
... | ... | |
108 | 113 |
logger.info("end make " + getPluralString() + " ... " + getSuccessString(success)); |
109 | 114 |
return success; |
110 | 115 |
} |
116 |
|
|
117 |
public boolean doPartition(ResultSetPartitioner partitioner, ErmsImportState state) { |
|
118 |
boolean success = true ; |
|
119 |
Set objectsToSave = new HashSet(); |
|
120 |
|
|
121 |
DbImportMapping<?, ?> mapping = getMapping(); |
|
122 |
mapping.initialize(state, cdmTargetClass); |
|
123 |
|
|
124 |
ResultSet rs = partitioner.getResultSet(); |
|
125 |
try{ |
|
126 |
while (rs.next()){ |
|
127 |
success &= mapping.invoke(rs,objectsToSave); |
|
128 |
} |
|
129 |
} catch (SQLException e) { |
|
130 |
logger.error("SQLException:" + e); |
|
131 |
return false; |
|
132 |
} |
|
133 |
|
|
134 |
partitioner.startDoSave(); |
|
135 |
getCommonService().save(objectsToSave); |
|
136 |
return success; |
|
137 |
} |
|
111 | 138 |
|
139 |
|
|
140 |
|
|
141 |
/** |
|
142 |
* @return |
|
143 |
*/ |
|
144 |
protected abstract DbImportMapping<?, ?> getMapping(); |
|
112 | 145 |
|
113 | 146 |
/** |
114 | 147 |
* @return |
Also available in: Unified diff
some refactoring in the IO classes