Revision 21743 branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/SingleVectorialDBConnectionExtension.java
SingleVectorialDBConnectionExtension.java | ||
---|---|---|
47 | 47 |
import javax.swing.JOptionPane; |
48 | 48 |
|
49 | 49 |
import org.apache.log4j.Logger; |
50 |
import org.gvsig.fmap.drivers.formats.db.utils.ConnectionWithParams; |
|
51 |
import org.gvsig.fmap.drivers.formats.db.utils.SingleVectorialDBConnectionManager; |
|
52 |
import org.gvsig.fmap.drivers.reading.DBException; |
|
53 | 50 |
|
54 | 51 |
import com.iver.andami.PluginServices; |
55 | 52 |
import com.iver.andami.plugins.Extension; |
... | ... | |
119 | 116 |
xml.putProperty("literalDBName",true); |
120 | 117 |
xml.remove("db-connections"); |
121 | 118 |
|
122 |
ConnectionWithParams[] all = SingleVectorialDBConnectionManager.instance() |
|
123 |
.getAllConnections(); |
|
124 |
|
|
125 |
if (all == null) { |
|
126 |
PluginServices.getPluginServices(ext).setPersistentXML(xml); |
|
127 |
return; |
|
128 |
} |
|
129 |
|
|
130 |
for (int i = 0; i < all.length; i++) { |
|
131 |
addToPersistence(all[i],ext); |
|
132 |
} |
|
119 |
// ConnectionWithParams[] all = SingleVectorialDBConnectionManager.instance()
|
|
120 |
// .getAllConnections();
|
|
121 |
// |
|
122 |
// if (all == null) {
|
|
123 |
// PluginServices.getPluginServices(ext).setPersistentXML(xml);
|
|
124 |
// return;
|
|
125 |
// }
|
|
126 |
// |
|
127 |
// for (int i = 0; i < all.length; i++) {
|
|
128 |
// addToPersistence(all[i],ext);
|
|
129 |
// }
|
|
133 | 130 |
} |
134 | 131 |
|
135 |
private static void addToPersistence(ConnectionWithParams cwp, Extension ext) { |
|
136 |
if (cwp == null) { |
|
137 |
return; |
|
138 |
} |
|
132 |
// private static void addToPersistence(ConnectionWithParams cwp, Extension ext) { |
|
133 |
// if (cwp == null) { |
|
134 |
// return; |
|
135 |
// } |
|
136 |
// |
|
137 |
// ConnectionSettings _cs = new ConnectionSettings(); |
|
138 |
// |
|
139 |
// _cs.setHost(cwp.getHost()); |
|
140 |
// _cs.setPort(cwp.getPort()); |
|
141 |
// _cs.setDb(cwp.getDb()); |
|
142 |
// _cs.setDriver(cwp.getDrvName()); |
|
143 |
// _cs.setUser(cwp.getUser()); |
|
144 |
// _cs.setName(cwp.getName()); |
|
145 |
// |
|
146 |
// String newstr = _cs.toString(); |
|
147 |
// |
|
148 |
// XMLEntity xml = PluginServices.getPluginServices(ext).getPersistentXML(); |
|
149 |
// |
|
150 |
// String[] old = null; |
|
151 |
// |
|
152 |
// if (xml.contains("db-connections")) { |
|
153 |
// old = xml.getStringArrayProperty("db-connections"); |
|
154 |
// } |
|
155 |
// |
|
156 |
// ArrayList oldl = stringArrayToArrayList(old); |
|
157 |
// oldl.add(newstr); |
|
158 |
// |
|
159 |
// String[] newarr = (String[]) oldl.toArray(new String[0]); |
|
160 |
// |
|
161 |
// xml.remove("db-connections"); |
|
162 |
// xml.putProperty("db-connections", newarr); |
|
163 |
// PluginServices.getPluginServices(ext).setPersistentXML(xml); |
|
164 |
// } |
|
139 | 165 |
|
140 |
ConnectionSettings _cs = new ConnectionSettings(); |
|
141 |
|
|
142 |
_cs.setHost(cwp.getHost()); |
|
143 |
_cs.setPort(cwp.getPort()); |
|
144 |
_cs.setDb(cwp.getDb()); |
|
145 |
_cs.setDriver(cwp.getDrvName()); |
|
146 |
_cs.setUser(cwp.getUser()); |
|
147 |
_cs.setName(cwp.getName()); |
|
148 |
|
|
149 |
String newstr = _cs.toString(); |
|
150 |
|
|
151 |
XMLEntity xml = PluginServices.getPluginServices(ext).getPersistentXML(); |
|
152 |
|
|
153 |
String[] old = null; |
|
154 |
|
|
155 |
if (xml.contains("db-connections")) { |
|
156 |
old = xml.getStringArrayProperty("db-connections"); |
|
157 |
} |
|
158 |
|
|
159 |
ArrayList oldl = stringArrayToArrayList(old); |
|
160 |
oldl.add(newstr); |
|
161 |
|
|
162 |
String[] newarr = (String[]) oldl.toArray(new String[0]); |
|
163 |
|
|
164 |
xml.remove("db-connections"); |
|
165 |
xml.putProperty("db-connections", newarr); |
|
166 |
PluginServices.getPluginServices(ext).setPersistentXML(xml); |
|
167 |
} |
|
168 |
|
|
169 | 166 |
private static ArrayList stringArrayToArrayList(String[] arr) { |
170 | 167 |
ArrayList resp = new ArrayList(); |
171 | 168 |
|
... | ... | |
268 | 265 |
} |
269 | 266 |
|
270 | 267 |
private void addDisconnected(ConnectionSettings _cs) { |
271 |
try { |
|
272 |
SingleVectorialDBConnectionManager.instance() |
|
273 |
.getConnection(_cs.getDriver(), |
|
274 |
_cs.getUser(), null, _cs.getName(), _cs.getHost(), |
|
275 |
_cs.getPort(), _cs.getDb(), false); |
|
276 |
} |
|
277 |
catch (DBException e) { |
|
278 |
System.err.println("While getting connection: " + e.getMessage()); |
|
279 |
showConnectionErrorMessage(e.getMessage()); |
|
280 |
} |
|
268 |
// try {
|
|
269 |
// SingleVectorialDBConnectionManager.instance()
|
|
270 |
// .getConnection(_cs.getDriver(),
|
|
271 |
// _cs.getUser(), null, _cs.getName(), _cs.getHost(),
|
|
272 |
// _cs.getPort(), _cs.getDb(), false);
|
|
273 |
// }
|
|
274 |
// catch (DBException e) {
|
|
275 |
// System.err.println("While getting connection: " + e.getMessage());
|
|
276 |
// showConnectionErrorMessage(e.getMessage());
|
|
277 |
// }
|
|
281 | 278 |
} |
282 | 279 |
|
283 | 280 |
private void showConnectionErrorMessage(String _msg) { |
... | ... | |
289 | 286 |
|
290 | 287 |
public void terminate() { |
291 | 288 |
saveAllToPersistence(); |
292 |
SingleVectorialDBConnectionManager.instance().closeAllBeforeTerminate(); |
|
289 |
// SingleVectorialDBConnectionManager.instance().closeAllBeforeTerminate();
|
|
293 | 290 |
} |
294 | 291 |
} |
Also available in: Unified diff