Revision 44198 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/JDBCHelperBase.java
JDBCHelperBase.java | ||
---|---|---|
15 | 15 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
16 | 16 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
17 | 17 |
import org.gvsig.expressionevaluator.Function; |
18 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
18 | 19 |
import org.gvsig.fmap.dal.DataTypes; |
19 | 20 |
import org.gvsig.fmap.dal.exception.DataException; |
20 | 21 |
import org.gvsig.fmap.dal.exception.InitializeException; |
21 | 22 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
22 | 23 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
24 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
23 | 25 |
import org.gvsig.fmap.dal.feature.FeatureType; |
24 | 26 |
|
25 | 27 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
... | ... | |
159 | 161 |
} |
160 | 162 |
|
161 | 163 |
@Override |
162 |
public boolean supportFilter(Evaluator filter) { |
|
164 |
public boolean supportFilter(final FeatureType type, Evaluator filter) {
|
|
163 | 165 |
// No podemos filtrar cuando: |
164 | 166 |
// - Hay una subquery especificada en los parametros |
165 | 167 |
// - Si hay un filtro y el getSQL devuelbe null. |
166 | 168 |
// - Si se esta usando alguna funcion no-sql en el getSQL |
167 | 169 |
// - Si se estan usando funciones OGC y no soportamos funciones espaciales |
170 |
// - Si se esta usando algun campo calculado en la expresion de filtro. |
|
168 | 171 |
// |
169 | 172 |
// Un proveedor especifico podria sobreescribir el metodo, |
170 | 173 |
// para hilar mas fino al comprobar si soporta el filtro o no. |
... | ... | |
189 | 192 |
// Ahora vamos a comprobar que las funciones que se usan son |
190 | 193 |
// compatibles sql, y que no se usan funciones OGC si el |
191 | 194 |
// proveedor dice que no soporta funciones espaciales. |
195 |
// Tambien comprobaremos que el filtro no usa ningun campo calculado. |
|
192 | 196 |
final MutableBoolean isCompatible = new MutableBoolean(true); |
193 | 197 |
final boolean supportSpatialFunctions = this.hasSpatialFunctions(); |
194 | 198 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
195 | 199 |
Code code = manager.compile(sql); |
200 |
SymbolTable symbolTable = manager.createSymbolTable(); |
|
201 |
code.link(symbolTable); |
|
196 | 202 |
try { |
197 | 203 |
code.accept(new Visitor() { |
198 | 204 |
@Override |
199 | 205 |
public void visit(Object code_obj) throws VisitCanceledException, BaseException { |
200 | 206 |
Code code = (Code) code_obj; |
201 |
if ( code.code()==Code.CALLER ) { |
|
202 |
Code.Caller caller = (Code.Caller) code; |
|
203 |
Function function = caller.function(); |
|
204 |
if( function==null ) { |
|
205 |
isCompatible.setValue(false); |
|
206 |
throw new VisitCanceledException(); |
|
207 |
} |
|
208 |
if( !function.isSQLCompatible() ) { |
|
209 |
isCompatible.setValue(false); |
|
210 |
throw new VisitCanceledException(); |
|
211 |
} |
|
212 |
if( !supportSpatialFunctions ) { |
|
213 |
if( StringUtils.equalsIgnoreCase(function.group(),Function.GROUP_OGC) ) { |
|
207 |
switch(code.code()) { |
|
208 |
case Code.CALLER: |
|
209 |
Code.Caller caller = (Code.Caller) code; |
|
210 |
Function function = caller.function(); |
|
211 |
if( function==null ) { |
|
214 | 212 |
isCompatible.setValue(false); |
215 | 213 |
throw new VisitCanceledException(); |
216 | 214 |
} |
217 |
} |
|
215 |
if( !function.isSQLCompatible() ) { |
|
216 |
isCompatible.setValue(false); |
|
217 |
throw new VisitCanceledException(); |
|
218 |
} |
|
219 |
if( !supportSpatialFunctions ) { |
|
220 |
if( StringUtils.equalsIgnoreCase(function.group(),Function.GROUP_OGC) ) { |
|
221 |
isCompatible.setValue(false); |
|
222 |
throw new VisitCanceledException(); |
|
223 |
} |
|
224 |
} |
|
225 |
break; |
|
226 |
|
|
227 |
case Code.IDENTIFIER: |
|
228 |
Code.Identifier identifier = (Code.Identifier) code; |
|
229 |
if( type!=null ) { |
|
230 |
FeatureAttributeDescriptor attrdesc = type.getAttributeDescriptor(identifier.name()); |
|
231 |
if( attrdesc!=null ) { |
|
232 |
if( attrdesc.isComputed() ) { |
|
233 |
isCompatible.setValue(false); |
|
234 |
throw new VisitCanceledException(); |
|
235 |
} |
|
236 |
} |
|
237 |
} |
|
238 |
break; |
|
218 | 239 |
} |
219 | 240 |
} |
220 | 241 |
}); |
... | ... | |
229 | 250 |
} |
230 | 251 |
|
231 | 252 |
@Override |
232 |
public boolean supportOrder(FeatureQueryOrder order) { |
|
253 |
public boolean supportOrder(FeatureType type, FeatureQueryOrder order) {
|
|
233 | 254 |
if (this.useSubquery()) { |
234 | 255 |
return false; |
235 | 256 |
} |
... | ... | |
238 | 259 |
} |
239 | 260 |
for( FeatureQueryOrder.FeatureQueryOrderMember member : order.members() ) { |
240 | 261 |
if (member.hasEvaluator()) { |
241 |
if( !this.supportFilter(member.getEvaluator()) ) { |
|
262 |
if( !this.supportFilter(type, member.getEvaluator()) ) {
|
|
242 | 263 |
return false; |
243 | 264 |
} |
244 | 265 |
} |
... | ... | |
324 | 345 |
} |
325 | 346 |
} |
326 | 347 |
|
348 |
@Override |
|
327 | 349 |
public void closeConnectionQuietly(Connection connection) { |
328 | 350 |
if( connection != null ) { |
329 | 351 |
LOGGER.debug("Clossing connection quietly "+connection.hashCode()); |
... | ... | |
509 | 531 |
parameters.getSchema()+ ":" + |
510 | 532 |
parameters.tableID(); |
511 | 533 |
} |
534 |
|
|
535 |
@Override |
|
536 |
public boolean isThreadSafe() { |
|
537 |
return true; |
|
538 |
} |
|
512 | 539 |
|
513 | 540 |
} |
Also available in: Unified diff