Index: JDBCHelperBase.java
===================================================================
--- JDBCHelperBase.java	(revision 44190)
+++ JDBCHelperBase.java	(revision 44191)
@@ -5,15 +5,21 @@
 import java.sql.Connection;
 import java.sql.ResultSet;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.mutable.MutableBoolean;
+import org.gvsig.expressionevaluator.Code;
 import org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType;
 import static org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType.EWKB;
 import static org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType.NATIVE;
 import static org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType.WKB;
 import static org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType.WKT;
+import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
+import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
+import org.gvsig.expressionevaluator.Function;
 import org.gvsig.fmap.dal.DataTypes;
 import org.gvsig.fmap.dal.exception.DataException;
 import org.gvsig.fmap.dal.exception.InitializeException;
 import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
+import org.gvsig.fmap.dal.feature.FeatureQueryOrder;
 import org.gvsig.fmap.dal.feature.FeatureType;
 
 import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
@@ -41,18 +47,22 @@
 import org.gvsig.fmap.geom.GeometryLocator;
 import org.gvsig.fmap.geom.GeometryManager;
 import org.gvsig.tools.dispose.impl.AbstractDisposable;
+import org.gvsig.tools.evaluator.Evaluator;
 import org.gvsig.tools.exception.BaseException;
 import org.gvsig.tools.exception.NotYetImplemented;
+import org.gvsig.tools.visitor.VisitCanceledException;
+import org.gvsig.tools.visitor.Visitor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@SuppressWarnings("UseSpecificCatch")
 public class JDBCHelperBase extends AbstractDisposable implements ResourceConsumer, JDBCHelper {
 
     private static final boolean ALLOW_AUTOMATIC_VALUES = true;
     private static final String QUOTE_FOR_USE_IN_IDENTIFIERS = "\"";
     private static final String QUOTE_FOR_USE_IN_STRINGS = "'";
 
-    private static final Logger logger = LoggerFactory.getLogger(JDBCHelperBase.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(JDBCHelperBase.class);
 
     private ResulSetControler resulSetControler = null;
 
@@ -112,6 +122,11 @@
     }
 
     @Override
+    public boolean allowNestedOperations() {
+        return false;
+    }
+    
+    @Override
     public boolean canWriteGeometry(int geometryType, int geometrySubtype) {
         // Como va a guardar las geometrias en WKT, puede escribirlas todas.
         return true;
@@ -142,8 +157,96 @@
     public String getQuoteForStrings() {
         return QUOTE_FOR_USE_IN_STRINGS;
     }
+
+    @Override
+    public boolean supportFilter(Evaluator filter) {
+        // No podemos filtrar cuando:
+        // - Hay una subquery especificada en los parametros 
+        // - Si hay un filtro y el getSQL devuelbe null.
+        // - Si se esta usando alguna funcion no-sql en el getSQL
+        // - Si se estan usando funciones OGC y no soportamos funciones espaciales
+        // 
+        // Un proveedor especifico podria sobreescribir el metodo,
+        // para hilar mas fino al comprobar si soporta el filtro o no.
+        //
+        
+        if (this.useSubquery()) {
+            // Se esta usando una subquery en los parametros de acceso a la
+            // BBDD, asi que no podemos filtrar.
+            return false;
+        }
+        if (filter == null) {
+            // No hay que filtrar nada, asi que se pùede.
+            return true;
+        }
+        String sql = filter.getSQL();
+        if (StringUtils.isEmpty(sql)) {
+            // Hay un filtro, pero la SQL es null, con lo que no podemos
+            // filtrar por el.
+            return false;
+        }
+
+        // Ahora vamos a comprobar que las funciones que se usan son 
+        // compatibles sql, y que no se usan funciones OGC si el 
+        // proveedor dice que no soporta funciones espaciales.
+        final MutableBoolean isCompatible = new MutableBoolean(true);
+        final boolean supportSpatialFunctions = this.hasSpatialFunctions();
+        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
+        Code code = manager.compile(sql);
+        try {
+            code.accept(new Visitor() {
+                @Override
+                public void visit(Object code_obj) throws VisitCanceledException, BaseException {
+                    Code code = (Code) code_obj;
+                    if ( code.code()==Code.CALLER ) {
+                        Code.Caller caller = (Code.Caller) code;
+                        Function function = caller.function();
+                        if( function==null ) {
+                            isCompatible.setValue(false);
+                            throw new VisitCanceledException();
+                        }
+                        if( !function.isSQLCompatible() ) {
+                            isCompatible.setValue(false);
+                            throw new VisitCanceledException();
+                        }
+                        if( !supportSpatialFunctions ) {
+                            if( StringUtils.equalsIgnoreCase(function.group(),Function.GROUP_OGC) ) {
+                                isCompatible.setValue(false);
+                                throw new VisitCanceledException();
+                            }
+                        }
+                    }
+                }
+            });
+
+        } catch (VisitCanceledException ex) {
+            // Do nothing
+        } catch (Exception ex) {
+            LOGGER.warn("Can't calculate if is SQL compatible.", ex);
+        }
+        
+        return isCompatible.booleanValue();
+    }
     
     @Override
+    public boolean supportOrder(FeatureQueryOrder order) {
+        if (this.useSubquery()) {
+            return false;
+        }
+        if (order == null) {
+            return true;
+        }
+        for( FeatureQueryOrder.FeatureQueryOrderMember member : order.members() ) {
+            if (member.hasEvaluator()) {
+                if( !this.supportFilter(member.getEvaluator()) ) {
+                    return false;
+                }
+            }            
+        }
+        return true;
+    }
+    
+    @Override
     public OperationsFactory getOperations() {
         if (this.operationsFactory== null) {
             this.operationsFactory = new OperationsFactoryBase(this);
@@ -212,14 +315,25 @@
     @Override
     public void closeConnection(Connection connection) {
         if( connection != null ) {
-            logger.debug("Clossing connection "+connection.hashCode());
+            LOGGER.debug("Clossing connection "+connection.hashCode());
             try {
                 connection.close();
             } catch(Exception ex) {
-                logger.warn("Can't close connection.", ex);
+                LOGGER.warn("Can't close connection.", ex);
             }
        }
     }
+
+    public void closeConnectionQuietly(Connection connection) {
+        if( connection != null ) {
+            LOGGER.debug("Clossing connection quietly "+connection.hashCode());
+            try {
+                connection.close();
+            } catch(Exception ex) {
+                LOGGER.warn("Can't close connection.", ex);
+            }
+       }
+    }
     
     @Override
     protected void doDispose() throws BaseException {
@@ -348,14 +462,14 @@
             DataStoreProviderServices providerServices
         ) throws InitializeException {
         
-        JDBCStoreProviderBase store = new JDBCStoreProviderBase(
+        JDBCStoreProviderBase theStore = new JDBCStoreProviderBase(
                 parameters, 
                 providerServices, 
                 DBHelper.newMetadataContainer(JDBCLibrary.NAME),
                 this
         );
-        this.initialize(store, parameters, store);
-        return store;
+        this.initialize(theStore, parameters, theStore);
+        return theStore;
     }
 
     @Override
