2 * Copyright (C) 2020 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.
9 package eu
.etaxonomy
.taxeditor
.local
.server
;
11 import org
.eclipse
.core
.runtime
.jobs
.Job
;
12 import org
.eclipse
.swt
.widgets
.Display
;
13 import org
.springframework
.core
.io
.Resource
;
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
;
28 public class CdmStoreLocal
extends CdmStore
{
30 protected static CdmStoreConnectorLocal job
;
31 private static CdmServer managedServer
;
36 protected CdmStoreLocal(ICdmRepository repository
, ICdmSource cdmSource
) {
37 super(repository
, cdmSource
);
38 // TODO Auto-generated constructor stub
43 * Initialize with a specific datasource
46 * a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
48 public static void connect(ICdmSource cdmSource
) {
49 connect(cdmSource
, DEFAULT_DB_SCHEMA_VALIDATION
,
50 DEFAULT_APPLICATION_CONTEXT
);
53 public static void connect(ICdmSource cdmSource
, RemotingLoginDialogLocal loginDialog
) {
55 DEFAULT_DB_SCHEMA_VALIDATION
,
56 DEFAULT_APPLICATION_CONTEXT
,
61 * Initialize and provide
64 * @param dbSchemaValidation
65 * @param applicationContextBean
67 private static void connect(final ICdmSource cdmSource
,
68 final DbSchemaValidation dbSchemaValidation
,
69 final Resource applicationContextBean
) {
71 MessagingUtils
.info("Connecting to datasource: " + cdmSource
);
73 job
= new CdmStoreConnectorLocal(Display
.getDefault(), cdmSource
,
74 dbSchemaValidation
, applicationContextBean
);
76 job
.setPriority(Job
.BUILD
);
80 private static void connect(final ICdmSource cdmSource
,
81 final DbSchemaValidation dbSchemaValidation
,
82 final Resource applicationContextBean
,
83 RemotingLoginDialogLocal remotingLoginDialog
) {
84 RemotingLoginDialogLocal loginDialog
= remotingLoginDialog
;
86 // before we connect we clear the entity caches and the sessions
87 CdmRemoteCacheManager
.removeEntityCaches();
88 if(getCurrentSessionManager(true) != null) {
89 getCurrentSessionManager(true).disposeAll();
92 MessagingUtils
.info("Connecting to datasource: " + cdmSource
);
94 job
= new CdmStoreConnectorLocal(Display
.getDefault(),
97 applicationContextBean
);
98 job
.start(loginDialog
);
102 public static boolean isConnecting() {
103 return job
!= null && job
.getState() == Job
.RUNNING
;
106 public static void setManagedServer(CdmServer server
) {
107 managedServer
= server
;
110 public static CdmServer
getManagedServer() {
111 return managedServer
;