Revision 45742
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialHelper.java | ||
---|---|---|
22 | 22 |
package org.gvsig.fmap.dal.store.h2; |
23 | 23 |
|
24 | 24 |
import java.io.File; |
25 |
import java.io.IOException; |
|
26 | 25 |
import java.sql.Connection; |
26 |
import java.sql.DriverManager; |
|
27 | 27 |
import java.sql.SQLException; |
28 | 28 |
import java.text.MessageFormat; |
29 |
import javax.activation.DataSource; |
|
29 | 30 |
import org.apache.commons.dbcp.BasicDataSource; |
30 | 31 |
import org.apache.commons.io.FilenameUtils; |
31 | 32 |
import org.apache.commons.lang3.StringUtils; |
... | ... | |
146 | 147 |
|
147 | 148 |
@Override |
148 | 149 |
public String getStatus() { |
150 |
if(dataSource == null) { |
|
151 |
return "Not using pool."; |
|
152 |
} |
|
149 | 153 |
StringBuilder builder = new StringBuilder(); |
150 | 154 |
builder.append("Pool: "); |
151 | 155 |
builder.append(JDBCUtils.getHexId(dataSource)); |
... | ... | |
172 | 176 |
} catch (Throwable th) { |
173 | 177 |
LOGGER.warn("Problems shutdown the database.", th); |
174 | 178 |
} |
175 |
try { |
|
176 |
if( dataSource!=null ) { |
|
177 |
LOGGER.info("Clossing connection pool."); |
|
178 |
LOGGER.info(this.getStatus()); |
|
179 |
dataSource.close(); |
|
180 |
LOGGER.info("Connection pool closed."); |
|
181 |
LOGGER.info(this.getStatus()); |
|
182 |
} |
|
183 |
} catch (Throwable th) { |
|
184 |
LOGGER.warn("Problems closing connections pool.", th); |
|
185 |
} |
|
179 |
closeDataSource(); |
|
186 | 180 |
} |
187 | 181 |
|
188 | 182 |
public static void stopServer() { |
... | ... | |
262 | 256 |
File f = H2SpatialHelper.getLocalFile(connectionParameters); |
263 | 257 |
boolean newdb = !f.exists(); |
264 | 258 |
|
265 |
if (this.dataSource == null) { |
|
266 |
this.dataSource = this.createDataSource(); |
|
267 |
} |
|
268 | 259 |
Connection conn; |
260 |
|
|
269 | 261 |
try { |
270 |
conn = this.dataSource.getConnection(); |
|
262 |
conn = DriverManager.getConnection( |
|
263 |
connectionParameters.getUrl(), |
|
264 |
connectionParameters.getUser(), |
|
265 |
connectionParameters.getPassword() |
|
266 |
); |
|
267 |
|
|
271 | 268 |
} catch(Throwable th) { |
272 |
LOGGER.warn("Can't create connection to '"+this.dataSource.getUrl()+"'. "+this.getStatus()); |
|
273 |
LOGGER.warn("Can't create connection to '"+this.dataSource.getUrl()+"'.",th); |
|
274 | 269 |
throw th; |
275 | 270 |
} |
271 |
|
|
272 |
|
|
273 |
// if (this.dataSource == null) { |
|
274 |
// this.dataSource = this.createDataSource(); |
|
275 |
// } |
|
276 |
// |
|
277 |
// try { |
|
278 |
// conn = this.dataSource.getConnection(); |
|
279 |
// } catch(Throwable th) { |
|
280 |
// LOGGER.warn("Can't create connection to '"+this.dataSource.getUrl()+"'. "+this.getStatus()); |
|
281 |
// LOGGER.warn("Can't create connection to '"+this.dataSource.getUrl()+"'.",th); |
|
282 |
// throw th; |
|
283 |
// } |
|
284 |
|
|
285 |
|
|
276 | 286 |
try { |
277 | 287 |
conn.createStatement().execute("SELECT TOP 1 SRID FROM SPATIAL_REF_SYS"); |
278 | 288 |
} catch(SQLException ex) { |
... | ... | |
374 | 384 |
|
375 | 385 |
@Override |
376 | 386 |
public void dispose() { |
377 |
if( this.dataSource!=null ) { |
|
378 |
try { |
|
379 |
this.dataSource.close(); |
|
380 |
} catch (SQLException ex) { |
|
381 |
LOGGER.warn("Can't close BasicDataSource", ex); |
|
387 |
closeDataSource(); |
|
388 |
this.connectionParameters = null; |
|
389 |
} |
|
390 |
|
|
391 |
private void closeDataSource() { |
|
392 |
try { |
|
393 |
if( dataSource!=null ) { |
|
394 |
LOGGER.info("Clossing connection pool."); |
|
395 |
LOGGER.info(this.getStatus()); |
|
396 |
dataSource.close(); |
|
397 |
dataSource = null; |
|
398 |
LOGGER.info("Connection pool closed."); |
|
399 |
LOGGER.info(this.getStatus()); |
|
382 | 400 |
} |
383 |
this.dataSource = null; |
|
401 |
} catch (Throwable th) { |
|
402 |
LOGGER.warn("Problems closing connections pool.", th); |
|
384 | 403 |
} |
385 |
this.connectionParameters = null; |
|
404 |
|
|
386 | 405 |
} |
387 | 406 |
|
388 | 407 |
} |
... | ... | |
601 | 620 |
return explorer; |
602 | 621 |
} |
603 | 622 |
|
623 |
public String getConnectionProviderStatus(){ |
|
624 |
return this.getConnectionProvider().getStatus(); |
|
625 |
} |
|
626 |
|
|
627 |
|
|
604 | 628 |
} |
Also available in: Unified diff