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
.berlinModel
.out
.mapper
;
13 import java
.sql
.PreparedStatement
;
14 import java
.sql
.SQLException
;
16 import org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
19 import eu
.etaxonomy
.cdm
.io
.berlinModel
.out
.DbExportState
;
20 import eu
.etaxonomy
.cdm
.io
.common
.MultipleAttributeMapperBase
;
21 import eu
.etaxonomy
.cdm
.model
.common
.AnnotatableEntity
;
22 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
23 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
30 public class CreatedAndNotesMapper
extends MultipleAttributeMapperBase
<DbSingleAttributeExportMapperBase
<DbExportState
<?
>>> implements IDbExportMapper
<DbExportState
<?
>>{
31 @SuppressWarnings("unused")
32 private static final Logger logger
= Logger
.getLogger(CreatedAndNotesMapper
.class);
34 public static CreatedAndNotesMapper
NewInstance(){
35 return new CreatedAndNotesMapper(true);
38 public static CreatedAndNotesMapper
NewInstance(boolean withUpdate
){
39 return new CreatedAndNotesMapper(withUpdate
);
44 * @param dbAttributString
45 * @param cdmAttributeString
47 private CreatedAndNotesMapper(boolean withUpdate
) {
48 singleMappers
.add(DbStringMapper
.NewInstance("createdBy", "Created_Who"));
49 singleMappers
.add(DbDateMapper
.NewInstance("created", "Created_When"));
50 singleMappers
.add(MethodMapper
.NewInstance("Notes", this.getClass(), "getNotes", AnnotatableEntity
.class));
52 singleMappers
.add(DbStringMapper
.NewInstance("updatedBy", "Updated_Who"));
53 singleMappers
.add(DbDateMapper
.NewInstance("updated", "Updated_When"));
59 * @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.IDbExportMapper#initialize(java.sql.PreparedStatement, eu.etaxonomy.cdm.io.berlinModel.out.mapper.IndexCounter, eu.etaxonomy.cdm.io.berlinModel.out.DbExportState)
61 public void initialize(PreparedStatement stmt
, IndexCounter index
, DbExportState
<?
> state
, String tableName
) {
62 for (DbSingleAttributeExportMapperBase
<DbExportState
<?
>> mapper
: singleMappers
){
63 mapper
.initialize(stmt
, index
, state
, tableName
);
69 * @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.IDbExportMapper#invoke(eu.etaxonomy.cdm.model.common.CdmBase)
71 public boolean invoke(CdmBase cdmBase
) throws SQLException
{
72 boolean result
= true;
73 for (DbSingleAttributeExportMapperBase
<DbExportState
<?
>> mapper
: singleMappers
){
74 result
&= mapper
.invoke(cdmBase
);
79 //used by MethodMapper
80 @SuppressWarnings("unused")
81 private static String
getNotes(AnnotatableEntity obj
){
83 String separator
= ";";
84 for (Annotation annotation
:obj
.getAnnotations()){
85 result
= CdmUtils
.concat(separator
, result
, annotation
.getText());
87 return (result
.trim().equals("")?
null : result
);