Revision ab4cc1fb
Added by Andreas Müller about 14 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/erms/ErmsAreaImport.java | ||
---|---|---|
12 | 12 |
import java.sql.ResultSet; |
13 | 13 |
import java.sql.SQLException; |
14 | 14 |
import java.util.HashMap; |
15 |
import java.util.HashSet; |
|
16 | 15 |
import java.util.Map; |
17 |
import java.util.Set; |
|
18 | 16 |
import java.util.UUID; |
19 | 17 |
|
20 | 18 |
import org.apache.log4j.Logger; |
21 | 19 |
import org.springframework.stereotype.Component; |
22 | 20 |
|
23 | 21 |
import eu.etaxonomy.cdm.io.common.IOValidator; |
24 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
|
25 | 22 |
import eu.etaxonomy.cdm.io.common.mapping.DbImportAnnotationMapper; |
26 | 23 |
import eu.etaxonomy.cdm.io.common.mapping.DbImportExtensionMapper; |
27 | 24 |
import eu.etaxonomy.cdm.io.common.mapping.DbImportMapping; |
... | ... | |
34 | 31 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
35 | 32 |
import eu.etaxonomy.cdm.model.location.NamedAreaLevel; |
36 | 33 |
import eu.etaxonomy.cdm.model.location.NamedAreaType; |
37 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
38 | 34 |
|
39 | 35 |
|
40 | 36 |
/** |
... | ... | |
52 | 48 |
private int modCount = 10000; |
53 | 49 |
private static final String pluralString = "areas"; |
54 | 50 |
private static final String dbTableName = "gu"; |
55 |
private Class cdmTargetClass = NamedArea.class; |
|
51 |
private static final Class cdmTargetClass = NamedArea.class;
|
|
56 | 52 |
|
57 | 53 |
public ErmsAreaImport(){ |
58 |
super(pluralString, dbTableName); |
|
54 |
super(pluralString, dbTableName, cdmTargetClass);
|
|
59 | 55 |
} |
60 | 56 |
|
61 | 57 |
|
... | ... | |
71 | 67 |
return strRecordQuery; |
72 | 68 |
} |
73 | 69 |
|
74 |
/**
|
|
75 |
* @return
|
|
70 |
/* (non-Javadoc)
|
|
71 |
* @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getMapping()
|
|
76 | 72 |
*/ |
77 |
private DbImportMapping getMapping() {
|
|
73 |
protected DbImportMapping getMapping() {
|
|
78 | 74 |
if (mapping == null){ |
79 | 75 |
mapping = new DbImportMapping(); |
80 | 76 |
|
... | ... | |
87 | 83 |
return mapping; |
88 | 84 |
} |
89 | 85 |
|
90 |
|
|
91 |
public boolean doPartition(ResultSetPartitioner partitioner, ErmsImportState state) { |
|
92 |
boolean success = true ; |
|
93 |
ErmsImportConfigurator config = state.getConfig(); |
|
94 |
Set areasToSave = new HashSet<TaxonBase>(); |
|
95 |
|
|
96 |
DbImportMapping<?, ?> mapping = getMapping(); |
|
97 |
mapping.initialize(state, cdmTargetClass); |
|
98 |
|
|
99 |
ResultSet rs = partitioner.getResultSet(); |
|
100 |
try{ |
|
101 |
while (rs.next()){ |
|
102 |
success &= mapping.invoke(rs,areasToSave); |
|
103 |
} |
|
104 |
} catch (SQLException e) { |
|
105 |
logger.error("SQLException:" + e); |
|
106 |
return false; |
|
107 |
} |
|
108 |
|
|
109 |
partitioner.startDoSave(); |
|
110 |
getTermService().save(areasToSave); |
|
111 |
return success; |
|
112 |
} |
|
113 |
|
|
114 |
|
|
115 | 86 |
|
116 | 87 |
/* (non-Javadoc) |
117 | 88 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet) |
Also available in: Unified diff
some refactoring in the IO classes