Project

General

Profile

« Previous | Next » 

Revision f905a388

Added by Andreas Müller almost 2 years ago

cleanup

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/mapping/DbIgnoreMapper.java
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;import org.apache.logging.log4j.Logger;
16

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

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

  
30
    private static final Logger logger = LogManager.getLogger(DbIgnoreMapper.class);
31

  
32
//*************************** FACTORY ***************************************************************//
33

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

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

  
42
//*************************** VARIABLES ***************************************************************//
43

  
44
	private String ignoreReason;
45

  
46
//*************************** CONSTRUCTOR ***************************************************************//
47

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

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

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

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

Also available in: Unified diff