Project

General

Profile

« Previous | Next » 

Revision c9a67492

Added by Niels Hoffmann over 12 years ago

Added a missing feature to plugin dependencies

View differences:

eu.etaxonomy.taxeditor.feature.platform/feature.xml
853 853
         fragment="true"
854 854
         unpack="false"/>
855 855

  
856
   <plugin
857
         id="org.junit"
858
         download-size="0"
859
         install-size="0"
860
         version="0.0.0"/>
861

  
856 862
</feature>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java
1 1
// $Id$
2 2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy 
5
 * http://www.e-taxonomy.eu
6
 * 
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.
9
 */
10 10

  
11 11
package eu.etaxonomy.taxeditor.store;
12 12

  
......
34 34
 * @created Dec 8, 2010
35 35
 * @version 1.0
36 36
 */
37
class CdmStoreConnector extends Job{
38
	private Display display;
39
	private ICdmDataSource dataSource;
37
class CdmStoreConnector extends Job {
38
	private final Display display;
39
	private final ICdmDataSource dataSource;
40 40
	private DbSchemaValidation dbSchemaValidation;
41
	private Resource applicationContextBean;
41
	private final Resource applicationContextBean;
42 42

  
43 43
	/**
44 44
	 * @param datasource
......
55 55
		this.applicationContextBean = applicationContextBean;
56 56
	}
57 57

  
58

  
58
	@Override
59 59
	public IStatus run(final IProgressMonitor monitor) {
60 60

  
61 61
		monitor.beginTask(getConnectionMessage(), 10);
62
		
62

  
63 63
		// check if database is up and running
64 64
		checkDatabaseReachable(monitor);
65
		
66
		if(! monitor.isCanceled()){
65

  
66
		if (!monitor.isCanceled()) {
67 67
			// check if the datasource actually holds data
68 68
			checkIsNonEmptyCdmDatabase(monitor);
69 69
		}
70
		
71
		if(dbSchemaValidation != DbSchemaValidation.CREATE && ! monitor.isCanceled()){
72
			// if we do not create the datasource, we want to check if the datasource is compatible with this editor
70

  
71
		if (dbSchemaValidation != DbSchemaValidation.CREATE
72
				&& !monitor.isCanceled()) {
73
			// if we do not create the datasource, we want to check if the
74
			// datasource is compatible with this editor
73 75
			checkDbSchemaVersionCompatibility(monitor);
74 76
		}
75
		
77

  
76 78
		// we are done with our low level checking and will free resources now
77 79
		dataSource.closeOpenConnections();
78
		
79
		if(! monitor.isCanceled()){
80

  
81
		if (!monitor.isCanceled()) {
80 82
			CdmStore.close(monitor);
81 83
		}
82
		
84

  
83 85
		CdmApplicationController applicationController = null;
84
		
85
		if(! monitor.isCanceled()){
86
			CdmProgressMonitorAdapter subprogressMonitor = CdmProgressMonitorAdapter.CreateSubMonitor(monitor, 5);
86

  
87
		if (!monitor.isCanceled()) {
88
			CdmProgressMonitorAdapter subprogressMonitor = CdmProgressMonitorAdapter
89
					.CreateSubMonitor(monitor, IProgressMonitor.UNKNOWN);
87 90
			// This is where we instantiate the application controller
88
			try{
89
				applicationController = CdmApplicationController.NewInstance(applicationContextBean, dataSource, dbSchemaValidation, false, subprogressMonitor);
90
			}catch(Exception e){
91
			try {
92
				applicationController = CdmApplicationController.NewInstance(
93
						applicationContextBean, dataSource, dbSchemaValidation,
94
						false, subprogressMonitor);
95
			} catch (Exception e) {
91 96
				StoreUtil.error(this.getClass(), e.getMessage(), e);
92 97
			}
93 98
		}
94
		
99

  
95 100
		monitor.done();
96
		
97
		if(! monitor.isCanceled()){
101

  
102
		if (!monitor.isCanceled()) {
98 103
			CdmStore.setInstance(applicationController, dataSource);
99
			
100
			display.asyncExec(new Runnable(){
101
				/* (non-Javadoc)
104

  
105
			display.asyncExec(new Runnable() {
106
				/*
107
				 * (non-Javadoc)
108
				 * 
102 109
				 * @see java.lang.Runnable#run()
103 110
				 */
104 111
				@Override
105 112
				public void run() {
106 113
					authenticate();
107
			
114

  
108 115
					startContext();
109 116
				}
110 117
			});
111
							
112
			StoreUtil.info("Application context initialized.");	
118

  
119
			StoreUtil.info("Application context initialized.");
113 120
			return Status.OK_STATUS;
114
		}else{
121
		} else {
115 122
			// Show datasource view if not shown yet
116
			display.asyncExec(new Runnable(){
117
				/* (non-Javadoc)
123
			display.asyncExec(new Runnable() {
124
				/*
125
				 * (non-Javadoc)
126
				 * 
118 127
				 * @see java.lang.Runnable#run()
119 128
				 */
120 129
				@Override
......
124 133
			});
125 134
			return Status.CANCEL_STATUS;
126 135
		}
127
		
128
		
