Revision 134 trunk/org.gvsig.spatialite/org.gvsig.spatialite.provider/src/main/java/org/gvsig/spatialite/dal/SpatiaLiteHelper.java
SpatiaLiteHelper.java | ||
---|---|---|
99 | 99 |
} |
100 | 100 |
|
101 | 101 |
public Connection getConnection() throws SQLException { |
102 |
boolean newDB = (connectionParameters.getFile()==null || !connectionParameters.getFile().exists()); |
|
102 | 103 |
if (this.dataSource == null) { |
103 | 104 |
this.dataSource = this.createDataSource(); |
104 | 105 |
} |
105 | 106 |
Connection conn = this.dataSource.getConnection(); |
106 | 107 |
loadExtension(conn); |
108 |
if (newDB) { |
|
109 |
initSpatialMetadata(conn); |
|
110 |
} |
|
107 | 111 |
return conn; |
108 | 112 |
} |
109 | 113 |
|
... | ... | |
167 | 171 |
} |
168 | 172 |
finally { |
169 | 173 |
JDBCUtils.closeQuietly(st); |
170 |
} |
|
171 |
try { |
|
172 |
st = conn.createStatement(); |
|
173 |
JDBCUtils.execute(st, "SELECT InitSpatialMetaData(1)"); |
|
174 |
} catch(Exception ex) { |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
public void initSpatialMetadata(Connection conn) { |
|
178 |
Statement st = null; |
|
179 |
try { |
|
180 |
st = conn.createStatement(); |
|
181 |
//harmless if already existing |
|
182 |
JDBCUtils.execute(st, "SELECT InitSpatialMetaData(1)"); |
|
183 |
} catch(Exception ex) { |
|
175 | 184 |
logger.warn("Can't initialize spatial metatada in SQLite database (" + |
176 | 185 |
" driver class "+StringUtils.defaultString(connectionParameters.getJDBCDriverClassName()) + |
177 | 186 |
" url format "+StringUtils.defaultString(connectionParameters.getURLFormat()) + |
178 | 187 |
" file "+connectionParameters.getFile()==null?"null":connectionParameters.getFile().getAbsolutePath() + |
179 | 188 |
").", ex); |
180 |
}
|
|
181 |
finally {
|
|
182 |
JDBCUtils.closeQuietly(st);
|
|
183 |
}
|
|
189 |
}
|
|
190 |
finally {
|
|
191 |
JDBCUtils.closeQuietly(st);
|
|
192 |
}
|
|
184 | 193 |
} |
194 |
|
|
185 | 195 |
} |
186 | 196 |
|
187 | 197 |
private ConnectionProvider connectionProvider = null; |
Also available in: Unified diff