Revision 8e7b7068
Added by Andreas Müller over 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/out/mapper/FactCategoryMapper.java | ||
---|---|---|
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 |
import org.hsqldb.Types; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportConfigurator; |
|
20 |
import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportState; |
|
21 |
import eu.etaxonomy.cdm.io.common.ImportHelper; |
|
22 |
import eu.etaxonomy.cdm.io.common.mapping.out.CdmDbExportMapping; |
|
23 |
import eu.etaxonomy.cdm.io.common.mapping.out.CreatedAndNotesMapper; |
|
24 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbObjectMapper; |
|
25 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbSingleAttributeExportMapperBase; |
|
26 |
import eu.etaxonomy.cdm.io.common.mapping.out.IDbExportMapper; |
|
27 |
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer; |
|
28 |
import eu.etaxonomy.cdm.io.common.mapping.out.IndexCounter; |
|
29 |
import eu.etaxonomy.cdm.io.common.mapping.out.MethodMapper; |
|
30 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
31 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
32 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus; |
|
33 |
|
|
34 |
/** |
|
35 |
* @author a.mueller |
|
36 |
* @created 12.05.2009 |
|
37 |
* @version 1.0 |
|
38 |
*/ |
|
39 |
public class FactCategoryMapper extends DbSingleAttributeExportMapperBase<BerlinModelExportState> implements IDbExportMapper<BerlinModelExportState, IExportTransformer>{ |
|
40 |
@SuppressWarnings("unused") |
|
41 |
private static final Logger logger = Logger.getLogger(FactCategoryMapper.class); |
|
42 |
|
|
43 |
private PreparedStatement preparedStatement; |
|
44 |
private CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = null; |
|
45 |
private String dbTableName = "NomStatusRel"; |
|
46 |
// protected BerlinModelExportState<?> state; |
|
47 |
|
|
48 |
public static FactCategoryMapper NewInstance(String cdmAttributeString, String dbAttributeString){ |
|
49 |
return new FactCategoryMapper(cdmAttributeString, dbAttributeString); |
|
50 |
} |
|
51 |
|
|
52 |
private CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> getMapping(){ |
|
53 |
String tableName = dbTableName; |
|
54 |
CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = new CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer>(tableName); |
|
55 |
|
|
56 |
mapping.addMapper(MethodMapper.NewInstance("NomStatusFk", this.getClass(), "getNomStatusFk", NomenclaturalStatus.class)); |
|
57 |
mapping.addMapper(DbObjectMapper.NewInstance("citation", "NomStatusRefFk")); |
|
58 |
mapping.addMapper(RefDetailMapper.NewInstance("citationMicroReference","citation", "NomStatusRefDetailFk")); |
|
59 |
|
|
60 |
mapping.addMapper(CreatedAndNotesMapper.NewInstance()); |
|
61 |
//TODO |
|
62 |
// DoubtfulFlag |
|
63 |
|
|
64 |
return mapping; |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
// public static RefDetailMapper NewInstance(String cdmAttributeString, String dbAttributeString){ |
|
69 |
// return new RefDetailMapper(); |
|
70 |
// } |
|
71 |
|
|
72 |
|
|
73 |
/** |
|
74 |
* @param dbAttributString |
|
75 |
* @param cdmAttributeString |
|
76 |
*/ |
|
77 |
private FactCategoryMapper(String cdmAttributeString, String dbAttributeString) { |
|
78 |
super(cdmAttributeString, dbAttributeString, null); |
|
79 |
} |
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
/* (non-Javadoc) |
|
84 |
* @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) |
|
85 |
*/ |
|
86 |
@Override |
|
87 |
public void initialize(PreparedStatement stmt, IndexCounter index,BerlinModelExportState state, String tableName) { |
|
88 |
super.initialize(stmt, index, state, tableName); |
|
89 |
mapping = getMapping(); |
|
90 |
|
|
91 |
// String inRefSql = "INSERT INTO FactCategory (FactCategoryId, FactCategory , " + |
|
92 |
// " MaxFactNumber , RankRestrictionFk" + |
|
93 |
// " VALUES (?,?,?,?)"; |
|
94 |
// Connection con = getState().getConfig().getDestination().getConnection(); |
|
95 |
try { |
|
96 |
mapping.initialize(state); |
|
97 |
mapping.initialize(state); |
|
98 |
// preparedStatement = con.prepareStatement(inRefSql); |
|
99 |
} catch (SQLException e) { |
|
100 |
e.printStackTrace(); |
|
101 |
throw new RuntimeException(); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
/* (non-Javadoc) |
|
106 |
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue() |
|
107 |
*/ |
|
108 |
//@Override |
|
109 |
public Object invoke(CdmBase cdmBase, boolean xxx) { |
|
110 |
String value = (String)super.getValue(cdmBase); |
|
111 |
boolean isBoolean = false; |
|
112 |
Feature feature = (Feature)ImportHelper.getValue(cdmBase, getSourceAttribute(), isBoolean, true); |
|
113 |
Object result = makeRow(feature); |
|
114 |
// getState().getConfig().getCdmAppController().commitTransaction(tx); |
|
115 |
return result; |
|
116 |
} |
|
117 |
|
|
118 |
/* (non-Javadoc) |
|
119 |
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue() |
|
120 |
*/ |
|
121 |
@Override |
|
122 |
protected Object getValue(CdmBase cdmBase) { |
|
123 |
String value = (String)super.getValue(cdmBase); |
|
124 |
boolean isBoolean = false; |
|
125 |
Feature feature = (Feature)ImportHelper.getValue(cdmBase, getSourceAttribute(), isBoolean, true); |
|
126 |
Object result = makeRow(feature); |
|
127 |
// getState().getConfig().getCdmAppController().commitTransaction(tx); |
|
128 |
return result; |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
protected Integer makeRow(Feature feature){ |
|
133 |
if (feature == null){ |
|
134 |
return null; |
|
135 |
} |
|
136 |
Integer factCategoryId = getState().getNextFactCategoryId(); |
|
137 |
String factCategory = feature.getLabel(); |
|
138 |
Integer maxFactNumber = null; |
|
139 |
Integer RankRestrictionFk = null; |
|
140 |
|
|
141 |
try { |
|
142 |
preparedStatement.setInt(1, factCategoryId); |
|
143 |
preparedStatement.setString(2, factCategory); |
|
144 |
preparedStatement.setNull(3, Types.INTEGER) ;//.setString(3, maxFactNumber); |
|
145 |
preparedStatement.setNull(4, Types.INTEGER) ;//.setString(4, RankRestrictionFk); |
|
146 |
preparedStatement.executeUpdate(); |
|
147 |
} catch (SQLException e) { |
|
148 |
// TODO Auto-generated catch block |
|
149 |
e.printStackTrace(); |
|
150 |
} |
|
151 |
return factCategoryId; |
|
152 |
} |
|
153 |
|
|
154 |
protected Integer getId(CdmBase cdmBase){ |
|
155 |
BerlinModelExportConfigurator config = getState().getConfig(); |
|
156 |
if (false && config.getIdType() == BerlinModelExportConfigurator.IdType.CDM_ID){ |
|
157 |
return cdmBase.getId(); |
|
158 |
}else{ |
|
159 |
Integer id = getState().getDbId(cdmBase); |
|
160 |
return id; |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
/* (non-Javadoc) |
|
165 |
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValueType() |
|
166 |
*/ |
|
167 |
@Override |
|
168 |
protected int getSqlType() { |
|
169 |
return Types.INTEGER; |
|
170 |
} |
|
171 |
|
|
172 |
/* (non-Javadoc) |
|
173 |
* @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass() |
|
174 |
*/ |
|
175 |
@Override |
|
176 |
public Class<?> getTypeClass() { |
|
177 |
return String.class; |
|
178 |
} |
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
} |
|
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 |
import java.sql.Types; |
|
16 |
|
|
17 |
import org.apache.log4j.Logger; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportConfigurator; |
|
20 |
import eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportState; |
|
21 |
import eu.etaxonomy.cdm.io.common.ImportHelper; |
|
22 |
import eu.etaxonomy.cdm.io.common.mapping.out.CdmDbExportMapping; |
|
23 |
import eu.etaxonomy.cdm.io.common.mapping.out.CreatedAndNotesMapper; |
|
24 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbObjectMapper; |
|
25 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbSingleAttributeExportMapperBase; |
|
26 |
import eu.etaxonomy.cdm.io.common.mapping.out.IDbExportMapper; |
|
27 |
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer; |
|
28 |
import eu.etaxonomy.cdm.io.common.mapping.out.IndexCounter; |
|
29 |
import eu.etaxonomy.cdm.io.common.mapping.out.MethodMapper; |
|
30 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
31 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
32 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus; |
|
33 |
|
|
34 |
/** |
|
35 |
* @author a.mueller |
|
36 |
* @created 12.05.2009 |
|
37 |
* @version 1.0 |
|
38 |
*/ |
|
39 |
public class FactCategoryMapper extends DbSingleAttributeExportMapperBase<BerlinModelExportState> implements IDbExportMapper<BerlinModelExportState, IExportTransformer>{ |
|
40 |
@SuppressWarnings("unused") |
|
41 |
private static final Logger logger = Logger.getLogger(FactCategoryMapper.class); |
|
42 |
|
|
43 |
private PreparedStatement preparedStatement; |
|
44 |
private CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = null; |
|
45 |
private final String dbTableName = "NomStatusRel"; |
|
46 |
// protected BerlinModelExportState<?> state; |
|
47 |
|
|
48 |
public static FactCategoryMapper NewInstance(String cdmAttributeString, String dbAttributeString){ |
|
49 |
return new FactCategoryMapper(cdmAttributeString, dbAttributeString); |
|
50 |
} |
|
51 |
|
|
52 |
private CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> getMapping(){ |
|
53 |
String tableName = dbTableName; |
|
54 |
CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = new CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer>(tableName); |
|
55 |
|
|
56 |
mapping.addMapper(MethodMapper.NewInstance("NomStatusFk", this.getClass(), "getNomStatusFk", NomenclaturalStatus.class)); |
|
57 |
mapping.addMapper(DbObjectMapper.NewInstance("citation", "NomStatusRefFk")); |
|
58 |
mapping.addMapper(RefDetailMapper.NewInstance("citationMicroReference","citation", "NomStatusRefDetailFk")); |
|
59 |
|
|
60 |
mapping.addMapper(CreatedAndNotesMapper.NewInstance()); |
|
61 |
//TODO |
|
62 |
// DoubtfulFlag |
|
63 |
|
|
64 |
return mapping; |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
// public static RefDetailMapper NewInstance(String cdmAttributeString, String dbAttributeString){ |
|
69 |
// return new RefDetailMapper(); |
|
70 |
// } |
|
71 |
|
|
72 |
|
|
73 |
/** |
|
74 |
* @param dbAttributString |
|
75 |
* @param cdmAttributeString |
|
76 |
*/ |
|
77 |
private FactCategoryMapper(String cdmAttributeString, String dbAttributeString) { |
|
78 |
super(cdmAttributeString, dbAttributeString, null); |
|
79 |
} |
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
/* (non-Javadoc) |
|
84 |
* @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) |
|
85 |
*/ |
|
86 |
@Override |
|
87 |
public void initialize(PreparedStatement stmt, IndexCounter index,BerlinModelExportState state, String tableName) { |
|
88 |
super.initialize(stmt, index, state, tableName); |
|
89 |
mapping = getMapping(); |
|
90 |
|
|
91 |
// String inRefSql = "INSERT INTO FactCategory (FactCategoryId, FactCategory , " + |
|
92 |
// " MaxFactNumber , RankRestrictionFk" + |
|
93 |
// " VALUES (?,?,?,?)"; |
|
94 |
// Connection con = getState().getConfig().getDestination().getConnection(); |
|
95 |
try { |
|
96 |
mapping.initialize(state); |
|
97 |
mapping.initialize(state); |
|
98 |
// preparedStatement = con.prepareStatement(inRefSql); |
|
99 |
} catch (SQLException e) { |
|
100 |
e.printStackTrace(); |
|
101 |
throw new RuntimeException(); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
/* (non-Javadoc) |
|
106 |
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue() |
|
107 |
*/ |
|
108 |
//@Override |
|
109 |
public Object invoke(CdmBase cdmBase, boolean xxx) { |
|
110 |
String value = (String)super.getValue(cdmBase); |
|
111 |
boolean isBoolean = false; |
|
112 |
Feature feature = (Feature)ImportHelper.getValue(cdmBase, getSourceAttribute(), isBoolean, true); |
|
113 |
Object result = makeRow(feature); |
|
114 |
// getState().getConfig().getCdmAppController().commitTransaction(tx); |
|
115 |
return result; |
|
116 |
} |
|
117 |
|
|
118 |
/* (non-Javadoc) |
|
119 |
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue() |
|
120 |
*/ |
|
121 |
@Override |
|
122 |
protected Object getValue(CdmBase cdmBase) { |
|
123 |
String value = (String)super.getValue(cdmBase); |
|
124 |
boolean isBoolean = false; |
|
125 |
Feature feature = (Feature)ImportHelper.getValue(cdmBase, getSourceAttribute(), isBoolean, true); |
|
126 |
Object result = makeRow(feature); |
|
127 |
// getState().getConfig().getCdmAppController().commitTransaction(tx); |
|
128 |
return result; |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
protected Integer makeRow(Feature feature){ |
|
133 |
if (feature == null){ |
|
134 |
return null; |
|
135 |
} |
|
136 |
Integer factCategoryId = getState().getNextFactCategoryId(); |
|
137 |
String factCategory = feature.getLabel(); |
|
138 |
Integer maxFactNumber = null; |
|
139 |
Integer RankRestrictionFk = null; |
|
140 |
|
|
141 |
try { |
|
142 |
preparedStatement.setInt(1, factCategoryId); |
|
143 |
preparedStatement.setString(2, factCategory); |
|
144 |
preparedStatement.setNull(3, Types.INTEGER) ;//.setString(3, maxFactNumber); |
|
145 |
preparedStatement.setNull(4, Types.INTEGER) ;//.setString(4, RankRestrictionFk); |
|
146 |
preparedStatement.executeUpdate(); |
|
147 |
} catch (SQLException e) { |
|
148 |
// TODO Auto-generated catch block |
|
149 |
e.printStackTrace(); |
|
150 |
} |
|
151 |
return factCategoryId; |
|
152 |
} |
|
153 |
|
|
154 |
protected Integer getId(CdmBase cdmBase){ |
|
155 |
BerlinModelExportConfigurator config = getState().getConfig(); |
|
156 |
if (false && config.getIdType() == BerlinModelExportConfigurator.IdType.CDM_ID){ |
|
157 |
return cdmBase.getId(); |
|
158 |
}else{ |
|
159 |
Integer id = getState().getDbId(cdmBase); |
|
160 |
return id; |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
/* (non-Javadoc) |
|
165 |
* @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValueType() |
|
166 |
*/ |
|
167 |
@Override |
|
168 |
protected int getSqlType() { |
|
169 |
return Types.INTEGER; |
|
170 |
} |
|
171 |
|
|
172 |
/* (non-Javadoc) |
|
173 |
* @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass() |
|
174 |
*/ |
|
175 |
@Override |
|
176 |
public Class<?> getTypeClass() { |
|
177 |
return String.class; |
|
178 |
} |
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
} |
Also available in: Unified diff
Minor cleanups in appimport