Project

General

Profile

Download (2.65 KB) Statistics
| Branch: | Tag: | Revision:
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.sql.ResultSet;
13
import java.sql.SQLException;
14

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
18
import eu.etaxonomy.cdm.model.common.CdmBase;
19

    
20
/**
21
 * @author a.mueller
22
 * @since 12.03.2010
23
 * @version 1.0
24
 */
25
public abstract class DbImportMultiAttributeMapperBase<CDMBASE extends CdmBase, STATE extends DbImportStateBase<?,?>> extends MultipleAttributeMapperBase<CdmSingleAttributeMapperBase> implements IDbImportMapper<STATE, CDMBASE>{
26
	@SuppressWarnings("unused")
27
	private static final Logger logger = Logger.getLogger(DbImportMultiAttributeMapperBase.class);
28
	
29
//**************************** ATTRIBUTES ****************************************************
30
	
31
	protected DbImportMapperBase<STATE> importMapperHelper = new DbImportMapperBase<STATE>();
32
	
33
	/* (non-Javadoc)
34
	 * @see eu.etaxonomy.cdm.io.common.mapping.IDbImportMapper#initialize(eu.etaxonomy.cdm.io.common.DbImportStateBase, java.lang.Class)
35
	 */
36
	public void initialize(STATE state, Class<? extends CdmBase> destinationClass) {
37
		importMapperHelper.initialize(state, destinationClass);
38
	} 
39
	
40
	protected STATE getState(){
41
		return importMapperHelper.getState();
42
	}
43
	
44

    
45
	/**
46
	 * Retrieves a related object from the state's related object map. Needs casting.
47
	 * @param namespace
48
	 * @param foreignKey
49
	 * @return
50
	 */
51
	protected CdmBase getRelatedObject(String namespace, String foreignKey) {
52
		STATE state = importMapperHelper.getState();
53
		CdmBase result = state.getRelatedObject(namespace, foreignKey);
54
		return result;
55
	}
56
	
57
	/**
58
	 * Retrieves a related object from the state's related object map. Needs casting.
59
	 * @param namespace
60
	 * @param foreignKey
61
	 * @return
62
	 * @throws SQLException 
63
	 */
64
	protected CdmBase getRelatedObject(ResultSet rs, String namespace, String fkAttribute) throws SQLException {
65
		STATE state = importMapperHelper.getState();
66
		String foreignKey = getForeignKey(rs, fkAttribute);
67
		CdmBase result = state.getRelatedObject(namespace, foreignKey);
68
		return result;
69
	}
70
	
71
	/**
72
	 * @param rs
73
	 * @param dbReferenceFkAttribute2
74
	 * @return
75
	 * @throws SQLException 
76
	 */
77
	protected String getForeignKey(ResultSet rs, String fkAttribute) throws SQLException {
78
		Object oForeignKey = rs.getObject(fkAttribute);
79
		String result = String.valueOf(oForeignKey);
80
		return result;
81
	}
82
	
83
	
84
}
(26-26/51)