Revision 44198 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialHelper.java
H2SpatialHelper.java | ||
---|---|---|
27 | 27 |
import org.apache.commons.dbcp.BasicDataSource; |
28 | 28 |
import org.apache.commons.io.FilenameUtils; |
29 | 29 |
import org.apache.commons.lang3.StringUtils; |
30 |
import org.gvsig.fmap.dal.SQLBuilder;
|
|
30 |
import org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType;
|
|
31 | 31 |
import org.gvsig.fmap.dal.exception.InitializeException; |
32 | 32 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
33 | 33 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
... | ... | |
48 | 48 |
import org.slf4j.Logger; |
49 | 49 |
import org.slf4j.LoggerFactory; |
50 | 50 |
|
51 |
@SuppressWarnings("UseSpecificCatch") |
|
51 | 52 |
public class H2SpatialHelper extends JDBCHelperBase { |
52 | 53 |
|
53 |
static final Logger logger = LoggerFactory.getLogger(H2SpatialHelper.class);
|
|
54 |
static final Logger LOGGER = LoggerFactory.getLogger(H2SpatialHelper.class);
|
|
54 | 55 |
|
55 |
public static final String H2SpatialJDBCDriver = "org.h2.Driver";
|
|
56 |
public static final String H2SPATIAL_JDBC_DRIVER = "org.h2.Driver";
|
|
56 | 57 |
|
57 | 58 |
public static String getConnectionURL(H2SpatialConnectionParameters params) { |
58 | 59 |
String connectionURL; |
... | ... | |
88 | 89 |
dbfilename |
89 | 90 |
); |
90 | 91 |
} |
91 |
logger.debug("connectionURL: {}", connectionURL);
|
|
92 |
LOGGER.debug("connectionURL: {}", connectionURL);
|
|
92 | 93 |
return connectionURL; |
93 | 94 |
} |
94 | 95 |
|
... | ... | |
115 | 116 |
Server theServer = Server.createTcpServer("-tcpPort", port, /*"-tcpAllowOthers",*/ "-ifExists"); |
116 | 117 |
theServer.start(); |
117 | 118 |
server = theServer; |
118 |
logger.info("H2 Server started" );
|
|
119 |
logger.info(" port :"+ server.getPort());
|
|
120 |
logger.info(" status:"+ server.getStatus());
|
|
119 |
LOGGER.info("H2 Server started" );
|
|
120 |
LOGGER.info(" port :"+ server.getPort());
|
|
121 |
LOGGER.info(" status:"+ server.getStatus());
|
|
121 | 122 |
} catch (SQLException ex) { |
122 |
logger.warn("H2 Server not started",ex);
|
|
123 |
LOGGER.warn("H2 Server not started",ex);
|
|
123 | 124 |
} |
124 | 125 |
// Tanto si consigue lanzar el server como si no, no lo vuelve a intentar |
125 | 126 |
startServer = false; |
... | ... | |
192 | 193 |
|
193 | 194 |
} |
194 | 195 |
|
195 |
// private static class ConnectionProvider { |
|
196 |
// |
|
197 |
// private static boolean needRegisterDriver = true; |
|
198 |
// |
|
199 |
// |
|
200 |
// private final H2SpatialConnectionParameters connectionParameters; |
|
201 |
// |
|
202 |
// public ConnectionProvider(H2SpatialConnectionParameters connectionParameters) { |
|
203 |
// this.connectionParameters = connectionParameters; |
|
204 |
// } |
|
205 |
// |
|
206 |
// public Connection getConnection() throws SQLException { |
|
207 |
// if (!this.isRegistered()) { |
|
208 |
// this.registerDriver(); |
|
209 |
// } |
|
210 |
// Connection conn; |
|
211 |
// if( !StringUtils.isEmpty(connectionParameters.getUser()) ) { |
|
212 |
// conn = DriverManager.getConnection( |
|
213 |
// connectionParameters.getUrl(), |
|
214 |
// connectionParameters.getUser(), |
|
215 |
// connectionParameters.getPassword() |
|
216 |
// ); |
|
217 |
// } else { |
|
218 |
// conn = DriverManager.getConnection(connectionParameters.getUrl()); |
|
219 |
// } |
|
220 |
// try { |
|
221 |
// conn.createStatement().execute("SELECT TOP 1 SRID FROM SPATIAL_REF_SYS"); |
|
222 |
// } catch(SQLException ex) { |
|
223 |
// H2GISExtension.load(conn); |
|
224 |
// } |
|
225 |
// return conn; |
|
226 |
// } |
|
227 |
// |
|
228 |
// private boolean isRegistered() { |
|
229 |
// return needRegisterDriver; |
|
230 |
// } |
|
231 |
// |
|
232 |
// public void registerDriver() throws SQLException { |
|
233 |
// String className = this.connectionParameters.getJDBCDriverClassName(); |
|
234 |
// if (className == null) { |
|
235 |
// return; |
|
236 |
// } |
|
237 |
// try { |
|
238 |
// Class theClass = Class.forName(className); |
|
239 |
// if (theClass == null) { |
|
240 |
// throw new JDBCDriverClassNotFoundException(H2SpatialLibrary.NAME, className); |
|
241 |
// } |
|
242 |
// } catch (Exception e) { |
|
243 |
// throw new SQLException("Can't register JDBC driver '" + className + "'.", e); |
|
244 |
// } |
|
245 |
// needRegisterDriver = false; |
|
246 |
// } |
|
247 |
// |
|
248 |
// } |
|
249 |
|
|
250 | 196 |
private ConnectionProvider connectionProvider = null; |
251 | 197 |
|
252 | 198 |
public H2SpatialHelper(JDBCConnectionParameters connectionParameters) { |
... | ... | |
261 | 207 |
this.connectionProvider = new ConnectionProvider(this.getConnectionParameters()); |
262 | 208 |
} |
263 | 209 |
Connection connection = this.connectionProvider.getConnection(); |
264 |
if( logger.isDebugEnabled() ) {
|
|
265 |
logger.debug("getConnection: connection = "+connection.hashCode()+ connectionProvider.toString());
|
|
210 |
if( LOGGER.isDebugEnabled() ) {
|
|
211 |
LOGGER.debug("getConnection: connection = "+connection.hashCode()+ connectionProvider.toString());
|
|
266 | 212 |
} |
267 | 213 |
return connection; |
268 | 214 |
} catch (SQLException ex) { |
... | ... | |
272 | 218 |
|
273 | 219 |
@Override |
274 | 220 |
public void closeConnection(Connection connection) { |
275 |
logger.debug("closeConnection: connection = "+connection.hashCode());
|
|
221 |
LOGGER.debug("closeConnection: connection = "+connection.hashCode());
|
|
276 | 222 |
super.closeConnection(connection); |
277 | 223 |
} |
278 | 224 |
|
... | ... | |
310 | 256 |
} |
311 | 257 |
|
312 | 258 |
@Override |
313 |
public SQLBuilder.GeometrySupportType getGeometrySupportType() {
|
|
314 |
return SQLBuilder.GeometrySupportType.WKB;
|
|
259 |
public GeometrySupportType getGeometrySupportType() { |
|
260 |
return GeometrySupportType.WKB; |
|
315 | 261 |
} |
316 | 262 |
|
317 | 263 |
@Override |
Also available in: Unified diff