Project

General

Profile

« Previous | Next » 

Revision b0b59404

Added by Cherian Mathew almost 10 years ago

added PostFix to memento to distinguish between remote and data source

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/CdmDataSourceRepository.java
43 43
	/** Constant <code>TAG_DATASOURCE="tagDataSource"</code> */
44 44
	public static final String TAG_DATASOURCE = "tagDataSource";
45 45
	private static final String CURRENT_DATASOURCE = "currentDataSource";
46
	private static final String CURRENT_DATASOURCE_POSTFIX = "currentDataSourcePostFix";
46 47
	private static final String DEFAULT_DATASOURCE_STATE_FILENAME = "datasource.xml";
48
	
47 49
	private static final String DEFAULT_DATASOURCE_NAME = "cdm";
50
	private static final String DEFAULT_DATASOURCE_POSTFIX = CdmPersistentDataSource.DATASOURCE_BEAN_POSTFIX;
48 51
	
49 52
	private static ICdmSource currentCdmSource;
50 53
	private static IMemento memento;
51
	private static String lastUsedDataSourceName;
54
	
55
	private static String lastUsedCdmSourceName;
56
	private static String lastUsedCdmSourcePostFix;
57
	
58
	
52 59
	
53 60
	/**
54 61
	 * <p>Getter for the field <code>lastUsedDataSourceName</code>.</p>
55 62
	 *
56 63
	 * @return a {@link java.lang.String} object.
57 64
	 */
58
	public static String getLastUsedDataSourceName(){
59
		if(lastUsedDataSourceName == null){
65
	public static void updateLastUsedDataSource(){
66
		if(lastUsedCdmSourceName == null){
60 67
			memento = readMemento();		
61
			lastUsedDataSourceName = memento != null ? memento.getString(CURRENT_DATASOURCE) : DEFAULT_DATASOURCE_NAME;
68
			lastUsedCdmSourceName = memento != null ? memento.getString(CURRENT_DATASOURCE) : DEFAULT_DATASOURCE_NAME;
69
			lastUsedCdmSourcePostFix = memento != null ? memento.getString(CURRENT_DATASOURCE_POSTFIX) : DEFAULT_DATASOURCE_POSTFIX;
70
			
62 71
		}
63
		return lastUsedDataSourceName;
72
		
64 73
	}
65 74

  
66 75
	/**
......
135 144
	public static ICdmSource getCurrentCdmSource() throws CdmRemoteSourceException {
136 145
		
137 146
		if (currentCdmSource == null) {
138
			String lastUsedCdmSourceName = getLastUsedDataSourceName();
139
			if(lastUsedCdmSourceName.endsWith(CdmPersistentDataSource.DATASOURCE_BEAN_POSTFIX)) {
147
			updateLastUsedDataSource();
148
			
149
			if(lastUsedCdmSourceName == null) {
150
				return null;
151
			}
152
			// for post fix = null , source is by default a data source
153
			if(lastUsedCdmSourcePostFix == null || lastUsedCdmSourcePostFix.equals(CdmPersistentDataSource.DATASOURCE_BEAN_POSTFIX)) {
140 154
				try {
141 155
					currentCdmSource = CdmPersistentDataSource.NewInstance(lastUsedCdmSourceName);
142 156
				} catch (DataSourceNotFoundException e) {
......
146 160
					save(h2DataSource.getName(), h2DataSource);
147 161
					setCurrentCdmSource(h2DataSource);
148 162
				}
149
			} else if (lastUsedCdmSourceName.endsWith(CdmPersistentRemoteSource.REMOTESOURCE_BEAN_POSTFIX)) {				
163
			} else if (lastUsedCdmSourcePostFix.equals(CdmPersistentRemoteSource.REMOTESOURCE_BEAN_POSTFIX)) {				
150 164
				currentCdmSource = CdmPersistentRemoteSource.NewInstance(lastUsedCdmSourceName);
151 165
			} else {
152 166
				throw new CdmRemoteSourceException("Unkown Cdm Source Type");
......
259 273
	 *********************************************************/
260 274
	
261 275
	private static void saveAsCurrentDatabaseToMemento(ICdmSource cdmSource){
262
		if(memento == null)
276
		if(memento == null) {
263 277
			memento = readMemento();
278
		}
264 279
		memento.putString(CURRENT_DATASOURCE, cdmSource.getName());
280
		
281
		// Set postfix to distinguish between data and remote sources
282
		if(cdmSource instanceof CdmPersistentRemoteSource) {
283
			memento.putString(CURRENT_DATASOURCE_POSTFIX, CdmPersistentRemoteSource.REMOTESOURCE_BEAN_POSTFIX);
284
		} else {
285
			memento.putString(CURRENT_DATASOURCE_POSTFIX, CdmPersistentDataSource.DATASOURCE_BEAN_POSTFIX);
286
		}
287
		
288
		
265 289
		saveMementoToFile(memento);
266 290
	}
267 291
	

Also available in: Unified diff