Project

General

Profile

Download (2.31 KB) Statistics
| Branch: | Tag: | Revision:
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.common.mapping.out;
11

    
12
import java.sql.SQLException;
13
import java.sql.Types;
14

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.io.common.DbExportConfiguratorBase.IdType;
18
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
19
import eu.etaxonomy.cdm.model.common.CdmBase;
20

    
21
/**
22
 * Adds a single value to the mapping which represents the id of the mapped object
23
 *
24
 * @author a.mueller
25
 * @since 12.05.2009
26
 */
27
public class IdMapper
28
        extends DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>>
29
        implements IDbExportMapper<DbExportStateBase<?, IExportTransformer>, IExportTransformer>{
30
	private static final Logger logger = Logger.getLogger(IdMapper.class);
31

    
32
	public static IdMapper NewInstance(String dbIdAttributeString){
33
		return new IdMapper(dbIdAttributeString);
34
	}
35

    
36
	/**
37
	 * @param dbAttributString
38
	 * @param cdmAttributeString
39
	 */
40
	protected IdMapper(String dbIdAttributeString) {
41
		super(null, dbIdAttributeString, null);
42
	}
43

    
44

    
45
	@Override
46
	public Class<?> getTypeClass() {
47
		return Integer.class;
48
	}
49

    
50
	@Override
51
	protected boolean doInvoke(CdmBase cdmBase) throws SQLException{
52
		boolean result = super.doInvoke(cdmBase);
53
		getState().putDbId(cdmBase, (Integer)getValue(cdmBase));
54
		return result;
55

    
56
	}
57

    
58
	@Override
59
	protected Object getValue(CdmBase cdmBase) {
60
		IdType type = getState().getConfig().getIdType();
61
		if (type == IdType.CDM_ID){
62
			return cdmBase.getId();
63
		}else if (type == IdType.CDM_ID_WITH_EXCEPTIONS){
64
				return getState().getCurrentIO().getDbId(cdmBase, getState());
65
		}else if(type == IdType.MAX_ID){
66
			//TODO
67
			logger.warn("MAX_ID not yet implemented");
68
			return cdmBase.getId();
69
		}else if(type == IdType.ORIGINAL_SOURCE_ID){
70
			//TODO
71
			logger.warn("ORIGINAL_SOURCE_ID not yet implemented");
72
			return cdmBase.getId();
73
		}else{
74
			logger.warn("Unknown idType: " + type);
75
			return cdmBase.getId();
76
		}
77
	}
78

    
79

    
80

    
81
	/* (non-Javadoc)
82
	 * @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValueType()
83
	 */
84
	@Override
85
	protected int getSqlType() {
86
		return Types.INTEGER;
87
	}
88

    
89
}
(37-37/40)