Project

General

Profile

Download (2.38 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
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.berlinModel.out.DbExportState;
19
import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportConfigurator.IdType;
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21

    
22
/**
23
 * @author a.mueller
24
 * @created 12.05.2009
25
 * @version 1.0
26
 */
27
public class IdMapper extends DbSingleAttributeExportMapperBase<DbExportState<?>> implements IDbExportMapper<DbExportState<?>>{
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
	 * @param dbAttributString
36
	 * @param cdmAttributeString
37
	 */
38
	protected IdMapper(String dbIdAttributeString) {
39
		super(null, dbIdAttributeString, null);
40
	}
41

    
42

    
43
	/* (non-Javadoc)
44
	 * @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass()
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
	/* (non-Javadoc)
60
	 * @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue()
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
			//TODO
69
			logger.warn("MAX_ID not yet implemented");
70
			return cdmBase.getId();
71
		}else if(type == IdType.ORIGINAL_SOURCE_ID){
72
			//TODO
73
			logger.warn("ORIGINAL_SOURCE_ID");
74
			return cdmBase.getId();
75
		}else{
76
			logger.warn("Unknown idType: " + type);
77
			return cdmBase.getId();
78
		}
79
	}
80
	
81
	
82

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