package eu.etaxonomy.cdm.io.berlinModel.out;\r
\r
import java.sql.SQLException;\r
+import java.sql.Types;\r
import java.util.List;\r
\r
import org.apache.log4j.Logger;\r
import org.springframework.stereotype.Component;\r
import org.springframework.transaction.TransactionStatus;\r
\r
-import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;\r
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.CreatedAndNotesMapper;\r
+import eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbConstantMapper;\r
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbObjectMapper;\r
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.MethodMapper;\r
import eu.etaxonomy.cdm.io.common.DbExportStateBase;\r
-import eu.etaxonomy.cdm.io.common.IExportConfigurator;\r
-import eu.etaxonomy.cdm.io.common.Source;\r
import eu.etaxonomy.cdm.model.common.CdmBase;\r
import eu.etaxonomy.cdm.model.common.RelationshipBase;\r
-import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;\r
+import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;\r
\r
\r
\r
private static int modCount = 1000;\r
private static final String dbTableName = "RelPTaxon";\r
- private static final String pluralString = "TaxonomicTrees";\r
- private static final Class<? extends CdmBase> standardMethodParameter = RelationshipBase.class;\r
+ private static final String pluralString = "TaxonNodes";\r
+ private static final Class<? extends CdmBase> standardMethodParameter = TaxonNode.class;\r
\r
\r
public BerlinModelTaxonomicTreeExport(){\r
mapping.addMapper(MethodMapper.NewInstance("PTNameFk2", this.getClass(), "getPTNameFk2", standardMethodParameter, DbExportStateBase.class));\r
mapping.addMapper(MethodMapper.NewInstance("PTRefFk2", this.getClass(), "getPTRefFk2", standardMethodParameter, DbExportStateBase.class));\r
\r
- mapping.addMapper(MethodMapper.NewInstance("RelQualifierFk", this));\r
+ mapping.addMapper(DbConstantMapper.NewInstance("RelQualifierFk", Types.INTEGER, 1));\r
\r
- mapping.addMapper(DbObjectMapper.NewInstance("citation", "RelRefFk"));\r
+ mapping.addMapper(DbObjectMapper.NewInstance("referenceForParentChildRelation", "RelRefFk"));\r
// mapping.addMapper(RefDetailMapper.NewInstance("citationMicroReference","citation", "FactRefDetailFk"));\r
mapping.addMapper(CreatedAndNotesMapper.NewInstance());\r
\r
}\r
\r
protected boolean doInvoke(BerlinModelExportState state){\r
+ if (state.getConfig().isUseTaxonomicTree() == false){\r
+ return true;\r
+ }\r
+ \r
try{\r
logger.info("start make " + pluralString + " ...");\r
boolean success = true ;\r
\r
int count = 0;\r
for (TaxonomicTree tree : list){\r
- if (true){\r
- doCount(count++, modCount, pluralString);\r
- success &= mapping.invoke(tree);\r
+ for (TaxonNode node : tree.getAllNodes()){\r
+ if (node.getParent() == null){\r
+ continue;\r
+ }else{\r
+ doCount(count++, modCount, pluralString);\r
+ success &= mapping.invoke(node);\r
+ }\r
}\r
}\r
commitTransaction(txStatus);\r
protected boolean doDelete(BerlinModelExportState state){\r
BerlinModelExportConfigurator bmeConfig = state.getConfig();\r
\r
- String sql;\r
- Source destination = bmeConfig.getDestination();\r
- //RelPTaxon\r
- sql = "DELETE FROM RelPTaxon";\r
- destination.setQuery(sql);\r
- destination.update(sql);\r
+ //already deleted in BerlinModelTaxonRelationExport\r
+// String sql;\r
+// Source destination = bmeConfig.getDestination();\r
+// //RelPTaxon\r
+// sql = "DELETE FROM RelPTaxon ";\r
+// destination.setQuery(sql);\r
+// destination.update(sql);\r
\r
return true;\r
}\r
}\r
\r
//called by MethodMapper\r
- @SuppressWarnings("unused")\r
- private static Integer getRelQualifierFk(RelationshipBase<?, ?, ?> rel){\r
- return BerlinModelTransformer.taxRelation2relPtQualifierFk(rel);\r
- }\r
\r
@SuppressWarnings("unused")\r
- private static Integer getPTNameFk1(RelationshipBase<?, ?, ?> rel, DbExportStateBase<?> state){\r
- return getObjectFk(rel, state, true, true);\r
+ private static Integer getPTNameFk1(TaxonNode node, DbExportStateBase<?> state){\r
+ return getObjectFk(node, state, true, true);\r
}\r
\r
@SuppressWarnings("unused")\r
- private static Integer getPTRefFk1(RelationshipBase<?, ?, ?> rel, DbExportStateBase<?> state){\r
- return getObjectFk(rel, state, false, true);\r
+ private static Integer getPTRefFk1(TaxonNode node, DbExportStateBase<?> state){\r
+ return getObjectFk(node, state, false, true);\r
}\r
\r
@SuppressWarnings("unused")\r
- private static Integer getPTNameFk2(RelationshipBase<?, ?, ?> rel, DbExportStateBase<?> state){\r
- return getObjectFk(rel, state, true, false);\r
+ private static Integer getPTNameFk2(TaxonNode node, DbExportStateBase<?> state){\r
+ return getObjectFk(node, state, true, false);\r
}\r
\r
@SuppressWarnings("unused")\r
- private static Integer getPTRefFk2(RelationshipBase<?, ?, ?> rel, DbExportStateBase<?> state){\r
- return getObjectFk(rel, state, false, false);\r
+ private static Integer getPTRefFk2(TaxonNode node, DbExportStateBase<?> state){\r
+ return getObjectFk(node, state, false, false);\r
}\r
\r
- private static Integer getObjectFk(RelationshipBase<?, ?, ?> rel, DbExportStateBase<?> state, boolean isName, boolean isFrom){\r
- TaxonBase<?> taxon = null;\r
- if (rel.isInstanceOf(TaxonRelationship.class)){\r
- TaxonRelationship tr = (TaxonRelationship)rel;\r
- taxon = (isFrom) ? tr.getFromTaxon(): tr.getToTaxon();\r
- }else if (rel.isInstanceOf(SynonymRelationship.class)){\r
- SynonymRelationship sr = (SynonymRelationship)rel;\r
- taxon = (isFrom) ? sr.getSynonym() : sr.getAcceptedTaxon();\r
- }\r
+ private static Integer getObjectFk(TaxonNode node, DbExportStateBase<?> state, boolean isName, boolean isFrom){\r
+ Taxon taxon = (isFrom) ? node.getTaxon(): node.getParent().getTaxon();\r
if (taxon != null){\r
CdmBase cdmBase = (isName) ? taxon.getName(): taxon.getSec();\r
return state.getDbId(cdmBase);\r
}\r
- logger.warn("No taxon found for relationship: " + rel.toString());\r
+ logger.warn("No taxon or parent taxon found for taxon node: " + node.toString());\r
return null;\r
}\r
\r
--- /dev/null
+// $Id$\r
+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy \r
+* http://www.e-taxonomy.eu\r
+* \r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+\r
+package eu.etaxonomy.cdm.io.berlinModel.out.mapper;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import eu.etaxonomy.cdm.io.common.DbExportStateBase;\r
+import eu.etaxonomy.cdm.model.common.CdmBase;\r
+\r
+/**\r
+ * @author a.mueller\r
+ * @created 12.05.2009\r
+ * @version 1.0\r
+ */\r
+public class DbConstantMapper extends DbSingleAttributeExportMapperBase<DbExportStateBase<?>> implements IDbExportMapper<DbExportStateBase<?>>{\r
+ @SuppressWarnings("unused")\r
+ private static final Logger logger = Logger.getLogger(DbConstantMapper.class);\r
+ private int sqlType;\r
+ private Object value;\r
+ \r
+ public static DbConstantMapper NewInstance(String dbIdAttributeString, int sqlType, Object value){\r
+ return new DbConstantMapper(dbIdAttributeString, sqlType, value);\r
+ }\r
+ \r
+ /**\r
+ * @param dbAttributString\r
+ * @param cdmAttributeString\r
+ */\r
+ protected DbConstantMapper(String dbAttributeString, int sqlType, Object value) {\r
+ super(null, dbAttributeString, null);\r
+ this.sqlType = sqlType;\r
+ this.value = value;\r
+ }\r
+\r
+\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.io.common.CdmSingleAttributeMapperBase#getTypeClass()\r
+ */\r
+ @Override\r
+ public Class<?> getTypeClass() {\r
+ return Integer.class;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValue()\r
+ */\r
+ @Override\r
+ protected Object getValue(CdmBase cdmBase) {\r
+ return value;\r
+ }\r
+ \r
+ \r
+\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.io.berlinModel.out.mapper.DbSingleAttributeExportMapperBase#getValueType()\r
+ */\r
+ @Override\r
+ protected int getSqlType() {\r
+ return this.sqlType;\r
+ }\r
+ \r
+}\r