private boolean retrieveTaxa(FaunaEuropaeaImportState state) {\r
\r
int limit = state.getConfig().getLimitSave();\r
- \r
+\r
Map<String, MapWrapper<? extends CdmBase>> stores = state.getStores();\r
// MapWrapper<TaxonBase> nameStore = (MapWrapper<TaxonBase>)stores.get(ICdmIO.TAXONNAME_STORE);\r
MapWrapper<TaxonBase> taxonStore = (MapWrapper<TaxonBase>)stores.get(ICdmIO.TAXON_STORE);\r
MapWrapper<TeamOrPersonBase> authorStore = (MapWrapper<TeamOrPersonBase>)stores.get(ICdmIO.TEAM_STORE);\r
// Map<Integer, FaunaEuropaeaTaxon> fauEuTaxonMap = state.getFauEuTaxonMap();\r
Map<Integer, FaunaEuropaeaTaxon> fauEuTaxonMap = new HashMap<Integer, FaunaEuropaeaTaxon>(limit);\r
+ state.setFauEuTaxonMap(fauEuTaxonMap);\r
\r
if (logger.isInfoEnabled()) {\r
- logger.info("Initial size of taxon Store is: " + taxonStore.size());\r
+ logger.info("Initial size of taxon store is: " + taxonStore.size());\r
}\r
FaunaEuropaeaImportConfigurator fauEuConfig = state.getConfig();\r
ReferenceBase<?> sourceRef = fauEuConfig.getSourceReference();\r
boolean success = true;\r
\r
try {\r
- \r
+\r
String strQuery = \r
" SELECT Taxon.*, rank.*, author.* " + \r
" FROM dbo.Taxon " +\r
logger.debug("Query: " + strQuery);\r
}\r
ResultSet rs = source.getResultSet(strQuery);\r
- \r
+\r
while (rs.next()) {\r
\r
// if ((i++ % limit) == 0 && i != 1 ) { \r
-// if(logger.isInfoEnabled()) {\r
-// logger.info("Taxa retrieved: " + (i-1)); \r
-// }\r
+// if(logger.isInfoEnabled()) {\r
+// logger.info("Taxa retrieved: " + (i-1)); \r
+// }\r
// }\r
\r
int taxonId = rs.getInt("TAX_ID");\r
int status = rs.getInt("TAX_VALID");\r
int year = rs.getInt("TAX_YEAR");\r
String autName = rs.getString("aut_name");\r
- \r
+\r
Rank rank = null;\r
int parenthesis = rs.getInt("TAX_PARENTHESIS");\r
UUID taxonBaseUuid = null;\r
} else {\r
taxonBaseUuid = UUID.randomUUID();\r
}\r
- \r
+\r
// String originalGenusName = "";\r
// String genusName = "";\r
// String specificEpithet = "";\r
\r
- \r
+\r
FaunaEuropaeaTaxon fauEuTaxon = new FaunaEuropaeaTaxon();\r
fauEuTaxon.setUuid(taxonBaseUuid);\r
fauEuTaxon.setLocalName(rs.getString("TAX_NAME"));\r
fauEuTaxon.setValid(false);\r
}\r
\r
- \r
+\r
try {\r
rank = FaunaEuropaeaTransformer.rankId2Rank(rs, false);\r
} catch (UnknownCdmTypeException e) {\r
logger.warn("Taxon (" + taxonId + ") has rank null and can not be saved.");\r
continue;\r
}\r
- \r
+\r
ReferenceBase<?> sourceReference = fauEuConfig.getSourceReference();\r
ReferenceBase<?> auctReference = fauEuConfig.getAuctReference();\r
\r
\r
// set local name cache\r
// zooName.setNameCache(localName);\r
- \r
+\r
TaxonBase<?> taxonBase;\r
\r
Synonym synonym;\r
}\r
\r
taxonBase.setUuid(taxonBaseUuid);\r
- \r
+\r
ImportHelper.setOriginalSource(taxonBase, fauEuConfig.getSourceReference(), taxonId, OS_NAMESPACE_TAXON);\r
ImportHelper.setOriginalSource(zooName, fauEuConfig.getSourceReference(), taxonId, "TaxonName");\r
- \r
- \r
+\r
+\r
if (!taxonStore.containsId(taxonId)) {\r
if (taxonBase == null) {\r
if (logger.isDebugEnabled()) { \r
taxonStore.put(taxonId, taxonBase);\r
fauEuTaxonMap.put(taxonId, fauEuTaxon);\r
// if (logger.isDebugEnabled()) { \r
-// logger.debug("Stored taxon base (" + taxonId + ") " + localName); \r
+// logger.debug("Stored taxon base (" + taxonId + ") " + localName); \r
// }\r
} else {\r
logger.warn("Not imported taxon base with duplicated TAX_ID (" + taxonId + \r
} catch (Exception e) {\r
logger.warn("An exception occurred when creating taxon base with id " + taxonId + \r
". Taxon base could not be saved.");\r
+ e.printStackTrace();\r
}\r
- }\r
- \r
- if ((i++ % limit) == 0 && i != 1 ) { \r
- if(logger.isInfoEnabled()) {\r
- logger.info("Taxa retrieved: " + (i-1)); \r
- }\r
- success = processTaxaSecondPass(state);\r
- success = saveTaxa(state, state.getHighestTaxonIndex(), limit);\r
- \r
- if (logger.isInfoEnabled()) {\r
- logger.info("Final size of taxon Store is: " + taxonStore.size());\r
+\r
+ if ((i++ % limit) == 0 && i != 1 ) { \r
+ if(logger.isInfoEnabled()) {\r
+ logger.info("Taxa retrieved: " + (i-1)); \r
+ }\r
+ success = processTaxaSecondPass(state);\r
+ success = saveTaxa(state);\r
+\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("End size of taxon Store is: " + taxonStore.size());\r
+ }\r
+\r
+// taxonStore.makeNewMap((IService)getTaxonService());\r
+ taxonStore.makeEmpty();\r
+ fauEuTaxonMap = new HashMap<Integer, FaunaEuropaeaTaxon>(limit);\r
+ state.setFauEuTaxonMap(fauEuTaxonMap);\r
+\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("Final size of taxon Store is: " + taxonStore.size());\r
+ }\r
}\r
- \r
- taxonStore.makeNewMap((IService)getTaxonService());\r
-// taxonStore.makeEmpty();\r
- }\r
\r
+ }\r
} catch (SQLException e) {\r
logger.error("SQLException:" + e);\r
success = false;\r
\r
taxonBase = taxonBase.deproxy(taxonBase, TaxonBase.class);\r
\r
- completeString = \r
- buildLowerTaxonName(originalGenus, useOriginalGenus,\r
- genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet,\r
- fauEuTaxon, fauEuTaxonMap);\r
- \r
- completeString = (String) CdmUtils.removeDuplicateWhitespace(completeString.trim());\r
+// completeString = \r
+// buildLowerTaxonName(originalGenus, useOriginalGenus,\r
+// genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet,\r
+// fauEuTaxon, fauEuTaxonMap);\r
+// \r
+// completeString = (String) CdmUtils.removeDuplicateWhitespace(completeString.trim());\r
\r
}\r
setCompleteTaxonName(completeString, useOriginalGenus,\r
}\r
return success;\r
}\r
+\r
\r
+ protected boolean saveTaxa(FaunaEuropaeaImportState state) {\r
+\r
+ boolean success = true;\r
+\r
+ Map<String, MapWrapper<? extends CdmBase>> stores = state.getStores();\r
+ MapWrapper<TaxonBase> taxonStore = (MapWrapper<TaxonBase>)stores.get(ICdmIO.TAXON_STORE);\r
+ TransactionStatus txStatus = null;\r
+\r
+ if(logger.isInfoEnabled()) { logger.info("Saving taxa ..."); }\r
+\r
+ if (state.getConfig().isUseTransactions()) {\r
+ txStatus = startTransaction();\r
+ }\r
+\r
+ getTaxonService().saveTaxonAll(taxonStore.objects());\r
+\r
+ if (state.getConfig().isUseTransactions()) {\r
+ commitTransaction(txStatus);\r
+ }\r
+\r
+ return success;\r
+ }\r
\r
\r
}\r