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.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
17
|
|
18
|
/**
|
19
|
* @author a.mueller
|
20
|
* @since 10.06.2009
|
21
|
*/
|
22
|
public class DbIntegerAnnotationMapper extends DbAnnotationMapper {
|
23
|
private static final Logger logger = LogManager.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
|
private DbIntegerAnnotationMapper(String annotationPrefix, String dbAttributeString, Integer defaultValue) {
|
36
|
super(dbAttributeString, "annotations", null, null, defaultValue, null);
|
37
|
}
|
38
|
|
39
|
@Override
|
40
|
protected Object getValue(CdmBase cdmBase) {
|
41
|
String strValue = (String)super.getValue(cdmBase);
|
42
|
Integer intValue;
|
43
|
try {
|
44
|
intValue = (strValue == null) ? null : Integer.valueOf(strValue);
|
45
|
} catch (NumberFormatException e) {
|
46
|
logger.warn("Annotation could not be casted to Integer: " + strValue);
|
47
|
return null;
|
48
|
}
|
49
|
return intValue;
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
protected int getSqlType() {
|
54
|
return Types.INTEGER;
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public Class<?> getTypeClass() {
|
59
|
return Integer.class;
|
60
|
}
|
61
|
|
62
|
|
63
|
|
64
|
|
65
|
|
66
|
}
|