1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.io.common;
|
10
|
|
11
|
import java.sql.ResultSet;
|
12
|
import java.sql.SQLException;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.io.common.DbExportConfiguratorBase.IdType;
|
17
|
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
|
18
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
19
|
|
20
|
/**
|
21
|
* @author a.mueller
|
22
|
* @author e.-m.lee
|
23
|
* @since 17.02.2010
|
24
|
*
|
25
|
*/
|
26
|
public abstract class DbExportBase<CONFIG extends DbExportConfiguratorBase<STATE, TRANSFORM, Source>, STATE extends DbExportStateBase<CONFIG, TRANSFORM>, TRANSFORM extends IExportTransformer>
|
27
|
extends CdmExportBase<CONFIG, STATE, TRANSFORM, Source> {
|
28
|
|
29
|
private static final long serialVersionUID = -1652695446752713850L;
|
30
|
private static Logger logger = Logger.getLogger(DbExportBase.class);
|
31
|
|
32
|
protected boolean checkSqlServerColumnExists(Source source, String tableName, String columnName){
|
33
|
String strQuery = "SELECT Count(t.id) as n " +
|
34
|
" FROM sysobjects AS t " +
|
35
|
" INNER JOIN syscolumns AS c ON t.id = c.id " +
|
36
|
" WHERE (t.xtype = 'U') AND " +
|
37
|
" (t.name = '" + tableName + "') AND " +
|
38
|
" (c.name = '" + columnName + "')";
|
39
|
ResultSet rs = source.getResultSet(strQuery) ;
|
40
|
int n;
|
41
|
try {
|
42
|
rs.next();
|
43
|
n = rs.getInt("n");
|
44
|
return n>0;
|
45
|
} catch (SQLException e) {
|
46
|
e.printStackTrace();
|
47
|
return false;
|
48
|
}
|
49
|
|
50
|
}
|
51
|
|
52
|
public abstract Class<? extends CdmBase> getStandardMethodParameter();
|
53
|
|
54
|
protected void doCount(int count, int modCount, String pluralString){
|
55
|
if ((count % modCount ) == 0 && count!= 0 ){ logger.info(pluralString + " handled: " + (count));}
|
56
|
}
|
57
|
|
58
|
@Override
|
59
|
public Object getDbId(CdmBase cdmBase, STATE state) {
|
60
|
CONFIG config = state.getConfig();
|
61
|
IdType type = config.getIdType();
|
62
|
if (cdmBase == null){
|
63
|
return null;
|
64
|
}
|
65
|
if (type == IdType.CDM_ID){
|
66
|
return cdmBase.getId();
|
67
|
}else if (type == IdType.CDM_ID_WITH_EXCEPTIONS){
|
68
|
return getDbIdCdmWithExceptions(cdmBase, state);
|
69
|
}else if(type == IdType.MAX_ID){
|
70
|
//TODO
|
71
|
logger.warn("MAX_ID not yet implemented");
|
72
|
return cdmBase.getId();
|
73
|
}else if(type == IdType.ORIGINAL_SOURCE_ID){
|
74
|
//TODO
|
75
|
logger.warn("ORIGINAL_SOURCE_ID not yet implemented");
|
76
|
return cdmBase.getId();
|
77
|
}else{
|
78
|
logger.warn("Unknown idType: " + type);
|
79
|
return cdmBase.getId();
|
80
|
}
|
81
|
|
82
|
}
|
83
|
|
84
|
protected Object getDbIdCdmWithExceptions(CdmBase cdmBase, STATE state) {
|
85
|
//default -> override
|
86
|
return cdmBase.getId();
|
87
|
}
|
88
|
|
89
|
|
90
|
|
91
|
}
|