Project

General

Profile

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

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
18
import eu.etaxonomy.cdm.model.common.Extension;
19
import eu.etaxonomy.cdm.model.common.ExtensionType;
20
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
21

    
22

    
23
/**
24
 *  Object creation mapper which creates a extensions.
25
 *  
26
 * @author a.mueller
27
 * @since 11.03.2010
28
 * @version 1.0
29
 */
30
public class DbImportExtensionCreationMapper extends DbImportSupplementCreationMapperBase<Extension, IdentifiableEntity, DbImportStateBase<?, ?>, ExtensionType > {
31
	private static final Logger logger = Logger.getLogger(DbImportExtensionCreationMapper.class);
32

    
33
//************************** FACTORY METHODS ***************************************************************/
34
	
35
	
36
	/**
37
	 * Creates an extension mapper which creates an empty extension.
38
	 *
39
	 * @param dbExtendedObjectAttribute the database column that holds the foreign key for the extended object - obligatory
40
	 * @param extendedObjectNamespace the namespace under which the extended object has been saved previously - obligatory
41
	 * @return DbImportExtensionCreationMapper
42
	 */
43
	public static DbImportExtensionCreationMapper NewInstance(String dbExtendedObjectAttribute, String extendedObjectNamespace){
44
		return new DbImportExtensionCreationMapper(dbExtendedObjectAttribute, extendedObjectNamespace, null,  null, null);
45
	}
46
	
47
	/**
48
	 * Creates an extension mapper which creates an extension and sets the extension value,
49
	 * the extension type and adds an annotation holding the original source id
50
	 *
51
	 * @param dbExtendedObjectAttribute the database column that holds the foreign key for the extended object - obligatory
52
	 * @param extendedObjectNamespace the namespace under which the extended object has been saved previously - obligatory
53
	 * @param dbExtensionValueAttribute if null no extension value is set
54
	 * @param dbIdAttribute if null not original source id annotation is added
55
	 * @param extensionType if null no extension type is set
56
	 * @return DbImportExtensionCreationMapper
57
	 */
58
	public static DbImportExtensionCreationMapper NewInstance( String dbExtendedObjectAttribute, String extendedObjectNamespace, String dbExtensionValueAttribute,String dbIdAttribute, ExtensionType extensionType){
59
		return new DbImportExtensionCreationMapper(dbExtendedObjectAttribute, extendedObjectNamespace, dbExtensionValueAttribute, dbIdAttribute, extensionType);
60
	}
61

    
62
	
63
//********************************* CONSTRUCTOR ****************************************/
64

    
65
	protected DbImportExtensionCreationMapper(String dbSupplementedObjectAttribute, String supplementedObjectNamespace, String dbSupplementValueAttribute, String dbIdAttribute, ExtensionType supplementType) {
66
		super(dbSupplementValueAttribute, dbSupplementedObjectAttribute, dbIdAttribute, supplementedObjectNamespace, supplementType);
67
	}
68

    
69
//************************************ METHODS *******************************************/
70

    
71
	/* (non-Javadoc)
72
	 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportSupplementCreationMapperBase#addSupplement(eu.etaxonomy.cdm.model.common.AnnotatableEntity, java.lang.String, eu.etaxonomy.cdm.model.common.AnnotatableEntity)
73
	 */
74
	@Override
75
	protected boolean addSupplement(Extension extension, IdentifiableEntity identifiableEntity, String id) {
76
		if (identifiableEntity != null){
77
			identifiableEntity.addExtension(extension);
78
			return true;
79
		}else{
80
			String warning = "Identifiable entity (" + id + ") for extension not found. Extension not created.";
81
			logger.warn(warning);
82
			return false;
83
		}
84
	}
85

    
86
	/* (non-Javadoc)
87
	 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportSupplementCreationMapperBase#setSupplementValue(java.lang.Object)
88
	 */
89
	@Override
90
	protected void setSupplementValue(ResultSet rs, Extension extension) throws SQLException {
91
		String value = rs.getString(dbSupplementValueAttribute);
92
		extension.setValue(value);
93
		
94
	}
95

    
96
	/* (non-Javadoc)
97
	 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#createObject(java.sql.ResultSet)
98
	 */
99
	@Override
100
	protected Extension createObject(ResultSet rs) throws SQLException {
101
		Extension extension = Extension.NewInstance();
102
		extension.setType(this.supplementType);
103
		return extension;
104
	}
105

    
106
	
107
}
(13-13/51)