1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.io.berlinModel.out.mapper;
|
12
|
|
13
|
import java.sql.PreparedStatement;
|
14
|
import java.sql.SQLException;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
|
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;
|
24
|
|
25
|
/**
|
26
|
* @author a.mueller
|
27
|
* @created 12.05.2009
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class CreatedAndNotesMapper extends MultipleAttributeMapperBase<DbSingleAttributeExportMapperBase<DbExportState<?>>> implements IDbExportMapper<DbExportState<?>>{
|
31
|
@SuppressWarnings("unused")
|
32
|
private static final Logger logger = Logger.getLogger(CreatedAndNotesMapper.class);
|
33
|
|
34
|
public static CreatedAndNotesMapper NewInstance(){
|
35
|
return new CreatedAndNotesMapper(true);
|
36
|
}
|
37
|
|
38
|
public static CreatedAndNotesMapper NewInstance(boolean withUpdate){
|
39
|
return new CreatedAndNotesMapper(withUpdate);
|
40
|
}
|
41
|
|
42
|
|
43
|
/**
|
44
|
* @param dbAttributString
|
45
|
* @param cdmAttributeString
|
46
|
*/
|
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));
|
51
|
if (withUpdate){
|
52
|
singleMappers.add(DbStringMapper.NewInstance("updatedBy", "Updated_Who"));
|
53
|
singleMappers.add(DbDateMapper.NewInstance("updated", "Updated_When"));
|
54
|
}
|
55
|
}
|
56
|
|
57
|
|
58
|
/* (non-Javadoc)
|
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)
|
60
|
*/
|
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);
|
64
|
}
|
65
|
}
|
66
|
|
67
|
|
68
|
/* (non-Javadoc)
|
69
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.IDbExportMapper#invoke(eu.etaxonomy.cdm.model.common.CdmBase)
|
70
|
*/
|
71
|
public boolean invoke(CdmBase cdmBase) throws SQLException {
|
72
|
boolean result = true;
|
73
|
for (DbSingleAttributeExportMapperBase<DbExportState<?>> mapper : singleMappers){
|
74
|
result &= mapper.invoke(cdmBase);
|
75
|
}
|
76
|
return result;
|
77
|
}
|
78
|
|
79
|
//used by MethodMapper
|
80
|
@SuppressWarnings("unused")
|
81
|
private static String getNotes(AnnotatableEntity obj){
|
82
|
String result = "";
|
83
|
String separator = ";";
|
84
|
for (Annotation annotation :obj.getAnnotations()){
|
85
|
result = CdmUtils.concat(separator, result, annotation.getText());
|
86
|
}
|
87
|
return (result.trim().equals("")? null : result);
|
88
|
}
|
89
|
|
90
|
}
|