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