3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.cdm
.io
.common
.mapping
;
13 import java
.sql
.ResultSet
;
14 import java
.sql
.SQLException
;
16 import org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
19 import eu
.etaxonomy
.cdm
.io
.common
.DbImportStateBase
;
20 import eu
.etaxonomy
.cdm
.model
.common
.DescriptionElementSource
;
21 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
22 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
25 * This mapper creates an description element source that is added to the according description element.
26 * It adds the reference and the microReference.
31 public class DbImportDescriptionElementSourceCreationMapper
extends DbImportObjectCreationMapperBase
<DescriptionElementSource
, DbImportStateBase
<?
,?
>> {
32 @SuppressWarnings("unused")
33 private static final Logger logger
= Logger
.getLogger(DbImportDescriptionElementSourceCreationMapper
.class);
35 //**************************** FACTORY METHOD ***********************************************/
38 * Returns an description element source creation mapper.
39 * @param dbDescriptionElementFkAttribute
40 * @param descriptionElementNamespace
41 * @param dbReferenceFkAttribute
42 * @param referenceNamespace
45 public static DbImportDescriptionElementSourceCreationMapper
NewInstance(String dbDescriptionElementFkAttribute
, String descriptionElementNamespace
, String dbReferenceFkAttribute
, String referenceNamespace
){
46 String dbMicroReferenceAttribute
= null;
47 return new DbImportDescriptionElementSourceCreationMapper(dbDescriptionElementFkAttribute
, descriptionElementNamespace
, dbReferenceFkAttribute
, referenceNamespace
, dbMicroReferenceAttribute
);
52 * Returns an description element source creation mapper.
53 * @param dbDescriptionElementFkAttribute
54 * @param descriptionElementNamespace
55 * @param dbReferenceFkAttribute
56 * @param referenceNamespace
57 * @param dbMicroReferenceAttribute
60 public static DbImportDescriptionElementSourceCreationMapper
NewInstance(String dbDescriptionElementFkAttribute
, String descriptionElementNamespace
, String dbReferenceFkAttribute
, String referenceNamespace
, String dbMicroReferenceAttribute
){
61 return new DbImportDescriptionElementSourceCreationMapper(dbDescriptionElementFkAttribute
, descriptionElementNamespace
, dbReferenceFkAttribute
, referenceNamespace
, dbMicroReferenceAttribute
);
65 //******************************* VARIABLES ***********************************************/
67 protected String descriptionElementNamespace
;
68 protected String dbDescriptionElementFkAttribute
;
69 protected String referenceNamespace
;
70 protected String dbReferenceFkAttribute
;
71 protected String dbMicroReferenceAttribute
;
74 //******************************* CONSTRUCTOR ***********************************************/
77 * @param dbIdAttribute
78 * @param objectToCreateNamespace
80 protected DbImportDescriptionElementSourceCreationMapper(String dbDescriptionElementFkAttribute
, String descriptionElementNamespace
, String dbReferenceFkAttribute
, String referenceNamespace
, String dbMicroReferenceAttribute
) {
81 super(null, null); // idAttribute and objectToCreateNamespace not needed
82 this.descriptionElementNamespace
= descriptionElementNamespace
;
83 this.dbDescriptionElementFkAttribute
= dbDescriptionElementFkAttribute
;
84 this.dbReferenceFkAttribute
= dbReferenceFkAttribute
;
85 this.referenceNamespace
= referenceNamespace
;
86 this.dbMicroReferenceAttribute
= dbMicroReferenceAttribute
;
89 //******************************* METHODS ***********************************************/
92 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#createObject(java.sql.ResultSet)
95 protected DescriptionElementSource
createObject(ResultSet rs
)throws SQLException
{
96 DescriptionElementSource source
= DescriptionElementSource
.NewInstance();
101 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#doInvoke(java.sql.ResultSet, eu.etaxonomy.cdm.model.common.VersionableEntity)
104 protected DescriptionElementSource
doInvoke(ResultSet rs
, DescriptionElementSource source
) throws SQLException
{
105 addCitation(rs
, source
);
106 addMicroCitation(rs
, source
);
107 setDescriptionElement(rs
, source
);
114 * @throws SQLException
116 private void setDescriptionElement(ResultSet rs
,
117 DescriptionElementSource source
) throws SQLException
{
118 DescriptionElementBase descriptionElement
= (DescriptionElementBase
)getRelatedObject(rs
, descriptionElementNamespace
, dbDescriptionElementFkAttribute
);
119 source
.setSourcedObj(descriptionElement
);
125 * @throws SQLException
127 private void addMicroCitation(ResultSet rs
, DescriptionElementSource source
) throws SQLException
{
128 String microReference
= null;
129 if (CdmUtils
.isNotEmpty(dbMicroReferenceAttribute
)){
130 microReference
= rs
.getString(dbMicroReferenceAttribute
);
132 source
.setCitationMicroReference(microReference
);
138 * @throws SQLException
140 private void addCitation(ResultSet rs
, DescriptionElementSource source
) throws SQLException
{
141 ReferenceBase citation
= (ReferenceBase
)getRelatedObject(rs
, referenceNamespace
, dbReferenceFkAttribute
);
142 source
.setCitation(citation
);