Revision 138
trunk/org.gvsig.spatialite/org.gvsig.spatialite.provider/src/main/java/org/gvsig/spatialite/dal/SpatiaLiteSQLBuilder.java | ||
---|---|---|
13 | 13 |
import org.gvsig.fmap.geom.Geometry; |
14 | 14 |
import org.gvsig.tools.dispose.Disposable; |
15 | 15 |
import org.apache.commons.lang3.tuple.Pair; |
16 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
16 | 17 |
|
17 | 18 |
public class SpatiaLiteSQLBuilder extends JDBCSQLBuilderBase { |
18 | 19 |
|
... | ... | |
108 | 109 |
builder.append(this.table.toString()); |
109 | 110 |
builder.append(" ("); |
110 | 111 |
boolean first = true; |
111 |
for (ColumnDescriptorBuilder column : columns) {
|
|
112 |
for (ColumnDescriptor column : columns) { |
|
112 | 113 |
if( column.isGeometry() ) { |
113 | 114 |
continue; |
114 | 115 |
} |
... | ... | |
146 | 147 |
sqls.add(builder.toString()); |
147 | 148 |
|
148 | 149 |
String AddGeometryColumn = "SELECT AddGeometryColumn({0} , {1} , {2,number,#######} , {3}, {4}, {5})"; |
149 |
for (ColumnDescriptorBuilderBase column : columns) {
|
|
150 |
for (ColumnDescriptor column : columns) { |
|
150 | 151 |
if( column.isGeometry() ) { |
151 | 152 |
String sql = MessageFormat.format( |
152 | 153 |
AddGeometryColumn, |
... | ... | |
417 | 418 |
sqls.add(builder.toString()); |
418 | 419 |
} |
419 | 420 |
|
420 |
for (ColumnDescriptorBuilderBase column : adds) {
|
|
421 |
for (ColumnDescriptor column : adds) { |
|
421 | 422 |
if (column.isGeometry()) { |
422 | 423 |
String addGeometryColumn = "SELECT AddGeometryColumn({0} , {1} , {2,number,#######}, {3}, {4}, {5})"; |
423 | 424 |
String sql = MessageFormat.format( |
... | ... | |
481 | 482 |
} |
482 | 483 |
} |
483 | 484 |
|
485 |
private ColumnDescriptor getDescriptorForUseInIndex(Value arg) { |
|
486 |
if( arg instanceof Variable ) { |
|
487 |
ColumnDescriptor descriptor = ((Variable)arg).getDescriptor(); |
|
488 |
if( descriptor.getType()==DataTypes.GEOMETRY && descriptor.isIndexed() ) { |
|
489 |
return descriptor; |
|
490 |
} |
|
491 |
} |
|
492 |
// Aqui probablemente estaria bien comprobar si el argumento es la funcion |
|
493 |
// ST_Envelope sobre un campo geometria y tambien usar el indice espacial |
|
494 |
// para cubrir el caso que se use algo como: |
|
495 |
// ST_Intersecta(x, ST_Envelope("geom")) |
|
496 |
return null; |
|
497 |
} |
|
498 |
|
|
499 |
private ColumnDescriptor getDescriptorForUseInIndex(Value... args) { |
|
500 |
for (Value arg : args) { |
|
501 |
ColumnDescriptor descriptor = getDescriptorForUseInIndex(arg); |
|
502 |
if( descriptor != null ) { |
|
503 |
return descriptor; |
|
504 |
} |
|
505 |
} |
|
506 |
return null; |
|
507 |
} |
|
508 |
|
|
509 |
@Override |
|
510 |
public Function ST_Intersects(Value geom1, Value geom2) { |
|
511 |
// return super.ST_Intersects(geom1, geom2); |
|
512 |
JDBCStoreParameters jdbcparams = null; |
|
513 |
ColumnDescriptor descriptor = getDescriptorForUseInIndex(geom1, geom2); |
|
514 |
|
|
515 |
if( descriptor != null ) { |
|
516 |
jdbcparams = (JDBCStoreParameters) descriptor.getStoreParameters(); |
|
517 |
} |
|
518 |
Function f; |
|
519 |
if( jdbcparams!=null ) { |
|
520 |
// Usamos indices espaciales |
|
521 |
f = function( |
|
522 |
"ST_Intersects", |
|
523 |
"(ST_Intersects({0},{1}) AND ROWID IN ( SELECT ROWID FROM SpatialIndex WHERE f_table_name = ''"+jdbcparams.getTable()+"'' AND f_geometry_column = ''"+descriptor.getName()+"'' AND search_frame = \""+jdbcparams.getTable()+"\".\""+descriptor.getName()+"\"))", |
|
524 |
geom1, |
|
525 |
geom2 |
|
526 |
); |
|
527 |
} else { |
|
528 |
f = super.ST_Intersects(geom1, geom2); |
|
529 |
} |
|
530 |
return f; |
|
531 |
} |
|
484 | 532 |
} |
Also available in: Unified diff