Revision ab4cc1fb
Added by Andreas Müller about 14 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/erms/ErmsImageImport.java | ||
---|---|---|
20 | 20 |
import org.springframework.stereotype.Component; |
21 | 21 |
|
22 | 22 |
import eu.etaxonomy.cdm.io.common.IOValidator; |
23 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
|
24 | 23 |
import eu.etaxonomy.cdm.io.common.mapping.DbImportImageCreationMapper; |
25 | 24 |
import eu.etaxonomy.cdm.io.common.mapping.DbImportMapping; |
26 | 25 |
import eu.etaxonomy.cdm.io.common.mapping.DbImportMediaMapper; |
... | ... | |
38 | 37 |
*/ |
39 | 38 |
@Component |
40 | 39 |
public class ErmsImageImport extends ErmsImportBase<TextData> { |
40 |
@SuppressWarnings("unused") |
|
41 | 41 |
private static final Logger logger = Logger.getLogger(ErmsImageImport.class); |
42 | 42 |
|
43 | 43 |
private DbImportMapping mapping; |
... | ... | |
46 | 46 |
private int modCount = 10000; |
47 | 47 |
private static final String pluralString = "images"; |
48 | 48 |
private static final String dbTableName = "images"; |
49 |
//TODO needed? |
|
50 |
private Class cdmTargetClass = Media.class; |
|
49 |
private static final Class cdmTargetClass = Media.class; |
|
51 | 50 |
|
52 | 51 |
public ErmsImageImport(){ |
53 |
super(pluralString, dbTableName); |
|
52 |
super(pluralString, dbTableName, cdmTargetClass);
|
|
54 | 53 |
} |
55 | 54 |
|
56 | 55 |
|
... | ... | |
80 | 79 |
return strRecordQuery; |
81 | 80 |
} |
82 | 81 |
|
83 |
/**
|
|
84 |
* @return
|
|
82 |
/* (non-Javadoc)
|
|
83 |
* @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getMapping()
|
|
85 | 84 |
*/ |
86 |
private DbImportMapping getMapping() {
|
|
85 |
protected DbImportMapping getMapping() {
|
|
87 | 86 |
if (mapping == null){ |
88 | 87 |
mapping = new DbImportMapping(); |
89 | 88 |
//TODO do we need to add to TaxonNameBase too? |
... | ... | |
95 | 94 |
return mapping; |
96 | 95 |
} |
97 | 96 |
|
98 |
|
|
99 |
public boolean doPartition(ResultSetPartitioner partitioner, ErmsImportState state) { |
|
100 |
boolean success = true ; |
|
101 |
ErmsImportConfigurator config = state.getConfig(); |
|
102 |
Set referencesToSave = new HashSet<TaxonBase>(); |
|
103 |
|
|
104 |
DbImportMapping<?, ?> mapping = getMapping(); |
|
105 |
mapping.initialize(state, cdmTargetClass); |
|
106 |
|
|
107 |
ResultSet rs = partitioner.getResultSet(); |
|
108 |
try{ |
|
109 |
while (rs.next()){ |
|
110 |
success &= mapping.invoke(rs,referencesToSave); |
|
111 |
} |
|
112 |
} catch (SQLException e) { |
|
113 |
logger.error("SQLException:" + e); |
|
114 |
return false; |
|
115 |
} |
|
116 |
|
|
117 |
partitioner.startDoSave(); |
|
118 |
getReferenceService().save(referencesToSave); |
|
119 |
return success; |
|
120 |
} |
|
121 |
|
|
122 | 97 |
/* (non-Javadoc) |
123 | 98 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet) |
124 | 99 |
*/ |
Also available in: Unified diff
some refactoring in the IO classes