1
2
3
4
5
6
7
8
9
10
11 package eu.etaxonomy.cdm.io.berlinModel.out.mapper;
12
13 import java.sql.SQLException;
14
15 import org.apache.log4j.Logger;
16 import org.hsqldb.Types;
17
18 import eu.etaxonomy.cdm.io.common.DbExportConfiguratorBase.IdType;
19 import eu.etaxonomy.cdm.io.common.DbExportStateBase;
20 import eu.etaxonomy.cdm.model.common.CdmBase;
21
22
23
24
25
26
27 public class IdMapper extends DbSingleAttributeExportMapperBase<DbExportStateBase<?>> implements IDbExportMapper<DbExportStateBase<?>>{
28 private static final Logger logger = Logger.getLogger(IdMapper.class);
29
30 public static IdMapper NewInstance(String dbIdAttributeString){
31 return new IdMapper(dbIdAttributeString);
32 }
33
34
35
36
37
38 protected IdMapper(String dbIdAttributeString) {
39 super(null, dbIdAttributeString, null);
40 }
41
42
43
44
45
46 @Override
47 public Class<?> getTypeClass() {
48 return Integer.class;
49 }
50
51 @Override
52 protected boolean doInvoke(CdmBase cdmBase) throws SQLException{
53 boolean result = super.doInvoke(cdmBase);
54 getState().putDbId(cdmBase, (Integer)getValue(cdmBase));
55 return result;
56
57 }
58
59
60
61
62 @Override
63 protected Object getValue(CdmBase cdmBase) {
64 IdType type = getState().getConfig().getIdType();
65 if (type == IdType.CDM_ID){
66 return cdmBase.getId();
67 }else if(type == IdType.MAX_ID){
68
69 logger.warn("MAX_ID not yet implemented");
70 return cdmBase.getId();
71 }else if(type == IdType.ORIGINAL_SOURCE_ID){
72
73 logger.warn("ORIGINAL_SOURCE_ID not yet implemented");
74 return cdmBase.getId();
75 }else{
76 logger.warn("Unknown idType: " + type);
77 return cdmBase.getId();
78 }
79 }
80
81
82
83
84
85
86 @Override
87 protected int getSqlType() {
88 return Types.INTEGER;
89 }
90
91 }