Project

General

Profile

Download (3.02 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.out;
11

    
12
import java.sql.PreparedStatement;
13
import java.sql.SQLException;
14

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

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

    
21
/**
22
 * This mapper does not change any import object, but logs the information that a database
23
 * attribute is ignored for the mapping.
24
 *
25
 * @see DbNullMapper
26
 *
27
 * @author a.mueller
28
 * @since 25.02.2010
29
 */
30
public class DbExportIgnoreMapper
31
            extends DbSingleAttributeExportMapperBase<DbExportStateBase<?, IExportTransformer>> {
32

    
33
    private static final Logger logger = LogManager.getLogger(DbExportIgnoreMapper.class);
34

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

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

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

    
45
	protected String ignoreReason;
46
	protected String dbAttributeString;
47

    
48
//*************************** CONSTRUCTOR ***************************************************************//
49

    
50
	protected DbExportIgnoreMapper(String cdmAttributeString, String dbAttributeString, Object defaultValue, String ignoreReason) {
51
		super(cdmAttributeString, null, defaultValue);
52
		//we do not pass to parent, otherwise this is part of the prepared statement
53
		//once we check if all fields of a table are mapped this behavior needs to be changed
54
		//or at least the checking mechanism needs to know that this attribute is handled (but ignored)
55
		this.dbAttributeString = dbAttributeString;
56
		this.ignoreReason = ignoreReason;
57
	}
58

    
59
	@Override
60
	public void initialize(PreparedStatement stmt, IndexCounter index, DbExportStateBase state, String tableName) {
61
		initializeLogging();
62
		exportMapperHelper.initializeNull(stmt, state, tableName);
63
	}
64

    
65
    protected void initializeLogging() {
66
        String attributeName = dbAttributeString; //this.getDestinationAttribute();
67
        String localReason = "";
68
        if (StringUtils.isNotBlank(ignoreReason)){
69
            localReason = " (" + ignoreReason +")";
70
        }
71
        logger.warn(attributeName + " ignored" +  localReason + ".");
72
    }
73

    
74
    @Override
75
	protected boolean doInvoke(CdmBase cdmBase) throws SQLException {
76
		return true;   // do nothing
77
	}
78

    
79
	@Override
80
	public Class getTypeClass() {
81
		return null;  //not needed
82
	}
83

    
84
	@Override
85
	protected int getSqlType() {
86
		return -1;  // not needed
87
	}
88
}
(13-13/44)