3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.io
.common
.mapping
;
13 import java
.lang
.reflect
.Method
;
14 import java
.sql
.ResultSet
;
15 import java
.sql
.SQLException
;
17 import org
.apache
.log4j
.Logger
;
19 import eu
.etaxonomy
.cdm
.io
.common
.DbImportStateBase
;
20 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
21 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 public class DbImportObjectMapper
extends DbSingleAttributeImportMapperBase
<DbImportStateBase
<?
,?
>, CdmBase
> {
29 @SuppressWarnings("unused")
30 private static final Logger logger
= Logger
.getLogger(DbImportObjectMapper
.class);
32 String relatedObjectNamespace
;
34 public static DbImportObjectMapper
NewInstance(String dbAttributString
, String cdmAttributeString
, String relatedObjectNamespace
){
35 return new DbImportObjectMapper(dbAttributString
, cdmAttributeString
, relatedObjectNamespace
);
40 * @param dbAttributString
41 * @param cdmAttributeString
43 protected DbImportObjectMapper(String dbAttributString
, String cdmAttributeString
, String relatedObjectNamespace
) {
44 super(dbAttributString
, cdmAttributeString
);
45 this.relatedObjectNamespace
= relatedObjectNamespace
;
51 * @see eu.etaxonomy.cdm.io.common.mapping.DbSingleAttributeImportMapperBase#getValue(java.sql.ResultSet)
54 protected Object
getValue(ResultSet rs
) throws SQLException
{
56 Object dbValue
= getDbValue(rs
);
57 String id
= String
.valueOf(dbValue
);
58 DbImportStateBase state
= importMapperHelper
.getState();
59 result
= state
.getRelatedObject(relatedObjectNamespace
, id
);
66 * @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass()
69 public Class
getTypeClass() {
70 String getterMethodName
= ImportHelper
.getGetterMethodName(getDestinationAttribute(), false);
73 method
= targetClass
.getMethod(getterMethodName
, null);
74 } catch (Exception e
) {
75 throw new RuntimeException("parameter type for DbImportObjectMapper could not be determined :"+ getterMethodName
);
77 Class
<?
> returnType
= method
.getReturnType();