1
|
/**
|
2
|
* Copyright (C) 2008 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*/
|
6
|
|
7
|
package eu.etaxonomy.cdm.io.common;
|
8
|
|
9
|
import org.apache.log4j.Logger;
|
10
|
import org.springframework.core.io.ClassPathResource;
|
11
|
|
12
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
13
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
14
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
15
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
16
|
|
17
|
/**
|
18
|
* This is an exporter that invokes the application aware defaultExport when
|
19
|
* invoked itself
|
20
|
*
|
21
|
* @author a.babadshanjan
|
22
|
* @since 17.11.2008
|
23
|
*/
|
24
|
public class CdmDefaultIOBase<T extends IIoConfigurator> {
|
25
|
@SuppressWarnings("unused")
|
26
|
private static final Logger logger = Logger.getLogger(CdmDefaultIOBase.class);
|
27
|
|
28
|
public static final String DEFAULT_IO_APPLICATION_CONTEXT_RESOURCE = "/eu/etaxonomy/cdm/defaultIoApplicationContext.xml";
|
29
|
|
30
|
|
31
|
protected ICdmRepository cdmApp = null;
|
32
|
|
33
|
/**
|
34
|
* Creates a new {@link CdmApplicationController} if it does not exist yet
|
35
|
* or if createNew is <ocde>true</code>
|
36
|
*
|
37
|
* @param config
|
38
|
* @param destination
|
39
|
* @param omitTermLoading
|
40
|
* @param createNew
|
41
|
* @return
|
42
|
*/
|
43
|
protected boolean startApplicationController(IIoConfigurator config,
|
44
|
ICdmDataSource cdmSource, boolean omitTermLoading, boolean createNew) {
|
45
|
if (config.getCdmAppController() != null) {
|
46
|
this.cdmApp = config.getCdmAppController();
|
47
|
}
|
48
|
DbSchemaValidation schemaValidation = config.getDbSchemaValidation();
|
49
|
if (this instanceof CdmDefaultExport) {
|
50
|
if (schemaValidation.equals(DbSchemaValidation.CREATE)
|
51
|
|| schemaValidation.equals(DbSchemaValidation.CREATE_DROP)) {
|
52
|
throw new IllegalArgumentException(
|
53
|
"The export may not run with DbSchemaValidation.CREATE or DbSchemaValidation.CREATE_DROP as this value deletes the source database");
|
54
|
}
|
55
|
}
|
56
|
|
57
|
if (createNew == true || cdmApp == null) {
|
58
|
ClassPathResource applicationContextResource = new ClassPathResource(DEFAULT_IO_APPLICATION_CONTEXT_RESOURCE);
|
59
|
cdmApp = CdmApplicationController.NewInstance(applicationContextResource, cdmSource, schemaValidation,
|
60
|
config.getHibernateConfig(), omitTermLoading, config.getProgressMonitor());
|
61
|
if (cdmApp != null) {
|
62
|
return true;
|
63
|
} else {
|
64
|
return false;
|
65
|
}
|
66
|
}
|
67
|
return true;
|
68
|
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Returns the {@link CdmApplicationController}. This is null if invoke()
|
73
|
* has not been called yet and if the controller has not been set manually
|
74
|
* by setCdmApp() yet.
|
75
|
*
|
76
|
* @return the cdmApp
|
77
|
*/
|
78
|
public ICdmRepository getCdmAppController() {
|
79
|
return this.cdmApp;
|
80
|
}
|
81
|
/**
|
82
|
* @see #getCdmAppController()
|
83
|
*/
|
84
|
public void setCdmAppController(ICdmRepository cdmApp) {
|
85
|
this.cdmApp = cdmApp;
|
86
|
}
|
87
|
|
88
|
}
|