1
|
/**
|
2
|
* Copyright (C) 2020 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.taxeditor.local.server;
|
10
|
|
11
|
import org.eclipse.core.runtime.jobs.Job;
|
12
|
import org.eclipse.swt.widgets.Display;
|
13
|
import org.springframework.core.io.Resource;
|
14
|
|
15
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
16
|
import eu.etaxonomy.cdm.cache.CdmRemoteCacheManager;
|
17
|
import eu.etaxonomy.cdm.config.ICdmSource;
|
18
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
19
|
import eu.etaxonomy.taxeditor.local.CdmServer;
|
20
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
21
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
22
|
|
23
|
/**
|
24
|
* @author k.luther
|
25
|
* @since Sep 18, 2020
|
26
|
*/
|
27
|
public class CdmStoreLocal extends CdmStore {
|
28
|
|
29
|
protected static CdmStoreConnectorLocal job;
|
30
|
private static CdmServer managedServer;
|
31
|
/**
|
32
|
* @param repository
|
33
|
* @param cdmSource
|
34
|
*/
|
35
|
protected CdmStoreLocal(ICdmRepository repository, ICdmSource cdmSource) {
|
36
|
super(repository, cdmSource);
|
37
|
}
|
38
|
|
39
|
|
40
|
/**
|
41
|
* Initialize with a specific datasource
|
42
|
*
|
43
|
* @param datasource
|
44
|
* a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
|
45
|
*/
|
46
|
public static void connect(ICdmSource cdmSource) {
|
47
|
connect(cdmSource, DEFAULT_DB_SCHEMA_VALIDATION,
|
48
|
DEFAULT_APPLICATION_CONTEXT);
|
49
|
}
|
50
|
|
51
|
public static void connect(ICdmSource cdmSource, RemotingLoginDialogLocal loginDialog) {
|
52
|
connect(cdmSource,
|
53
|
DEFAULT_DB_SCHEMA_VALIDATION,
|
54
|
DEFAULT_APPLICATION_CONTEXT,
|
55
|
loginDialog);
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Initialize and provide
|
60
|
*
|
61
|
* @param datasource
|
62
|
* @param dbSchemaValidation
|
63
|
* @param applicationContextBean
|
64
|
*/
|
65
|
private static void connect(final ICdmSource cdmSource,
|
66
|
final DbSchemaValidation dbSchemaValidation,
|
67
|
final Resource applicationContextBean) {
|
68
|
|
69
|
MessagingUtils.info("Connecting to datasource: " + cdmSource);
|
70
|
|
71
|
job = new CdmStoreConnectorLocal(Display.getDefault(), cdmSource,
|
72
|
dbSchemaValidation, applicationContextBean);
|
73
|
job.setUser(true);
|
74
|
job.setPriority(Job.BUILD);
|
75
|
job.schedule();
|
76
|
}
|
77
|
|
78
|
private static void connect(final ICdmSource cdmSource,
|
79
|
final DbSchemaValidation dbSchemaValidation,
|
80
|
final Resource applicationContextBean,
|
81
|
RemotingLoginDialogLocal remotingLoginDialog) {
|
82
|
RemotingLoginDialogLocal loginDialog = remotingLoginDialog;
|
83
|
if(isActive()) {
|
84
|
// before we connect we clear the entity caches and the sessions
|
85
|
CdmRemoteCacheManager.removeEntityCaches();
|
86
|
if(getCurrentSessionManager(true) != null) {
|
87
|
getCurrentSessionManager(true).disposeAll();
|
88
|
}
|
89
|
}
|
90
|
MessagingUtils.info("Connecting to datasource: " + cdmSource);
|
91
|
|
92
|
job = new CdmStoreConnectorLocal(Display.getDefault(),
|
93
|
cdmSource,
|
94
|
dbSchemaValidation,
|
95
|
applicationContextBean);
|
96
|
job.start(loginDialog);
|
97
|
|
98
|
}
|
99
|
|
100
|
public static boolean isConnecting() {
|
101
|
return job != null && job.getState() == Job.RUNNING;
|
102
|
}
|
103
|
|
104
|
public static void setManagedServer(CdmServer server) {
|
105
|
managedServer = server;
|
106
|
}
|
107
|
|
108
|
public static CdmServer getManagedServer() {
|
109
|
return managedServer;
|
110
|
}
|
111
|
}
|