svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.sqlite / org.gvsig.sqlite.provider / src / main / java / org / gvsig / sqlite / dal / geopackage / GeopackageGeometryColumns.java @ 47456
History | View | Annotate | Download (4.18 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.sqlite.dal.geopackage; |
7 |
|
8 |
import java.sql.ResultSet; |
9 |
import java.sql.SQLException; |
10 |
import java.sql.Statement; |
11 |
import java.util.Map; |
12 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
13 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
14 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
15 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
16 |
import org.gvsig.sqlite.dal.operations.SQLiteFetchFeatureTypeOperation; |
17 |
import org.gvsig.sqlite.dal.operations.SQLiteFetchFeatureTypeOperation.SQLiteColumnInfo; |
18 |
import org.sqlite.SQLiteException; |
19 |
|
20 |
/**
|
21 |
*
|
22 |
* @author jjdelcerro
|
23 |
*/
|
24 |
public class GeopackageGeometryColumns { |
25 |
|
26 |
|
27 |
public static class GeopackageGeometryColumn extends SQLiteFetchFeatureTypeOperation.SQLiteColumnInfo { |
28 |
|
29 |
private String geometry_type_name; |
30 |
private int srs_id; |
31 |
private int z; |
32 |
private int m; |
33 |
|
34 |
/*friend*/ GeopackageGeometryColumn() {
|
35 |
super();
|
36 |
} |
37 |
|
38 |
public void set( |
39 |
String table_name,
|
40 |
String column_column,
|
41 |
String geometry_type_name,
|
42 |
int srs_id,
|
43 |
int z,
|
44 |
int m
|
45 |
) { |
46 |
this.table_name = table_name;
|
47 |
this.column_column = column_column;
|
48 |
this.geometry_type_name = geometry_type_name;
|
49 |
this.srs_id = srs_id;
|
50 |
this.z = z;
|
51 |
this.m = m;
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* @return the geometry_type_name
|
56 |
*/
|
57 |
public String getGeometry_type_name() { |
58 |
return geometry_type_name;
|
59 |
} |
60 |
|
61 |
/**
|
62 |
* @return the srs_id
|
63 |
*/
|
64 |
public int getSrs_id() { |
65 |
return srs_id;
|
66 |
} |
67 |
|
68 |
/**
|
69 |
* @return the z
|
70 |
*/
|
71 |
public int getZ() { |
72 |
return z;
|
73 |
} |
74 |
|
75 |
/**
|
76 |
* @return the m
|
77 |
*/
|
78 |
public int getM() { |
79 |
return m;
|
80 |
} |
81 |
|
82 |
} |
83 |
|
84 |
/*friend*/ static void load_gpkg_geometry_columns(Map<String,SQLiteColumnInfo> columns_info, JDBCConnection conn, String tableName, JDBCSQLBuilderBase sqlbuilder) { |
85 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
86 |
sqlbuilder.select().column().name("table_name");
|
87 |
sqlbuilder.select().column().name("column_name");
|
88 |
sqlbuilder.select().column().name("geometry_type_name");
|
89 |
sqlbuilder.select().column().name("srs_id");
|
90 |
sqlbuilder.select().column().name("z");
|
91 |
sqlbuilder.select().column().name("m");
|
92 |
sqlbuilder.select().where().set( |
93 |
expbuilder.eq( |
94 |
expbuilder.column("table_name"),
|
95 |
expbuilder.constant(tableName) |
96 |
) |
97 |
); |
98 |
sqlbuilder.select().from().table().name("gpkg_geometry_columns");
|
99 |
Statement st = null; |
100 |
ResultSet rs = null; |
101 |
try {
|
102 |
st = conn.createStatement(); |
103 |
rs = JDBCUtils.executeQuery(st, sqlbuilder.toString()); |
104 |
while( rs.next() ) {
|
105 |
String columnname = rs.getString("column_name"); |
106 |
GeopackageGeometryColumn geominfo = new GeopackageGeometryColumn();
|
107 |
geominfo.copyfrom(columns_info.get(columnname)); |
108 |
geominfo.set( |
109 |
rs.getString("table_name"),
|
110 |
columnname, |
111 |
rs.getString("geometry_type_name"),
|
112 |
rs.getInt("srs_id"),
|
113 |
rs.getInt("z"),
|
114 |
rs.getInt("m")
|
115 |
); |
116 |
columns_info.put(columnname, geominfo); |
117 |
} |
118 |
} catch(SQLiteException ex) {
|
119 |
if( !ex.getMessage().contains("no such table") ) { |
120 |
throw new RuntimeException("Can't load information from table gpkg_geometry_columns",ex); |
121 |
} |
122 |
} catch (Throwable ex) { |
123 |
throw new RuntimeException("Can't load information from table gpkg_geometry_columns",ex); |
124 |
} finally {
|
125 |
JDBCUtils.closeQuietly(rs); |
126 |
JDBCUtils.closeQuietly(st); |
127 |
} |
128 |
} |
129 |
|
130 |
} |