Project

General

Profile

Download (2.31 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

    
14
import org.apache.commons.lang3.StringUtils;
15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17

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

    
21
/**
22
 * This mapper does not change any import object, but keeps the information that a database
23
 * attribute does not need to be mapped.
24
 *
25
 * @author a.mueller
26
 * @since 25.02.2010
27
 */
28
public class DbIgnoreMapper
29
        extends DbSingleAttributeImportMapperBase<DbImportStateBase<?,?>, CdmBase> {
30

    
31
    private static final Logger logger = LogManager.getLogger();
32

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

    
35
	public static DbIgnoreMapper NewInstance(String dbAttributeToIgnore){
36
		return new DbIgnoreMapper(dbAttributeToIgnore, null, null, null);
37
	}
38

    
39
	public static DbIgnoreMapper NewInstance(String dbAttributeToIgnore, String ignoreReason){
40
		return new DbIgnoreMapper(dbAttributeToIgnore, null, null, ignoreReason);
41
	}
42

    
43
//*************************** VARIABLES ***************************************************************//
44

    
45
	private String ignoreReason;
46

    
47
//*************************** CONSTRUCTOR ***************************************************************//
48

    
49
	protected DbIgnoreMapper(String dbAttributString, String cdmAttributeString, Object defaultValue, String ignoreReason) {
50
		super(dbAttributString, cdmAttributeString, defaultValue);
51
		this.ignoreReason = ignoreReason;
52
	}
53

    
54
	@Override
55
	public CdmBase invoke(ResultSet rs, CdmBase cdmBase) throws SQLException {
56
		return cdmBase; //do nothing
57
	}
58

    
59
	@Override
60
	public Class getTypeClass() {
61
		return null;  //not needed
62
	}
63

    
64
	@Override
65
	public void initialize(DbImportStateBase<?,?> state, Class<? extends CdmBase> destinationClass) {
66
		String localIgnoreReason = "";
67
		if (StringUtils.isNotBlank(ignoreReason)){
68
			localIgnoreReason = "(" + ignoreReason +")";
69
	}
70
		logger.warn(this.getSourceAttribute() +  " ignored" +  localIgnoreReason);
71
	}
72
}
(5-5/53)