Revision 35 trunk/org.gvsig.spatialite/org.gvsig.spatialite.provider/src/main/java/org/gvsig/spatialite/dal/SpatiaLiteHelper.java
SpatiaLiteHelper.java | ||
---|---|---|
24 | 24 |
import org.gvsig.spatialite.dal.operations.SpatiaLiteOperationsFactory; |
25 | 25 |
import java.sql.Connection; |
26 | 26 |
import java.sql.SQLException; |
27 |
import java.sql.Statement; |
|
27 | 28 |
import org.apache.commons.dbcp.BasicDataSource; |
28 | 29 |
import org.apache.commons.lang3.BooleanUtils; |
29 | 30 |
import org.cresques.cts.IProjection; |
... | ... | |
34 | 35 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
35 | 36 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
36 | 37 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException; |
38 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
|
37 | 39 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
38 | 40 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase; |
39 | 41 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
42 |
import org.gvsig.fmap.geom.Geometry; |
|
43 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
|
44 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
45 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
|
46 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
47 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
48 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
40 | 49 |
import org.slf4j.Logger; |
41 | 50 |
import org.slf4j.LoggerFactory; |
42 | 51 |
|
... | ... | |
66 | 75 |
} |
67 | 76 |
|
68 | 77 |
public Connection getConnection() throws SQLException { |
78 |
boolean newdb = !connectionParameters.getFile().exists(); |
|
69 | 79 |
if (this.dataSource == null) { |
70 | 80 |
this.dataSource = this.createDataSource(); |
71 | 81 |
} |
72 | 82 |
Connection conn = this.dataSource.getConnection(); |
83 |
if( newdb ) { |
|
84 |
Statement st = conn.createStatement(); |
|
85 |
JDBCUtils.executeQuery(st, "SELECT InitSpatialMetaData(1)"); |
|
86 |
} |
|
73 | 87 |
return conn; |
74 | 88 |
} |
75 | 89 |
|
... | ... | |
244 | 258 |
return new SpatiaLiteExplorerParameters(); |
245 | 259 |
} |
246 | 260 |
|
261 |
public Geometry forceGeometryType(GeometryType geomtype, Geometry geom) throws CreateGeometryException { |
|
262 |
switch( geomtype.getType() ) { |
|
263 |
case Geometry.TYPES.MULTIPOLYGON: |
|
264 |
if( geom.getType()==Geometry.TYPES.POLYGON ) { |
|
265 |
MultiPolygon x = getGeometryManager().createMultiPolygon(geomtype.getSubType()); |
|
266 |
x.addPrimitive((Primitive) geom); |
|
267 |
geom = x; |
|
268 |
} |
|
269 |
break; |
|
270 |
case Geometry.TYPES.MULTILINE: |
|
271 |
if( geom.getType()==Geometry.TYPES.LINE ) { |
|
272 |
MultiLine x = getGeometryManager().createMultiLine(geomtype.getSubType()); |
|
273 |
x.addPrimitive((Primitive) geom); |
|
274 |
geom = x; |
|
275 |
} |
|
276 |
break; |
|
277 |
case Geometry.TYPES.MULTIPOINT: |
|
278 |
if( geom.getType()==Geometry.TYPES.POINT ) { |
|
279 |
MultiLine x = getGeometryManager().createMultiLine(geomtype.getSubType()); |
|
280 |
x.addPrimitive((Primitive) geom); |
|
281 |
geom = x; |
|
282 |
} |
|
283 |
break; |
|
284 |
case Geometry.TYPES.POLYGON: |
|
285 |
if( geom.getType()==Geometry.TYPES.MULTIPOLYGON ) { |
|
286 |
MultiPolygon x = (MultiPolygon) geom; |
|
287 |
if( x.getPrimitivesNumber()==1 ) { |
|
288 |
geom = x.getPrimitiveAt(0); |
|
289 |
} |
|
290 |
} |
|
291 |
break; |
|
292 |
case Geometry.TYPES.LINE: |
|
293 |
if( geom.getType()==Geometry.TYPES.MULTILINE ) { |
|
294 |
MultiLine x = (MultiLine) geom; |
|
295 |
if( x.getPrimitivesNumber()==1 ) { |
|
296 |
geom = x.getPrimitiveAt(0); |
|
297 |
} |
|
298 |
} |
|
299 |
break; |
|
300 |
case Geometry.TYPES.POINT: |
|
301 |
if( geom.getType()==Geometry.TYPES.MULTIPOINT ) { |
|
302 |
MultiPoint x = (MultiPoint) geom; |
|
303 |
if( x.getPrimitivesNumber()==1 ) { |
|
304 |
geom = x.getPrimitiveAt(0); |
|
305 |
} |
|
306 |
} |
|
307 |
} |
|
308 |
return geom; |
|
309 |
} |
|
310 |
|
|
247 | 311 |
} |
Also available in: Unified diff