2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.io
.faunaEuropaea
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.ResultSetMetaData
;
14 import java
.sql
.SQLException
;
15 import java
.util
.Collection
;
16 import java
.util
.HashMap
;
18 import java
.util
.UUID
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.springframework
.transaction
.TransactionStatus
;
23 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
24 import eu
.etaxonomy
.cdm
.io
.common
.CdmImportBase
;
25 import eu
.etaxonomy
.cdm
.io
.common
.CdmIoBase
;
26 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
27 import eu
.etaxonomy
.cdm
.io
.common
.ICdmImport
;
28 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
29 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
30 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
31 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
32 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
33 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
34 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
35 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
36 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
41 * @author a.babadshanjan
45 public abstract class FaunaEuropaeaImportBase
extends CdmImportBase
<FaunaEuropaeaImportConfigurator
, FaunaEuropaeaImportState
>
46 implements ICdmImport
<FaunaEuropaeaImportConfigurator
,FaunaEuropaeaImportState
> {
47 private static final Logger logger
= Logger
.getLogger(FaunaEuropaeaImportBase
.class);
49 // /* Max number of taxa to retrieve (for test purposes) */
50 // protected static final int maxTaxa = 1000;
51 // /* Max number of taxa to be saved with one service call */
52 // protected int limit = 20000; // TODO: Make configurable
53 // /* Interval for progress info message when retrieving taxa */
54 // protected static final int modCount = 10000;
55 // /* Highest taxon index in the FauEu database */
56 // protected int highestTaxonIndex = 0;
58 protected boolean resultSetHasColumn(ResultSet rs
, String columnName
){
60 ResultSetMetaData metaData
= rs
.getMetaData();
61 for (int i
= 0; i
< metaData
.getColumnCount(); i
++){
62 if (metaData
.getColumnName(i
+ 1).equalsIgnoreCase(columnName
)){
67 } catch (SQLException e
) {
68 logger
.warn("Exception in resultSetHasColumn");
73 protected boolean checkSqlServerColumnExists(Source source
, String tableName
, String columnName
){
74 String strQuery
= "SELECT Count(t.id) as n " +
75 " FROM sysobjects AS t " +
76 " INNER JOIN syscolumns AS c ON t.id = c.id " +
77 " WHERE (t.xtype = 'U') AND " +
78 " (t.name = '" + tableName
+ "') AND " +
79 " (c.name = '" + columnName
+ "')";
80 ResultSet rs
= source
.getResultSet(strQuery
) ;
86 } catch (SQLException e
) {
94 * Returns a map that holds all values of a ResultSet. This is needed if a value needs to
98 * @throws SQLException
100 protected Map
<String
, Object
> getValueMap(ResultSet rs
) throws SQLException
{
102 Map
<String
, Object
> valueMap
= new HashMap
<String
, Object
>();
103 int colCount
= rs
.getMetaData().getColumnCount();
104 for (int c
= 0; c
< colCount
; c
++){
105 Object value
= rs
.getObject(c
+1);
106 String label
= rs
.getMetaData().getColumnLabel(c
+1).toLowerCase();
107 if (value
!= null && ! CdmUtils
.Nz(value
.toString()).trim().equals("")){
108 valueMap
.put(label
, value
);
112 }catch(SQLException e
){
122 protected TaxonomicTree
getTaxonomicTreeFor(FaunaEuropaeaImportState state
, ReferenceBase
<?
> sourceRef
) {
125 UUID treeUuid
= state
.getTreeUuid(sourceRef
);
126 if (treeUuid
== null){
127 if(logger
.isInfoEnabled()) { logger
.info(".. creating new taxonomic tree"); }
129 TransactionStatus txStatus
= startTransaction();
130 tree
= makeTreeMemSave(state
, sourceRef
);
131 commitTransaction(txStatus
);
134 tree
= getTaxonTreeService().getTaxonomicTreeByUuid(treeUuid
);