Revision f78917b1
Added by Patrick Plitzner almost 8 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmMetaDataAwareDataSourceContainer.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
10 | 10 |
|
11 | 11 |
package eu.etaxonomy.taxeditor.view.datasource; |
12 | 12 |
|
13 |
import java.sql.SQLException; |
|
14 | 13 |
import java.util.HashMap; |
15 | 14 |
import java.util.Map; |
16 | 15 |
|
17 | 16 |
import eu.etaxonomy.cdm.config.CdmSourceException; |
18 | 17 |
import eu.etaxonomy.cdm.config.ICdmSource; |
19 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
20 | 18 |
import eu.etaxonomy.cdm.model.metadata.CdmMetaData; |
21 | 19 |
import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName; |
22 | 20 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
... | ... | |
29 | 27 |
* @version 1.0 |
30 | 28 |
*/ |
31 | 29 |
public class CdmMetaDataAwareDataSourceContainer { |
32 |
|
|
33 |
|
|
34 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
35 | 33 |
/** Constant <code>DEFAULT_ENTRY="-"</code> */ |
36 | 34 |
public static final String DEFAULT_ENTRY = "-"; |
37 |
|
|
35 |
|
|
38 | 36 |
private ICdmSource cdmSource; |
39 |
|
|
37 |
|
|
40 | 38 |
private boolean running; |
41 |
|
|
39 |
|
|
42 | 40 |
private Map<MetaDataPropertyName, String> metaDataMap; |
43 |
|
|
41 |
|
|
44 | 42 |
/** |
45 | 43 |
* <p>Constructor for CdmMetaDataAwareDataSourceContainer.</p> |
46 | 44 |
* |
... | ... | |
49 | 47 |
*/ |
50 | 48 |
public CdmMetaDataAwareDataSourceContainer(ICdmSource cdmSource){ |
51 | 49 |
this.cdmSource = cdmSource; |
52 |
|
|
50 |
|
|
53 | 51 |
metaDataMap = getDefaultMetaDataMap(); |
54 |
|
|
52 |
|
|
55 | 53 |
} |
56 | 54 |
|
57 | 55 |
// /** |
... | ... | |
62 | 60 |
// public ICdmDataSource getDataSource() { |
63 | 61 |
// return dataSource; |
64 | 62 |
// } |
65 |
|
|
63 |
|
|
66 | 64 |
public ICdmSource getCdmSource() { |
67 | 65 |
return cdmSource; |
68 | 66 |
} |
69 |
|
|
67 |
|
|
70 | 68 |
public void getMetaDataFromDataSource(){ |
71 | 69 |
try { |
72 | 70 |
running = cdmSource.checkConnection(); |
73 | 71 |
} catch (Exception e) { |
74 | 72 |
running = false; |
75 | 73 |
for(MetaDataPropertyName metaDataPropertyName : MetaDataPropertyName.values()){ |
76 |
metaDataMap.put(metaDataPropertyName, DEFAULT_ENTRY);
|
|
74 |
metaDataMap.put(metaDataPropertyName, DEFAULT_ENTRY); |
|
77 | 75 |
} |
78 | 76 |
} |
79 | 77 |
|
... | ... | |
81 | 79 |
if(isRunning()){ |
82 | 80 |
|
83 | 81 |
// try { |
84 |
metaDataMap = cdmSource.getMetaDataMap();
|
|
82 |
metaDataMap = cdmSource.getMetaDataMap(); |
|
85 | 83 |
cdmSource.closeOpenConnections(); |
86 | 84 |
// } catch (CdmSourceException e) { |
87 | 85 |
// StoreUtil.warn(this.getClass(), "SQLException when trying to access: " + cdmSource.getName() + ". " + e.getMessage()); |
88 |
// }
|
|
86 |
// } |
|
89 | 87 |
} |
90 | 88 |
} catch (Exception e) { |
91 |
MessagingUtils.error(this.getClass(), e); |
|
89 |
if(e instanceof CdmSourceException && e.getMessage().toLowerCase().contains("\"cdmmetadata\"")){ |
|
90 |
MessagingUtils.error(this.getClass(), "Data source "+((CdmSourceException) e).getSourceName()+" does not have a CDMMETADATA table", null); |
|
91 |
} |
|
92 |
else{ |
|
93 |
MessagingUtils.error(this.getClass(), e); |
|
94 |
} |
|
92 | 95 |
} |
93 | 96 |
} |
94 |
|
|
97 |
|
|
95 | 98 |
private Map<MetaDataPropertyName, String> getDefaultMetaDataMap(){ |
96 | 99 |
Map<MetaDataPropertyName, String> resultMap = new HashMap<MetaDataPropertyName, String>(MetaDataPropertyName.values().length); |
97 |
|
|
100 |
|
|
98 | 101 |
for(MetaDataPropertyName metaDataPropertyName : MetaDataPropertyName.values()){ |
99 | 102 |
resultMap.put(metaDataPropertyName, null); |
100 | 103 |
} |
101 |
|
|
104 |
|
|
102 | 105 |
return resultMap; |
103 | 106 |
} |
104 | 107 |
|
... | ... | |
110 | 113 |
public Map<MetaDataPropertyName, String> getMetaDataMap() { |
111 | 114 |
return metaDataMap; |
112 | 115 |
} |
113 |
|
|
116 |
|
|
114 | 117 |
/** |
115 | 118 |
* <p>isDataSourceCompatible</p> |
116 | 119 |
* |
... | ... | |
131 | 134 |
String property = metaDataMap.get(metaDataPropertyName); |
132 | 135 |
return property != null ? property : DEFAULT_ENTRY; |
133 | 136 |
} |
134 |
|
|
137 |
|
|
135 | 138 |
/** |
136 | 139 |
* <p>isRunning</p> |
137 | 140 |
* |
... | ... | |
140 | 143 |
public boolean isRunning() { |
141 | 144 |
return running; |
142 | 145 |
} |
143 |
|
|
146 |
|
|
144 | 147 |
/* (non-Javadoc) |
145 | 148 |
* @see java.lang.Object#toString() |
146 | 149 |
*/ |
Also available in: Unified diff
Shorten exception logged when CDMMETADATA is missing #5785