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;
|
11
|
|
12
|
import java.lang.reflect.Method;
|
13
|
import java.sql.ResultSet;
|
14
|
import java.sql.SQLException;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
|
18
|
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
|
19
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
20
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
21
|
|
22
|
/**
|
23
|
* @author a.mueller
|
24
|
* @created 26.02.2010
|
25
|
* @version 1.0
|
26
|
*/
|
27
|
public class DbImportObjectMapper extends DbSingleAttributeImportMapperBase<DbImportStateBase<?,?>, CdmBase> {
|
28
|
@SuppressWarnings("unused")
|
29
|
private static final Logger logger = Logger.getLogger(DbImportObjectMapper.class);
|
30
|
|
31
|
String relatedObjectNamespace;
|
32
|
|
33
|
public static DbImportObjectMapper NewInstance(String dbAttributString, String cdmAttributeString, String relatedObjectNamespace){
|
34
|
return new DbImportObjectMapper(dbAttributString, cdmAttributeString, relatedObjectNamespace);
|
35
|
}
|
36
|
|
37
|
|
38
|
/**
|
39
|
* @param dbAttributString
|
40
|
* @param cdmAttributeString
|
41
|
*/
|
42
|
protected DbImportObjectMapper(String dbAttributString, String cdmAttributeString, String relatedObjectNamespace) {
|
43
|
super(dbAttributString, cdmAttributeString);
|
44
|
this.relatedObjectNamespace = relatedObjectNamespace;
|
45
|
}
|
46
|
|
47
|
|
48
|
|
49
|
/* (non-Javadoc)
|
50
|
* @see eu.etaxonomy.cdm.io.common.mapping.DbSingleAttributeImportMapperBase#getValue(java.sql.ResultSet)
|
51
|
*/
|
52
|
@Override
|
53
|
protected Object getValue(ResultSet rs) throws SQLException {
|
54
|
Object result;
|
55
|
Object dbValue = getDbValue(rs);
|
56
|
String id = String.valueOf(dbValue);
|
57
|
DbImportStateBase state = importMapperHelper.getState();
|
58
|
result = state.getRelatedObject(relatedObjectNamespace, id);
|
59
|
return result;
|
60
|
}
|
61
|
|
62
|
|
63
|
|
64
|
/* (non-Javadoc)
|
65
|
* @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass()
|
66
|
*/
|
67
|
@Override
|
68
|
public Class getTypeClass() {
|
69
|
String getterMethodName = ImportHelper.getGetterMethodName(getDestinationAttribute(), false);
|
70
|
Method method;
|
71
|
try {
|
72
|
method = targetClass.getMethod(getterMethodName, null);
|
73
|
} catch (Exception e) {
|
74
|
throw new RuntimeException("parameter type for DbImportObjectMapper could not be determined :"+ getterMethodName);
|
75
|
}
|
76
|
Class<?> returnType = method.getReturnType();
|
77
|
return returnType;
|
78
|
}
|
79
|
}
|