Revision 44058 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/CountOperation.java

View differences:

CountOperation.java
10 10
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
11 11
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
12 12
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
13
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
13 14

  
14 15
public class CountOperation extends AbstractConnectionOperation {
15 16

  
16
    private final String schemaName;
17
    private final String tableName;
18
    private final String subquery;
17
    private final TableReference table;
19 18
    private final String baseFilter;
20 19
    private final String filter;
21
    private final String dbName;
22 20

  
23 21
    public CountOperation(
24 22
            JDBCHelper helper
25 23
        ) {
26
        this(helper, null, null, null, null, null, null);
24
        this(helper, null, null, null);
27 25
    }
28 26

  
29 27
    public CountOperation(
30 28
            JDBCHelper helper,
31
            String dbName,
32
            String schemaName,
33
            String tableName,
34
            String subquery,
29
            TableReference table,
35 30
            String baseFilter,
36 31
            String filter
37 32
        ) {
38 33
        super(helper);
39
        this.dbName = dbName;
40
        this.schemaName = schemaName;
41
        this.tableName = tableName;
42
        this.subquery = subquery;
34
        this.table = table;
43 35
        this.baseFilter = baseFilter;
44 36
        this.filter = filter;
45 37
    }
46 38

  
47 39
    @Override
48 40
    public final Object perform(Connection conn) throws DataException {
49
        return this.count(conn,
50
                dbName, schemaName, tableName, subquery, baseFilter, filter);
41
        return this.count(conn, table, baseFilter, filter);
51 42
    }
52 43

  
53 44
    public long count(Connection conn,
54
            String dbName, 
55
            String schemaName,
56
            String tableName,
57
            String subquery,
45
            TableReference table,
58 46
            String baseFilter,
59 47
            String filter) throws DataException {
60 48

  
61 49
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
62 50

  
63 51
        sqlbuilder.select().column().value(sqlbuilder.count().all());
64
        sqlbuilder.select().from().table().database(dbName).schema(schemaName).name(tableName);
65
        sqlbuilder.select().from().subquery(subquery);
52
        sqlbuilder.select().from().table()
53
                .database(this.table.getDatabase())
54
                .schema(this.table.getSchema())
55
                .name(this.table.getTable());
56
        sqlbuilder.select().from().subquery(this.table.getSubquery());
66 57
        if (!StringUtils.isEmpty(baseFilter)) {
67 58
            sqlbuilder.select().where().set( sqlbuilder.custom(baseFilter) );
68 59
        }

Also available in: Unified diff