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.io.common.DbExportStateBase;
|
17
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
18
|
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
|
19
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
21
|
|
22
|
/**
|
23
|
* @author a.mueller
|
24
|
* @created 12.05.2009
|
25
|
* @version 1.0
|
26
|
*/
|
27
|
public class DbOriginalNameMapper extends DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> implements IDbExportMapper<DbExportStateBase<?, IExportTransformer>, IExportTransformer>{
|
28
|
@SuppressWarnings("unused")
|
29
|
private static final Logger logger = Logger.getLogger(DbOriginalNameMapper.class);
|
30
|
|
31
|
private boolean isCache = false;
|
32
|
|
33
|
public static DbOriginalNameMapper NewInstance(String dbAttributeString, boolean isCache, Object defaultValue){
|
34
|
return new DbOriginalNameMapper(dbAttributeString, isCache, defaultValue);
|
35
|
}
|
36
|
|
37
|
/**
|
38
|
* @param dbAttributeString
|
39
|
* @param cdmAttributeString
|
40
|
*/
|
41
|
protected DbOriginalNameMapper(String dbAttributeString, boolean isCache, Object defaultValue) {
|
42
|
super("originalName", dbAttributeString, defaultValue);
|
43
|
this.isCache = isCache;
|
44
|
}
|
45
|
|
46
|
/* (non-Javadoc)
|
47
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue(eu.etaxonomy.cdm.model.common.CdmBase)
|
48
|
*/
|
49
|
@Override
|
50
|
protected Object getValue(CdmBase cdmBase) {
|
51
|
Object result = null;
|
52
|
if (cdmBase.isInstanceOf(OriginalSourceBase.class)){
|
53
|
OriginalSourceBase<?> source = CdmBase.deproxy(cdmBase, OriginalSourceBase.class);
|
54
|
String nameString = source.getOriginalNameString();
|
55
|
TaxonName<?,?> name = null;
|
56
|
if (source.isInstanceOf(DescriptionElementSource.class)){
|
57
|
DescriptionElementSource descSource = CdmBase.deproxy(source, DescriptionElementSource.class);
|
58
|
name = descSource.getNameUsedInSource();
|
59
|
}
|
60
|
|
61
|
if (name != null){
|
62
|
if (isCache){
|
63
|
return name.getTitleCache();
|
64
|
}else{
|
65
|
return getState().getDbId(name);
|
66
|
}
|
67
|
}else{
|
68
|
if (isCache){
|
69
|
return nameString;
|
70
|
}else{
|
71
|
return null;
|
72
|
}
|
73
|
}
|
74
|
|
75
|
}else{
|
76
|
throw new ClassCastException("CdmBase for "+this.getClass().getName() +" must be of type OriginalSourceBase, but was " + cdmBase.getClass());
|
77
|
}
|
78
|
}
|
79
|
|
80
|
/* (non-Javadoc)
|
81
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValueType()
|
82
|
*/
|
83
|
@Override
|
84
|
protected int getSqlType() {
|
85
|
if (isCache){
|
86
|
return Types.VARCHAR;
|
87
|
}else{
|
88
|
return Types.INTEGER;
|
89
|
}
|
90
|
}
|
91
|
|
92
|
|
93
|
/* (non-Javadoc)
|
94
|
* @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass()
|
95
|
*/
|
96
|
@Override
|
97
|
public Class<?> getTypeClass() {
|
98
|
if (isCache){
|
99
|
return String.class;
|
100
|
}else{
|
101
|
return Integer.class;
|
102
|
}
|
103
|
}
|
104
|
}
|