3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.common
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.SQLException
;
15 import org
.apache
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.io
.common
.DbExportConfiguratorBase
.IdType
;
18 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.IExportTransformer
;
19 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 public abstract class DbExportBase
<CONFIG
extends DbExportConfiguratorBase
<STATE
, TRANSFORM
>, STATE
extends ExportStateBase
<CONFIG
, TRANSFORM
>, TRANSFORM
extends IExportTransformer
> extends CdmExportBase
<CONFIG
, STATE
, TRANSFORM
> {
28 private static Logger logger
= Logger
.getLogger(DbExportBase
.class);
30 protected boolean checkSqlServerColumnExists(Source source
, String tableName
, String columnName
){
31 String strQuery
= "SELECT Count(t.id) as n " +
32 " FROM sysobjects AS t " +
33 " INNER JOIN syscolumns AS c ON t.id = c.id " +
34 " WHERE (t.xtype = 'U') AND " +
35 " (t.name = '" + tableName
+ "') AND " +
36 " (c.name = '" + columnName
+ "')";
37 ResultSet rs
= source
.getResultSet(strQuery
) ;
43 } catch (SQLException e
) {
50 public abstract Class
<?
extends CdmBase
> getStandardMethodParameter();
52 protected void doCount(int count
, int modCount
, String pluralString
){
53 if ((count
% modCount
) == 0 && count
!= 0 ){ logger
.info(pluralString
+ " handled: " + (count
));}
57 public Object
getDbId(CdmBase cdmBase
, STATE state
) {
58 CONFIG config
= state
.getConfig();
59 IdType type
= config
.getIdType();
63 if (type
== IdType
.CDM_ID
){
64 return cdmBase
.getId();
65 }else if (type
== IdType
.CDM_ID_WITH_EXCEPTIONS
){
66 return getDbIdCdmWithExceptions(cdmBase
, state
);
67 }else if(type
== IdType
.MAX_ID
){
69 logger
.warn("MAX_ID not yet implemented");
70 return cdmBase
.getId();
71 }else if(type
== IdType
.ORIGINAL_SOURCE_ID
){
73 logger
.warn("ORIGINAL_SOURCE_ID not yet implemented");
74 return cdmBase
.getId();
76 logger
.warn("Unknown idType: " + type
);
77 return cdmBase
.getId();
82 protected Object
getDbIdCdmWithExceptions(CdmBase cdmBase
, STATE state
) {
84 return cdmBase
.getId();