Project

General

Profile

Download (2.62 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
package eu.etaxonomy.cdm.io.common.mapping;
10

    
11
import java.sql.ResultSet;
12
import java.sql.SQLException;
13
import java.util.ArrayList;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Set;
17

    
18
import org.apache.commons.lang3.StringUtils;
19
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
20

    
21
/**
22
 * @author a.mueller
23
 * @since 12.05.2009
24
 */
25
public abstract class MultipleAttributeMapperBase<SINGLE_MAPPER extends CdmSingleAttributeMapperBase> extends CdmAttributeMapperBase {
26
	@SuppressWarnings("unused")
27
	private static final Logger logger = LogManager.getLogger(MultipleAttributeMapperBase.class);
28

    
29

    
30
//******************************* ATTRIBUTES ***************************************/
31

    
32
	protected List<SINGLE_MAPPER> singleMappers = new ArrayList<>();
33

    
34
//********************************* CONSTRUCTOR ****************************************/
35

    
36
	public MultipleAttributeMapperBase() {
37
		singleMappers = new ArrayList<SINGLE_MAPPER>();
38
	}
39

    
40
//************************************ METHODS *******************************************/
41

    
42
	@Override
43
	public List<String> getDestinationAttributeList() {
44
		List<String> result = new ArrayList<>();
45
		for (SINGLE_MAPPER singleMapper : singleMappers){
46
			result.addAll(singleMapper.getDestinationAttributeList());
47
		}
48
		return result;
49
	}
50

    
51
	@Override
52
	public Set<String> getDestinationAttributes() {
53
		Set<String> result = new HashSet<>();
54
		result.addAll(getDestinationAttributeList());
55
		return result;
56
	}
57

    
58
	@Override
59
	public List<String> getSourceAttributeList() {
60
		List<String> result = new ArrayList<>();
61
		for (SINGLE_MAPPER singleMapper : singleMappers){
62
			result.addAll(singleMapper.getSourceAttributeList());
63
		}
64
		return result;
65
	}
66

    
67
	@Override
68
	public Set<String> getSourceAttributes() {
69
		Set<String> result = new HashSet<>();
70
		result.addAll(getSourceAttributeList());
71
		return result;
72
	}
73

    
74
    /**
75
	 * Returns the value of a result set attribute in its String representation.
76
	 * Better move this to a subclass for DbImportMappers (does not exist yet)
77
	 */
78
	protected String getStringDbValue(ResultSet rs, String attribute) throws SQLException {
79
		if (StringUtils.isBlank(attribute)){
80
			return null;
81
		}
82
		Object oId = rs.getObject(attribute);
83
		if (oId == null){
84
			return null;
85
		}
86
		String id = String.valueOf(oId);
87
		return id;
88
	}
89
}
(52-52/53)