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.io.common.DbExportStateBase;
|
17
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
18
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
19
|
|
20
|
/**
|
21
|
* @author a.mueller
|
22
|
* @since 12.05.2009
|
23
|
*/
|
24
|
public class DbTimePeriodMapper extends DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> implements IDbExportMapper<DbExportStateBase<?, IExportTransformer>, IExportTransformer> {
|
25
|
@SuppressWarnings("unused")
|
26
|
private static final Logger logger = LogManager.getLogger(DbTimePeriodMapper.class);
|
27
|
|
28
|
public static DbTimePeriodMapper NewInstance(String cdmAttributeString, String dbAttributeString){
|
29
|
return new DbTimePeriodMapper(cdmAttributeString, dbAttributeString, null, true);
|
30
|
}
|
31
|
|
32
|
public static DbTimePeriodMapper NewInstance(String cdmAttributeString, String dbAttributeString, String defaultValue){
|
33
|
return new DbTimePeriodMapper(cdmAttributeString, dbAttributeString, defaultValue, true);
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* @param cdmAttributeString source attribute (CDM)
|
38
|
* @param dbAttributString target attribute (export DB)
|
39
|
* @param defaultValue default value if source value is <code>null</code>
|
40
|
* @param obligatory if the source attribute is obligatory, but value may be <code>null</code>
|
41
|
*/
|
42
|
public static DbTimePeriodMapper NewInstance(String cdmAttributeString, String dbAttributeString, String defaultValue, boolean obligatory){
|
43
|
return new DbTimePeriodMapper(cdmAttributeString, dbAttributeString, defaultValue, obligatory);
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* @param cdmAttributeString source attribute (CDM)
|
48
|
* @param dbAttributString target attribute (export DB)
|
49
|
* @param defaultValue default value if source value is <code>null</code>
|
50
|
* @param obligatory if the source attribute is obligatory, but value may be <code>null</code>
|
51
|
*/
|
52
|
private DbTimePeriodMapper(String cdmAttributeString, String dbAttributeString, String defaultValue, boolean obligatory) {
|
53
|
super(cdmAttributeString, dbAttributeString, defaultValue, obligatory, false);
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
protected Object getValue(CdmBase cdmBase) {
|
58
|
String result = null;
|
59
|
TimePeriod timePeriod = (TimePeriod)super.getValue(cdmBase);
|
60
|
if (timePeriod != null){
|
61
|
result = timePeriod.toString();
|
62
|
}
|
63
|
return result;
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
protected int getSqlType() {
|
68
|
return Types.VARCHAR;
|
69
|
}
|
70
|
|
71
|
@Override
|
72
|
public Class<?> getTypeClass() {
|
73
|
return TimePeriod.class;
|
74
|
}
|
75
|
}
|