Project

General

Profile

Download (4.48 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
import java.util.UUID;
15

    
16
import org.apache.log4j.Logger;
17

    
18
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
19
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
20
import eu.etaxonomy.cdm.model.description.Feature;
21

    
22
/**
23
 * This class retrives or creates an existing or a new feature.
24
 *
25
 * @see DbImportDefinedTermCreationMapperBase
26
 * @author a.mueller
27
 * @since 11.03.2010
28
 */
29
public class DbImportFeatureCreationMapper<STATE extends DbImportStateBase<?,?>> extends DbImportDefinedTermCreationMapperBase<Feature, DescriptionElementBase, DbImportStateBase<?,?>> {
30
	@SuppressWarnings("unused")
31
	private static final Logger logger = Logger.getLogger(DbImportFeatureCreationMapper.class);
32

    
33
//******************************** FACTORY METHOD ***************************************************/
34

    
35

    
36
	/**
37
	 *
38
	 * @param dbIdAttribute
39
	 * @param dbTermAttribute
40
	 * @param dbLabelAttribute
41
	 * @param dbLabelAbbrevAttribute
42
	 * @return
43
	 */
44
	public static DbImportFeatureCreationMapper<?> NewInstance(String dbIdAttribute, String featureNamespace, String dbTermAttribute, String dbLabelAttribute, String dbLabelAbbrevAttribute){
45
		return new DbImportFeatureCreationMapper(dbIdAttribute, featureNamespace, dbTermAttribute, dbLabelAttribute, dbLabelAbbrevAttribute);
46
	}
47

    
48

    
49
//	/**
50
//	 * Creates a Distribution with status <code>status</code> and adds it to the description of a taxon.
51
//	 * @param dbIdAttribute
52
//	 * @param objectToCreateNamespace
53
//	 * @param dbTaxonFkAttribute
54
//	 * @param taxonNamespace
55
//	 * @param status
56
//	 * @return
57
//	 */
58
//	public static DbImportFeatureCreationMapper<?> NewInstance(String dbIdAttribute, String dbTermAttribute, String dbLabelAttribute, String dbLabelAbbrevAttribute){
59
//		return new DbImportFeatureCreationMapper(dbIdAttribute, objectToCreateNamespace, dbTaxonFkAttribute, taxonNamespace, dbTextAttribute, language, feature, format);
60
//	}
61

    
62
//******************************* ATTRIBUTES ***************************************/
63

    
64

    
65
//********************************* CONSTRUCTOR ****************************************/
66
	/**
67
	 * @param dbIdAttribute
68
	 * @param objectToCreateNamespace
69
	 * @param dbTaxonFkAttribute
70
	 * @param taxonNamespace
71
	 */
72
	protected DbImportFeatureCreationMapper(String dbIdAttribute, String featureNamespace, String dbTermAttribute, String dbLabelAttribute, String dbLabelAbbrevAttribute) {
73
		super(dbIdAttribute, featureNamespace, dbTermAttribute, dbLabelAttribute, dbLabelAbbrevAttribute);
74
	}
75

    
76
//************************************ METHODS *******************************************/
77

    
78
	@Override
79
	protected Feature getTermFromState(UUID uuid) {
80
		return getState().getFeature(uuid);
81
	}
82

    
83
	@Override
84
	protected Feature getTermFromTransformer(String key, IInputTransformer transformer) throws UndefinedTransformerMethodException {
85
		return transformer.getFeatureByKey(key);
86
	}
87

    
88
	@Override
89
	protected UUID getUuidFromTransformer(String key, IInputTransformer transformer) throws UndefinedTransformerMethodException {
90
		UUID uuid = transformer.getFeatureUuid(key);
91
		return uuid;
92
	}
93

    
94
	@Override
95
	protected void saveTermToState(Feature feature) {
96
		getState().putFeature(feature);
97

    
98
	}
99

    
100
//	@Override
101
//	protected Feature createObject(ResultSet rs) throws SQLException {
102
//		String term = this.getStringDbValue(rs, dbTermAttribute);
103
//		String label = this.getStringDbValue(rs, dbLabelAttribute);
104
//		String labelAbbrev = this.getStringDbValue(rs, dbLabelAbbrevAttribute);
105
//		if (term != null || label != null || labelAbbrev != null){
106
//			Feature feature = Feature.NewInstance(term, label, labelAbbrev);
107
//			return feature;
108
//		}else{
109
//			return null;
110
//		}
111
//	}
112

    
113
	@Override
114
	protected Feature createDefinedTerm(ResultSet rs) throws SQLException {
115
		String term = this.getStringDbValue(rs, dbTermAttribute);
116
		String label = this.getStringDbValue(rs, dbLabelAttribute);
117
		String labelAbbrev = this.getStringDbValue(rs, dbLabelAbbrevAttribute);
118
		if (term != null || label != null || labelAbbrev != null){
119
			Feature feature = Feature.NewInstance(term, label, labelAbbrev);
120
			return feature;
121
		}else{
122
			return null;
123
		}
124
	}
125

    
126
}
(16-16/51)