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.Connection;
|
14
|
import java.sql.PreparedStatement;
|
15
|
import java.sql.SQLException;
|
16
|
import java.util.Date;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.hsqldb.Types;
|
20
|
|
21
|
import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportConfigurator;
|
22
|
import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportState;
|
23
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
24
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
25
|
import eu.etaxonomy.cdm.model.description.Feature;
|
26
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
27
|
|
28
|
/**
|
29
|
* @author a.mueller
|
30
|
* @created 12.05.2009
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public class FactCategoryMapper extends DbSingleAttributeExportMapperBase<BerlinModelExportState<?>> implements IDbExportMapper<BerlinModelExportState<?>>{
|
34
|
@SuppressWarnings("unused")
|
35
|
private static final Logger logger = Logger.getLogger(FactCategoryMapper.class);
|
36
|
|
37
|
private PreparedStatement preparedStatement;
|
38
|
|
39
|
public static FactCategoryMapper NewInstance(String cdmAttributeString, String dbAttributeString){
|
40
|
return new FactCategoryMapper(cdmAttributeString, dbAttributeString);
|
41
|
}
|
42
|
|
43
|
// public static RefDetailMapper NewInstance(String cdmAttributeString, String dbAttributeString){
|
44
|
// return new RefDetailMapper();
|
45
|
// }
|
46
|
|
47
|
|
48
|
/**
|
49
|
* @param dbAttributString
|
50
|
* @param cdmAttributeString
|
51
|
*/
|
52
|
private FactCategoryMapper(String cdmAttributeString, String dbAttributeString) {
|
53
|
super(cdmAttributeString, dbAttributeString, null);
|
54
|
}
|
55
|
|
56
|
|
57
|
|
58
|
/* (non-Javadoc)
|
59
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#initialize(java.sql.PreparedStatement, eu.etaxonomy.cdm.io.berlinModel.out.mapper.IndexCounter, eu.etaxonomy.cdm.io.berlinModel.out.DbExportState)
|
60
|
*/
|
61
|
@Override
|
62
|
public void initialize(PreparedStatement stmt, IndexCounter index,BerlinModelExportState<?> state, String tableName) {
|
63
|
super.initialize(stmt, index, state, tableName);
|
64
|
String inRefSql = "INSERT INTO FactCategory (FactCategoryId, FactCategory , " +
|
65
|
" MaxFactNumber , RankRestrictionFk" +
|
66
|
" VALUES (?,?,?,?)";
|
67
|
Connection con = getState().getConfig().getDestination().getConnection();
|
68
|
try {
|
69
|
preparedStatement = con.prepareStatement(inRefSql);
|
70
|
} catch (SQLException e) {
|
71
|
e.printStackTrace();
|
72
|
throw new RuntimeException();
|
73
|
}
|
74
|
}
|
75
|
|
76
|
/* (non-Javadoc)
|
77
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue()
|
78
|
*/
|
79
|
@Override
|
80
|
protected Object getValue(CdmBase cdmBase) {
|
81
|
String value = (String)super.getValue(cdmBase);
|
82
|
boolean isBoolean = false;
|
83
|
Feature feature = (Feature)ImportHelper.getValue(cdmBase, getSourceAttribute(), isBoolean, true);
|
84
|
Object result = makeRow(feature);
|
85
|
// getState().getConfig().getCdmAppController().commitTransaction(tx);
|
86
|
return result;
|
87
|
}
|
88
|
|
89
|
|
90
|
protected Integer makeRow(Feature feature){
|
91
|
if (feature == null){
|
92
|
return null;
|
93
|
}
|
94
|
Integer factCategoryId = getState().getNextFactCategoryId();
|
95
|
String factCategory = feature.getLabel();
|
96
|
Integer maxFactNumber = null;
|
97
|
Integer RankRestrictionFk = null;
|
98
|
|
99
|
try {
|
100
|
preparedStatement.setInt(1, factCategoryId);
|
101
|
preparedStatement.setString(2, factCategory);
|
102
|
preparedStatement.setNull(3, Types.INTEGER) ;//.setString(3, maxFactNumber);
|
103
|
preparedStatement.setNull(4, Types.INTEGER) ;//.setString(4, RankRestrictionFk);
|
104
|
preparedStatement.executeUpdate();
|
105
|
} catch (SQLException e) {
|
106
|
// TODO Auto-generated catch block
|
107
|
e.printStackTrace();
|
108
|
}
|
109
|
return factCategoryId;
|
110
|
}
|
111
|
|
112
|
protected Integer getId(CdmBase cdmBase){
|
113
|
BerlinModelExportConfigurator config = getState().getConfig();
|
114
|
if (false && config.getIdType() == BerlinModelExportConfigurator.IdType.CDM_ID){
|
115
|
return cdmBase.getId();
|
116
|
}else{
|
117
|
Integer id = getState().getDbId(cdmBase);
|
118
|
return id;
|
119
|
}
|
120
|
}
|
121
|
|
122
|
/* (non-Javadoc)
|
123
|
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValueType()
|
124
|
*/
|
125
|
@Override
|
126
|
protected int getSqlType() {
|
127
|
return Types.INTEGER;
|
128
|
}
|
129
|
|
130
|
/* (non-Javadoc)
|
131
|
* @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass()
|
132
|
*/
|
133
|
@Override
|
134
|
public Class<?> getTypeClass() {
|
135
|
return String.class;
|
136
|
}
|
137
|
|
138
|
|
139
|
|
140
|
|
141
|
}
|