2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.common
.mapping
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.SQLException
;
15 import org
.apache
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
18 import eu
.etaxonomy
.cdm
.io
.common
.DbImportStateBase
;
19 import eu
.etaxonomy
.cdm
.model
.common
.AnnotatableEntity
;
20 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
21 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
22 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
23 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
24 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
31 public abstract class DbImportSupplementCreationMapperBase
<SUPPLEMENT
extends VersionableEntity
, SUPPLEMENTABLE
extends AnnotatableEntity
, STATE
extends DbImportStateBase
<?
,?
>, TYPE
extends DefinedTermBase
> extends DbImportObjectCreationMapperBase
<SUPPLEMENT
, STATE
> {
32 @SuppressWarnings("unused")
33 private static final Logger logger
= Logger
.getLogger(DbImportSupplementCreationMapperBase
.class);
36 //******************************* ATTRIBUTES ***************************************/
37 protected String dbSupplementValueAttribute
;
38 protected String dbSupplementedObjectAttribute
;
39 protected TYPE supplementType
;
40 protected boolean addOriginalSourceId
= false;
43 //********************************* CONSTRUCTOR ****************************************/
45 * @param mappingImport
47 protected DbImportSupplementCreationMapperBase(String dbSupplementValueAttribute
, String dbSupplementedObjectAttribute
, String dbIdAttribute
, String supplementedObjectNamespace
, TYPE supplementType
) {
48 super(dbIdAttribute
, supplementedObjectNamespace
);
49 this.dbSupplementValueAttribute
= dbSupplementValueAttribute
;
50 this.dbSupplementedObjectAttribute
= dbSupplementedObjectAttribute
;
51 this.supplementType
= supplementType
;
52 //FIXME make it a real Multiple attribute mapper
53 // this.singleMappers.add(DbImportAnnotationMapper.NewInstance(dbAnnotationAttribute, annotationType, language));
54 // String relatedObjectNamespace = "yyy";
55 // this.singleMappers.add(DbImportObjectMapper.NewInstance(dbAnnotatedObjectAttribute, "xxx",relatedObjectNamespace ));
58 //************************************ METHODS *******************************************/
61 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#doInvoke(java.sql.ResultSet, eu.etaxonomy.cdm.model.common.VersionableEntity)
64 protected SUPPLEMENT
doInvoke(ResultSet rs
, SUPPLEMENT supplement
) throws SQLException
{
65 //add object to supplementable object
66 String strId
= getStringDbValue(rs
, dbSupplementedObjectAttribute
);
67 SUPPLEMENTABLE supplementableEntity
= (SUPPLEMENTABLE
)getRelatedObject(objectToCreateNamespace
, strId
);
68 addSupplement(supplement
, supplementableEntity
, strId
);
71 if (CdmUtils
.isNotEmpty(dbSupplementValueAttribute
)){
72 setSupplementValue(rs
, supplement
);
83 protected abstract void setSupplementValue(ResultSet rs
, SUPPLEMENT supplement
) throws SQLException
;
86 * Adds the supplement to the supplementable entity. Returns falls if supplementable entity is
88 * @param supplement the supplement (e.g. an instance of class Extension)
89 * @param supplementableEntity the supplementable entity (e.g. an <code>IdentifiableEntity</code> in case of a
90 * supplement of type <code>Extension</code>
91 * @param id the supplementableEntity original source id (needed for verbose logging)
93 protected abstract boolean addSupplement(SUPPLEMENT supplement
, SUPPLEMENTABLE supplementableEntity
, String id
) ;
98 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#addOriginalSource(java.sql.ResultSet, eu.etaxonomy.cdm.model.common.VersionableEntity)
101 public void addOriginalSource(ResultSet rs
, SUPPLEMENT supplement
) throws SQLException
{
102 if (addOriginalSourceId
&& supplement
.isInstanceOf(AnnotatableEntity
.class)){
103 AnnotatableEntity annotatableEntity
= (AnnotatableEntity
)supplement
;
104 Language orginalSourceLanguage
= null;
105 AnnotationType annotationType
= AnnotationType
.TECHNICAL();
106 String originalId
= getStringDbValue(rs
, dbIdAttribute
);
107 Annotation idAnnotation
= Annotation
.NewInstance(originalId
, annotationType
, orginalSourceLanguage
);
108 annotatableEntity
.addAnnotation(idAnnotation
);