Project

General

Profile

Download (1.76 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.Types;
13

    
14
import org.apache.log4j.Logger;
15

    
16
import eu.etaxonomy.cdm.model.common.CdmBase;
17

    
18
/**
19
 * @author a.mueller
20
 * @created 10.06.2009
21
 */
22
public class DbIntegerAnnotationMapper extends DbAnnotationMapper {
23
	private static final Logger logger = Logger.getLogger(DbIntegerAnnotationMapper.class);
24

    
25

    
26

    
27
	public static DbIntegerAnnotationMapper NewInstance(String annotationPrefix, String dbAttributeString){
28
		return new DbIntegerAnnotationMapper(annotationPrefix, dbAttributeString, null);
29
	}
30

    
31
	public static DbIntegerAnnotationMapper NewInstance(String annotationPrefix, String dbAttributeString, Integer defaultValue){
32
		return new DbIntegerAnnotationMapper(annotationPrefix, dbAttributeString, defaultValue);
33
	}
34

    
35
	/**
36
	 * @param dbAttributeString
37
	 * @param cdmAttributeString
38
	 */
39
	private DbIntegerAnnotationMapper(String annotationPrefix, String dbAttributeString, Integer defaultValue) {
40
		super("annotations", dbAttributeString, defaultValue, null);
41
	}
42

    
43
	@Override
44
	protected Object getValue(CdmBase cdmBase) {
45
		String strValue = (String)super.getValue(cdmBase);
46
		Integer intValue;
47
		try {
48
			intValue = (strValue == null) ? null : Integer.valueOf(strValue);
49
		} catch (NumberFormatException e) {
50
			logger.warn("Annotation could not be casted to Integer: " + strValue);
51
			return null;
52
		}
53
		return intValue;
54
	}
55

    
56
	@Override
57
	protected int getSqlType() {
58
		return Types.INTEGER;
59
	}
60

    
61
	@Override
62
	public Class<?> getTypeClass() {
63
		return Integer.class;
64
	}
65

    
66

    
67

    
68

    
69

    
70
}
(17-17/40)