136

  
129 137
	}
130
	
131
	private void authenticate(){
138

  
139
	private void authenticate() {
132 140
		LoginDialog loginDialog = new LoginDialog(StoreUtil.getShell());
133
		loginDialog.open();		
141
		loginDialog.open();
134 142
	}
135
	
136
	private void startContext(){
143

  
144
	private void startContext() {
137 145
		CdmStore.getContextManager().notifyContextStart();
138 146
	}
139
	
147

  
140 148
	/**
141 149
	 * @return
142 150
	 */
143 151
	private String getConnectionMessage() {
144 152
		String message = "";
145
		if(dataSource.getDatabaseType().equals(DatabaseTypeEnum.H2)){
153
		if (dataSource.getDatabaseType().equals(DatabaseTypeEnum.H2)) {
146 154
			message = " local CDM Store ";
147
		}else{
155
		} else {
148 156
			message = " CDM Community Store ";
149 157
		}
150 158
		message += "'" + dataSource.getName() + "'";
151
		
159

  
152 160
		message = "Connecting to" + message + ".";
153
		
161

  
154 162
		return message;
155 163
	}
156
	
164

  
157 165
	/**
158 166
	 * @return
159
	 * @throws SQLException 
167
	 * @throws SQLException
160 168
	 */
161 169
	private void checkDbSchemaVersionCompatibility(IProgressMonitor monitor) {
162 170
		monitor.subTask("Checking if datasource is compatible with this editor.");
163 171
		String dbSchemaVersion;
164 172
		boolean result = false;
165 173
		try {
166
			dbSchemaVersion = (String) dataSource.getSingleValue(MetaDataPropertyName.DB_SCHEMA_VERSION.getSqlQuery());
167
			// we assume that empty dbSchemaVersion means an empty database and skip version checking
168
			result = dbSchemaVersion == null ? true : CdmMetaData.isDbSchemaVersionCompatible(dbSchemaVersion);
174
			dbSchemaVersion = (String) dataSource
175
					.getSingleValue(MetaDataPropertyName.DB_SCHEMA_VERSION
176
							.getSqlQuery());
177
			// we assume that empty dbSchemaVersion means an empty database and
178
			// skip version checking
179
			result = dbSchemaVersion == null ? true : CdmMetaData
180
					.isDbSchemaVersionCompatible(dbSchemaVersion);
169 181
			monitor.worked(1);
170 182
		} catch (SQLException e) {
171 183
			//
172 184
		}
173
		
174
		if(!result){
185

  
186
		if (!result) {
175 187
			// Show an error message
176
			StoreUtil.errorDialog("DatabaseCompatibilityCheck failed", this, "The database schema for the chosen " +
177
					"datasource '" + dataSource + "' \n is not valid for this version of the taxonomic editor. \n" +
178
					"Please update the chosen datasource or choose a new data source to connect to in the Datasource View.", null);
179
		
188
			StoreUtil
189
					.errorDialog(
190
							"DatabaseCompatibilityCheck failed",
191
							this,
192
							"The database schema for the chosen "
193
									+ "datasource '"
194
									+ dataSource
195
									+ "' \n is not valid for this version of the taxonomic editor. \n"
196
									+ "Please update the chosen datasource or choose a new data source to connect to in the Datasource View.",
197
							null);
198

  
180 199
			monitor.setCanceled(true);
181
		}					
182
		
200
		}
201

  
183 202
	}
184
	
203

  
185 204
	private void checkIsNonEmptyCdmDatabase(IProgressMonitor monitor) {
186 205
		monitor.subTask("Checking if datasource is a non empty CDM database.");
187
		
206

  
188 207
		try {
189
			dataSource.getSingleValue(MetaDataPropertyName.DB_SCHEMA_VERSION.getSqlQuery());
208
			dataSource.getSingleValue(MetaDataPropertyName.DB_SCHEMA_VERSION
209
					.getSqlQuery());
190 210
		} catch (SQLException e1) {
191 211
			dbSchemaValidation = DbSchemaValidation.CREATE;
192 212
		}
193 213
	}
194
	
195
	private void checkDatabaseReachable(IProgressMonitor monitor){
214

  
215
	private void checkDatabaseReachable(IProgressMonitor monitor) {
196 216
		try {
197 217
			monitor.subTask("Checking if datasource is reachable.");
198 218
			dataSource.testConnection();
199 219
			monitor.worked(1);
200 220
		} catch (ClassNotFoundException e) {
201
			StoreUtil.errorDialog("Could not connect to chosen datasource", this, "Reason: " + e.getMessage(), e);
221
			StoreUtil.errorDialog("Could not connect to chosen datasource",
222
					this, "Reason: " + e.getMessage(), e);
202 223
			monitor.setCanceled(true);
203 224
		} catch (SQLException e) {
204
			StoreUtil.errorDialog("Could not connect to chosen datasource", this, "Reason: " + e.getMessage(), e);
225
			StoreUtil.errorDialog("Could not connect to chosen datasource",
226
					this, "Reason: " + e.getMessage(), e);
205 227
			monitor.setCanceled(true);
206 228
		}
207
		
229

  
208 230
	}
209 231
}

Also available in: Unified diff