Revision 46517 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/operations/TableIsEmptyOperation.java

View differences:

TableIsEmptyOperation.java
28 28
import java.sql.Statement;
29 29
import org.apache.commons.lang3.StringUtils;
30 30
import org.gvsig.expressionevaluator.ExpressionBuilder;
31
import org.gvsig.fmap.dal.SQLBuilder;
31 32
import org.gvsig.fmap.dal.exception.DataException;
32 33
import org.gvsig.fmap.dal.feature.FeatureQuery;
33 34
import org.gvsig.fmap.dal.feature.FeatureType;
......
39 40
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
40 41
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE;
41 42
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_JDBCHELPER;
43
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_QUERY;
42 44
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_SYMBOLTABLE;
43 45
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_TABLE;
46
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation.getAllExtraColumns;
47
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation.process3_Where;
48
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation.process4_Aggregates;
49
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation.process5_GroupBys;
44 50
import org.gvsig.tools.evaluator.Evaluator;
45 51

  
46 52
public class TableIsEmptyOperation extends AbstractConnectionOperation {
......
79 85
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
80 86
        ExpressionBuilder expbuilder = sqlbuilder.expression();
81 87
        
82
        sqlbuilder.select().column().all();
83
        sqlbuilder.select().from().table()
88
        expbuilder.setProperty(PROP_FEATURE_TYPE, this.featureType);
89
        expbuilder.setProperty(PROP_TABLE, table);
90
        expbuilder.setProperty(PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable());
91
        expbuilder.setProperty(PROP_JDBCHELPER, this.helper);
92
        expbuilder.setProperty(PROP_QUERY, this.query);
93
        
94
        SQLBuilder.SelectBuilder select = sqlbuilder.select();
95
//        select.column().all();
96
        select.from().table()
84 97
                .database(this.table.getDatabase())
85 98
                .schema(this.table.getSchema())
86 99
                .name(this.table.getTable());
87
        sqlbuilder.select().from().subquery(this.table.getSubquery());
100
        select.from().subquery(this.table.getSubquery());
101
        
102
//        ResultSetForSetProviderOperation.process2_ComputedFields(helper, featureType, query, sqlbuilder, select, null);
103
        process3_Where(helper, featureType, query, sqlbuilder, select);
88 104
        if (!StringUtils.isEmpty(baseFilter)) {
89
            sqlbuilder.select().where().set( expbuilder.custom(baseFilter) );
105
            select.where().set( expbuilder.custom(baseFilter) );
90 106
        }
107
        if (this.query != null && (query.hasAggregateFunctions() || query.hasGroupByColumns())) {
108
            process4_Aggregates(this.table, this.featureType, this.query, getAllExtraColumns(this.featureType, this.query), sqlbuilder, select, null);
109
            process5_GroupBys(this.table, this.featureType, this.query, getAllExtraColumns(this.featureType, this.query), sqlbuilder, select, null);
110
        }
91 111
        
92
        Evaluator filter = query == null ? null : query.getFilter();
93
        if (filter != null) {
94
            String sqlfilter = filter.getSQL();
95
            if (!StringUtils.isEmpty(sqlfilter)) {
96
                if (this.helper.supportFilter(this.featureType, filter)) {
97
                    // El and() hace un set() si no hay un filtro previo
98
                    sqlbuilder.select().where().and(expbuilder.toValue(sqlfilter));
99
                }
100
            }
101
        }        
102
//        if (!StringUtils.isEmpty(filter)) {
103
//            // El and() hace un set() si no hay un filtro previo
104
//            sqlbuilder.select().where().and(expbuilder.toValue(filter));
105
//        }
106 112
        sqlbuilder.select().limit(1);
107
        this.helper.processSpecialFunctions(sqlbuilder, featureType, null);
108
//        sqlbuilder.setProperties(
109
//                ExpressionBuilder.Variable.class, 
110
//                PROP_TABLE, table
111
//        );
113
        
112 114
        sqlbuilder.setProperties(
113 115
                null,
114 116
                PROP_FEATURE_TYPE, this.featureType,
115 117
                PROP_TABLE, table,
116 118
                PROP_SYMBOLTABLE, this.query==null? null:this.query.getSymbolTable(),
117
                PROP_JDBCHELPER, this.helper
119
                PROP_JDBCHELPER, this.helper,
120
                PROP_QUERY, this.query
118 121
        );
122

  
123
	this.helper.expandCalculedColumns(sqlbuilder);
124
        this.helper.processSpecialFunctions(sqlbuilder, featureType, null);
125
        if(select.getColumns().isEmpty()){
126
            select.column().value(expbuilder.constant(1));
127
        }
119 128
        String sql = sqlbuilder.select().toString();
120 129
        return sql;
121 130
    }

Also available in: Unified diff