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 org.apache.log4j.Logger;
|
14
|
import org.hibernate.Hibernate;
|
15
|
import org.hsqldb.Types;
|
16
|
|
17
|
import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportConfigurator;
|
18
|
import eu.etaxonomy.cdm.io.berlinModel.out.DbExportState;
|
19
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
20
|
|
21
|
/**
|
22
|
* @author a.mueller
|
23
|
* @created 12.05.2009
|
24
|
* @version 1.0
|
25
|
*/
|
26
|
public class DbObjectMapper extends DbSingleAttributeExportMapperBase<DbExportState<?>> implements IDbExportMapper<DbExportState<?>> {
|
27
|
@SuppressWarnings("unused")
|
28
|
private static final Logger logger = Logger.getLogger(DbObjectMapper.class);
|
29
|
|
30
|
public static DbObjectMapper NewInstance(String cdmAttributeString, String dbAttributeString){
|
31
|
return new DbObjectMapper(cdmAttributeString, dbAttributeString, null);
|
32
|
}
|
33
|
|
34
|
/**
|
35
|
* @param dbAttributeString
|
36
|
* @param cdmAttributeString
|
37
|
*/
|
38
|
protected DbObjectMapper(String cdmAttributeString, String dbAttributeString, Object defaultValue) {
|
39
|
super(cdmAttributeString, dbAttributeString, defaultValue);
|
40
|
}
|
41
|
|
42
|
|
43
|
/* (non-Javadoc)
|
44
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue()
|
45
|
*/
|
46
|
@Override
|
47
|
protected Object getValue(CdmBase cdmBase) {
|
48
|
CdmBase value = (CdmBase)super.getValue(cdmBase);
|
49
|
if (value == null){
|
50
|
return null;
|
51
|
}
|
52
|
if (! Hibernate.isInitialized(value)){
|
53
|
Hibernate.initialize(value);
|
54
|
}
|
55
|
Object result = getId(value);
|
56
|
// getState().getConfig().getCdmAppController().commitTransaction(tx);
|
57
|
return result;
|
58
|
}
|
59
|
|
60
|
|
61
|
protected Integer getId(CdmBase cdmBase){
|
62
|
BerlinModelExportConfigurator config = getState().getConfig();
|
63
|
if (false && config.getIdType() == BerlinModelExportConfigurator.IdType.CDM_ID){
|
64
|
return cdmBase.getId();
|
65
|
}else{
|
66
|
Integer id = getState().getDbId(cdmBase);
|
67
|
return id;
|
68
|
}
|
69
|
}
|
70
|
|
71
|
/* (non-Javadoc)
|
72
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValueType()
|
73
|
*/
|
74
|
@Override
|
75
|
protected int getSqlType() {
|
76
|
return Types.INTEGER;
|
77
|
}
|
78
|
|
79
|
/* (non-Javadoc)
|
80
|
* @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass()
|
81
|
*/
|
82
|
@Override
|
83
|
public Class<?> getTypeClass() {
|
84
|
return CdmBase.class;
|
85
|
}
|
86
|
|
87
|
|
88
|
}
|