Revision 913
org.gvsig.oracle/trunk/org.gvsig.oracle/org.gvsig.oracle.provider/src/test/resources/org/gvsig/oracle/dal/operations/sql/createTable.sql | ||
---|---|---|
97 | 97 |
F_TABLE_SCHEMA, F_TABLE_NAME, F_GEOMETRY_COLUMN, GEOMETRY_TYPE) |
98 | 98 |
VALUES ('P1', 'TEST', 'GEOMETRY', 1); |
99 | 99 |
|
100 |
|
|
101 |
-- Create table with Index 3D geometry |
|
102 |
|
|
103 |
CREATE TABLE "P1"."TEST" ( |
|
104 |
"ID" NUMBER(9,0), |
|
105 |
"Byte" NUMBER(3,0) DEFAULT NULL, |
|
106 |
"Bool1" CHAR(1) DEFAULT NULL, |
|
107 |
"Long" NUMBER(18,0) DEFAULT NULL, |
|
108 |
"Timestamp" TIMESTAMP DEFAULT NULL, |
|
109 |
"Date" DATE DEFAULT NULL, |
|
110 |
"Time" TIMESTAMP DEFAULT NULL, |
|
111 |
"Bool2" CHAR(1) DEFAULT NULL, |
|
112 |
"String" NVARCHAR2(30) DEFAULT NULL, |
|
113 |
"Bool3" CHAR(1) DEFAULT NULL, |
|
114 |
"Double" BINARY_DOUBLE DEFAULT NULL, |
|
115 |
"Bool4" CHAR(1) DEFAULT NULL, |
|
116 |
"Float" BINARY_FLOAT DEFAULT NULL, |
|
117 |
"Bool5" CHAR(1) DEFAULT NULL, |
|
118 |
"Decimal" NUMBER(6,3) DEFAULT NULL, |
|
119 |
"GEOMETRY" SDO_GEOMETRY DEFAULT NULL |
|
120 |
); |
|
121 |
|
|
122 |
ALTER TABLE "P1"."TEST" ADD PRIMARY KEY ("ID"); |
|
123 |
|
|
124 |
DELETE FROM MDSYS.OGIS_GEOMETRY_COLUMNS |
|
125 |
WHERE F_TABLE_SCHEMA = 'P1' |
|
126 |
AND F_TABLE_NAME = 'TEST' |
|
127 |
AND F_GEOMETRY_COLUMN = 'GEOMETRY'; |
|
128 |
|
|
129 |
INSERT INTO MDSYS.OGIS_GEOMETRY_COLUMNS ( |
|
130 |
F_TABLE_SCHEMA, F_TABLE_NAME, F_GEOMETRY_COLUMN, GEOMETRY_TYPE) |
|
131 |
VALUES ('P1', 'TEST', 'GEOMETRY', 1001); |
|
132 |
|
|
133 |
CREATE INDEX "SDX_TEST_GEOMETRY" ON "TEST" ("Geometry") INDEXTYPE IS MDSYS.SPATIAL_INDEX PARAMETERS ('SDO_INDX_DIMS=3,LAYER_GTYPE=POINT'); |
|
134 |
|
|
135 |
ALTER INDEX "SDX_TEST_GEOMETRY" REBUILD PARAMETERS ('SDO_INDX_DIMS=3,LAYER_GTYPE=POINT'); |
|
136 |
|
|
137 |
-- Create table with Index 2D geometry |
|
138 |
|
|
139 |
CREATE TABLE "P1"."TEST" ( |
|
140 |
"ID" NUMBER(9,0), |
|
141 |
"Byte" NUMBER(3,0) DEFAULT NULL, |
|
142 |
"Bool1" CHAR(1) DEFAULT NULL, |
|
143 |
"Long" NUMBER(18,0) DEFAULT NULL, |
|
144 |
"Timestamp" TIMESTAMP DEFAULT NULL, |
|
145 |
"Date" DATE DEFAULT NULL, |
|
146 |
"Time" TIMESTAMP DEFAULT NULL, |
|
147 |
"Bool2" CHAR(1) DEFAULT NULL, |
|
148 |
"String" NVARCHAR2(30) DEFAULT NULL, |
|
149 |
"Bool3" CHAR(1) DEFAULT NULL, |
|
150 |
"Double" BINARY_DOUBLE DEFAULT NULL, |
|
151 |
"Bool4" CHAR(1) DEFAULT NULL, |
|
152 |
"Float" BINARY_FLOAT DEFAULT NULL, |
|
153 |
"Bool5" CHAR(1) DEFAULT NULL, |
|
154 |
"Decimal" NUMBER(6,3) DEFAULT NULL, |
|
155 |
"GEOMETRY" SDO_GEOMETRY DEFAULT NULL |
|
156 |
); |
|
157 |
|
|
158 |
ALTER TABLE "P1"."TEST" ADD PRIMARY KEY ("ID"); |
|
159 |
|
|
160 |
DELETE FROM MDSYS.OGIS_GEOMETRY_COLUMNS |
|
161 |
WHERE F_TABLE_SCHEMA = 'P1' |
|
162 |
AND F_TABLE_NAME = 'TEST' |
|
163 |
AND F_GEOMETRY_COLUMN = 'GEOMETRY'; |
|
164 |
|
|
165 |
INSERT INTO MDSYS.OGIS_GEOMETRY_COLUMNS ( |
|
166 |
F_TABLE_SCHEMA, F_TABLE_NAME, F_GEOMETRY_COLUMN, GEOMETRY_TYPE) |
|
167 |
VALUES ('P1', 'TEST', 'GEOMETRY', 1); |
|
168 |
|
|
169 |
CREATE INDEX "SDX_TEST_GEOMETRY" ON "TEST" ("Geometry") INDEXTYPE IS MDSYS.SPATIAL_INDEX PARAMETERS ('SDO_INDX_DIMS=2,LAYER_GTYPE=POINT'); |
|
170 |
|
|
171 |
ALTER INDEX "SDX_TEST_GEOMETRY" REBUILD PARAMETERS ('SDO_INDX_DIMS=2,LAYER_GTYPE=POINT'); |
|
172 |
|
org.gvsig.oracle/trunk/org.gvsig.oracle/org.gvsig.oracle.provider/src/test/java/org/gvsig/oracle/dal/operations/sql/TestCreateTable.java | ||
---|---|---|
5 | 5 |
import java.util.List; |
6 | 6 |
import junit.framework.TestCase; |
7 | 7 |
import org.gvsig.fmap.dal.DataManager; |
8 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
8 | 9 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
9 | 10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
10 | 11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
... | ... | |
13 | 14 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
14 | 15 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
15 | 16 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CreateTableOperation; |
17 |
import org.gvsig.fmap.geom.Geometry; |
|
18 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
19 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
20 |
import org.gvsig.oracle.dal.SpatialIndexUtils; |
|
16 | 21 |
import org.gvsig.oracle.dal.TestUtils; |
17 | 22 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
18 | 23 |
import org.slf4j.Logger; |
... | ... | |
63 | 68 |
null |
64 | 69 |
); |
65 | 70 |
List<String> SQLs = createTable.getSQLs(); |
66 |
int sz = expectedSQLs.size(); |
|
67 | 71 |
int offset = 0; |
68 |
int max = sz/3;
|
|
72 |
int max = 4;
|
|
69 | 73 |
assertEquals("CreateTable num. SQLs", max, SQLs.size()); |
70 | 74 |
for (int i = 0; i < max; i++) { |
71 | 75 |
System.out.println("###### SQL "+i+":"+SQLs.get(i)); |
... | ... | |
101 | 105 |
null |
102 | 106 |
); |
103 | 107 |
List<String> SQLs = createTable.getSQLs(); |
104 |
int sz = expectedSQLs.size(); |
|
105 |
int offset = (sz/3); |
|
106 |
int max = sz/3; |
|
108 |
int max = 4; |
|
109 |
int offset = 4; |
|
107 | 110 |
assertEquals("CreateTable num. SQLs", max, SQLs.size()); |
108 | 111 |
for (int i = 0; i < max; i++) { |
109 | 112 |
System.out.println("###### SQL "+i+":"+SQLs.get(i)); |
... | ... | |
138 | 141 |
null |
139 | 142 |
); |
140 | 143 |
List<String> SQLs = createTable.getSQLs(); |
141 |
int sz = expectedSQLs.size(); |
|
142 |
int offset = (sz/3)*2; |
|
143 |
int max = sz/3; |
|
144 |
int max = 4; |
|
145 |
int offset = 4*2; |
|
144 | 146 |
assertEquals("CreateTable num. SQLs", max, SQLs.size()); |
145 | 147 |
for (int i = 0; i < max; i++) { |
146 | 148 |
System.out.println("###### SQL "+i+":"+SQLs.get(i)); |
... | ... | |
150 | 152 |
|
151 | 153 |
} |
152 | 154 |
|
155 |
public void testCreateTableIndex3D() throws Exception { |
|
156 |
JDBCHelper helper = TestUtils.getJDBCHelper(); |
|
157 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
158 |
OperationsFactory operations = helper.getOperations(); |
|
159 |
|
|
160 |
List<String> expectedSQLs = TestUtils.getSQLs("createTable.sql"); |
|
161 |
|
|
162 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
163 |
Envelope env = sourceStore.getEnvelope(); |
|
164 |
|
|
165 |
TableReference table = operations.createTableReference( |
|
166 |
"dbtest", |
|
167 |
sqlbuilder.default_schema(), |
|
168 |
"test", |
|
169 |
null |
|
170 |
); |
|
171 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
172 |
EditableFeatureType eft = featureType.getEditable(); |
|
173 |
EditableFeatureAttributeDescriptor attrgeom = eft.getEditableAttributeDescriptor("Geometry"); |
|
174 |
attrgeom.setGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3D); |
|
175 |
attrgeom.setIsIndexed(true); |
|
176 |
CreateTableOperation createTable = operations.createTable( |
|
177 |
table, |
|
178 |
eft.getNotEditableCopy(), |
|
179 |
null, |
|
180 |
null |
|
181 |
); |
|
182 |
List<String> SQLs = createTable.getSQLs(); |
|
183 |
GeometryType geomtype = attrgeom.getGeomType(); |
|
184 |
SQLs.add(SpatialIndexUtils.getSQLCreateSpatialIndex( |
|
185 |
table.getTable(), |
|
186 |
attrgeom.getName(), |
|
187 |
geomtype.getType(), |
|
188 |
geomtype.getSubType() |
|
189 |
)); |
|
190 |
SQLs.add(SpatialIndexUtils.getSQLRebuildSpatialIndex( |
|
191 |
table.getTable(), |
|
192 |
attrgeom.getName(), |
|
193 |
geomtype.getType(), |
|
194 |
geomtype.getSubType() |
|
195 |
)); |
|
196 |
|
|
197 |
int max = 6; |
|
198 |
int offset = 4*3; |
|
199 |
assertEquals("CreateTable num. SQLs", max, SQLs.size()); |
|
200 |
for (int i = 0; i < max; i++) { |
|
201 |
System.out.println("###### SQL "+i+":"+SQLs.get(i)); |
|
202 |
System.out.println("###### EXP "+i+":"+expectedSQLs.get(offset+i)); |
|
203 |
assertEquals("CreateTable SQL "+i, expectedSQLs.get(offset+i), SQLs.get(i)); |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
207 |
public void testCreateTableIndex2D() throws Exception { |
|
208 |
JDBCHelper helper = TestUtils.getJDBCHelper(); |
|
209 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
210 |
OperationsFactory operations = helper.getOperations(); |
|
211 |
|
|
212 |
List<String> expectedSQLs = TestUtils.getSQLs("createTable.sql"); |
|
213 |
|
|
214 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
215 |
Envelope env = sourceStore.getEnvelope(); |
|
216 |
|
|
217 |
TableReference table = operations.createTableReference( |
|
218 |
"dbtest", |
|
219 |
sqlbuilder.default_schema(), |
|
220 |
"test", |
|
221 |
null |
|
222 |
); |
|
223 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
224 |
EditableFeatureType eft = featureType.getEditable(); |
|
225 |
EditableFeatureAttributeDescriptor attrgeom = eft.getEditableAttributeDescriptor("Geometry"); |
|
226 |
attrgeom.setGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
227 |
attrgeom.setIsIndexed(true); |
|
228 |
CreateTableOperation createTable = operations.createTable( |
|
229 |
table, |
|
230 |
eft.getNotEditableCopy(), |
|
231 |
null, |
|
232 |
null |
|
233 |
); |
|
234 |
List<String> SQLs = createTable.getSQLs(); |
|
235 |
GeometryType geomtype = attrgeom.getGeomType(); |
|
236 |
SQLs.add(SpatialIndexUtils.getSQLCreateSpatialIndex( |
|
237 |
table.getTable(), |
|
238 |
attrgeom.getName(), |
|
239 |
geomtype.getType(), |
|
240 |
geomtype.getSubType() |
|
241 |
)); |
|
242 |
SQLs.add(SpatialIndexUtils.getSQLRebuildSpatialIndex( |
|
243 |
table.getTable(), |
|
244 |
attrgeom.getName(), |
|
245 |
geomtype.getType(), |
|
246 |
geomtype.getSubType() |
|
247 |
)); |
|
248 |
|
|
249 |
int max = 6; |
|
250 |
int offset = 4*4+2; |
|
251 |
assertEquals("CreateTable num. SQLs", max, SQLs.size()); |
|
252 |
for (int i = 0; i < max; i++) { |
|
253 |
System.out.println("###### SQL "+i+":"+SQLs.get(i)); |
|
254 |
System.out.println("###### EXP "+i+":"+expectedSQLs.get(offset+i)); |
|
255 |
assertEquals("CreateTable SQL "+i, expectedSQLs.get(offset+i), SQLs.get(i)); |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
153 | 259 |
} |
org.gvsig.oracle/trunk/org.gvsig.oracle/org.gvsig.oracle.provider/src/main/java/org/gvsig/oracle/dal/GeometryTypeUtils.java | ||
---|---|---|
120 | 120 |
return Geometry.SUBTYPES.UNKNOWN; |
121 | 121 |
} |
122 | 122 |
} |
123 |
|
|
124 |
public static int getDimensions(int subtype) { |
|
125 |
switch(subtype) { |
|
126 |
case Geometry.SUBTYPES.GEOM2D: |
|
127 |
return 2; |
|
128 |
case Geometry.SUBTYPES.GEOM3D: |
|
129 |
return 3; |
|
130 |
case Geometry.SUBTYPES.GEOM2DM: |
|
131 |
return 3; |
|
132 |
case Geometry.SUBTYPES.GEOM3DM: |
|
133 |
return 4; |
|
134 |
default: |
|
135 |
return 2; |
|
136 |
} |
|
137 |
} |
|
123 | 138 |
|
124 | 139 |
public static GeometryType getGeometryTypeFromDatabaseTypeNumber(int typeCode) { |
125 | 140 |
int dimensions = typeCode/1000; |
org.gvsig.oracle/trunk/org.gvsig.oracle/org.gvsig.oracle.provider/src/main/java/org/gvsig/oracle/dal/OracleSQLBuilder.java | ||
---|---|---|
384 | 384 |
* duplicate the SRID definitions!! |
385 | 385 |
*/ |
386 | 386 |
int gvsigType = column.getGeometryType(); |
387 |
int gvsigSubtype = column.getGeometrySubtype(); //.getGeometryType();
|
|
387 |
int gvsigSubtype = column.getGeometrySubtype(); |
|
388 | 388 |
String sql = MessageFormat.format( // delete before inserting to avoid creating duplicates |
389 | 389 |
DELETE_FROM_OGIS_GEOMETRY_COLUMNS_QUERY, |
390 | 390 |
this.table().getSchema(), |
391 | 391 |
this.table().getName().toUpperCase(), |
392 |
column.getName() //.toUpperCase());
|
|
392 |
column.getName() |
|
393 | 393 |
); |
394 | 394 |
sqls.add(sql); |
395 | 395 |
sql = MessageFormat.format( |
396 | 396 |
INSERT_OGIS_GEOMETRY_COLUMNS_QUERY, |
397 | 397 |
this.table().getSchema(), |
398 | 398 |
this.table().getName().toUpperCase(), |
399 |
column.getName(), //.toUpperCase(),
|
|
399 |
column.getName(), |
|
400 | 400 |
Integer.toString(GeometryTypeUtils.toSFSGeometryTypeCode(gvsigType, gvsigSubtype)) |
401 | 401 |
); |
402 | 402 |
sqls.add(sql); |
... | ... | |
418 | 418 |
sql = SpatialIndexUtils.getSQLCreateSpatialIndex( |
419 | 419 |
this.table().getName(), |
420 | 420 |
column.getName(), |
421 |
column.getGeometryType() |
|
421 |
gvsigType, |
|
422 |
gvsigSubtype |
|
422 | 423 |
); |
423 | 424 |
sqls.add(sql); |
424 | 425 |
} |
org.gvsig.oracle/trunk/org.gvsig.oracle/org.gvsig.oracle.provider/src/main/java/org/gvsig/oracle/dal/operations/OracleUpdateSpatialIndexAndMetadata.java | ||
---|---|---|
310 | 310 |
|
311 | 311 |
public void createOrRebuildSpatialIndex(FeatureAttributeDescriptor geomDescriptor) { |
312 | 312 |
int geomType = geomDescriptor.getGeomType().getType(); |
313 |
int geomSubtype = geomDescriptor.getGeomType().getSubType(); |
|
313 | 314 |
String geomColumn = geomDescriptor.getName(); |
314 | 315 |
String indexName = SpatialIndexUtils.getSpatialIndex(connection, schema, table, geomColumn); |
315 | 316 |
|
316 | 317 |
Statement st = null; |
317 | 318 |
if (indexName == null) { |
318 |
String sql = SpatialIndexUtils.getSQLCreateSpatialIndex(table, geomColumn, geomType); |
|
319 |
String sql = SpatialIndexUtils.getSQLCreateSpatialIndex(table, geomColumn, geomType, geomSubtype);
|
|
319 | 320 |
try { |
320 | 321 |
st = connection.createStatement(); |
321 | 322 |
JDBCUtils.execute(st, sql); |
... | ... | |
325 | 326 |
JDBCUtils.closeQuietly(st); |
326 | 327 |
} |
327 | 328 |
} else { |
328 |
String sql = SpatialIndexUtils.getSQLRebuildSpatialIndex(table, geomColumn, geomType); |
|
329 |
String sql = SpatialIndexUtils.getSQLRebuildSpatialIndex(table, geomColumn, geomType, geomSubtype);
|
|
329 | 330 |
try { |
330 | 331 |
st = connection.createStatement(); |
331 | 332 |
JDBCUtils.executeQuery(st, sql); |
org.gvsig.oracle/trunk/org.gvsig.oracle/org.gvsig.oracle.provider/src/main/java/org/gvsig/oracle/dal/SpatialIndexUtils.java | ||
---|---|---|
181 | 181 |
return sql; |
182 | 182 |
} |
183 | 183 |
|
184 |
public static String getSQLCreateSpatialIndex(String table, String geomColumn, int geomType) { |
|
184 |
public static String getSQLCreateSpatialIndex(String table, String geomColumn, int geomType, int geomsubtype) {
|
|
185 | 185 |
table = table.toUpperCase(); |
186 | 186 |
String oracleGeomTypeName = GeometryTypeUtils.toOracleGeometryTypeName(geomType); |
187 |
int dimensions = GeometryTypeUtils.getDimensions(geomsubtype); |
|
187 | 188 |
String indexName = SpatialIndexUtils.getSpatialIndexName(table, geomColumn); |
188 |
String createIndexSql = "CREATE INDEX \"{0}\" ON \"{1}\" (\"{2}\") INDEXTYPE IS MDSYS.SPATIAL_INDEX PARAMETERS (''LAYER_GTYPE={3}'')"; // SDO_LEVEL=8
|
|
189 |
String createIndexSql = "CREATE INDEX \"{0}\" ON \"{1}\" (\"{2}\") INDEXTYPE IS MDSYS.SPATIAL_INDEX PARAMETERS (''SDO_INDX_DIMS={3},LAYER_GTYPE={4}'')"; // SDO_LEVEL=8
|
|
189 | 190 |
String sql = MessageFormat.format( |
190 | 191 |
createIndexSql, |
191 | 192 |
indexName, |
192 | 193 |
table, |
193 | 194 |
geomColumn, |
195 |
dimensions, |
|
194 | 196 |
oracleGeomTypeName |
195 | 197 |
); |
196 | 198 |
return sql; |
197 | 199 |
} |
198 | 200 |
|
199 |
public static String getSQLRebuildSpatialIndex(String table, String geomColumn, int geomType) { |
|
201 |
public static String getSQLRebuildSpatialIndex(String table, String geomColumn, int geomType, int geomsubtype) {
|
|
200 | 202 |
table = table.toUpperCase(); |
201 | 203 |
String indexName = SpatialIndexUtils.getSpatialIndexName(table, geomColumn); |
202 | 204 |
String oracleGeomTypeName = GeometryTypeUtils.toOracleGeometryTypeName(geomType); |
203 |
String rebuildIndexSql = "ALTER INDEX \"{0}\" REBUILD PARAMETERS (''LAYER_GTYPE={1}'')"; |
|
205 |
int dimensions = GeometryTypeUtils.getDimensions(geomsubtype); |
|
206 |
String rebuildIndexSql = "ALTER INDEX \"{0}\" REBUILD PARAMETERS (''SDO_INDX_DIMS={1},LAYER_GTYPE={2}'')"; |
|
204 | 207 |
String sql = MessageFormat.format( |
205 | 208 |
rebuildIndexSql, |
206 | 209 |
indexName, |
210 |
dimensions, |
|
207 | 211 |
oracleGeomTypeName |
208 | 212 |
); |
209 | 213 |
return sql; |
Also available in: Unified diff