Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.h2 / src / main / java / org / gvsig / fmap / dal / store / h2 / operations / H2SpatialListTablesOperation.java @ 44644

History | View | Annotate | Download (1.77 KB)

1
package org.gvsig.fmap.dal.store.h2.operations;
2

    
3
import java.sql.Connection;
4
import java.sql.ResultSet;
5
import java.sql.SQLException;
6
import java.util.ArrayList;
7
import java.util.List;
8
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
9
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
10
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
11
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ListTablesOperation;
12

    
13
public class H2SpatialListTablesOperation extends ListTablesOperation {
14

    
15
    public H2SpatialListTablesOperation(JDBCHelper helper, int mode, JDBCStoreParameters baseParameters, boolean informationTables) {
16
        super(helper, mode, baseParameters, informationTables);
17
    }
18

    
19
    @Override
20
    public List<JDBCStoreParameters> listTables(
21
            Connection conn,
22
            int mode,
23
            JDBCStoreParameters baseParameters,
24
            boolean informationTables
25
    ) {
26
        ResultSet rs = null;
27
        List<JDBCStoreParameters> tables = new ArrayList<>();
28

    
29
        try {
30
            String sql = "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES where table_type in ('TABLE','VIEW','EXTERNAL')";
31
            rs = conn.createStatement().executeQuery(sql);
32
            while (rs.next()) {
33
                JDBCStoreParameters params = baseParameters.getCopy();
34
                params.setCatalog(rs.getString("TABLE_CATALOG"));
35
                params.setSchema(rs.getString("TABLE_SCHEMA"));
36
                params.setTable(rs.getString("TABLE_NAME"));
37
                tables.add(params);
38
            }
39
            return tables;
40
            
41
        } catch (SQLException ex) {
42
            throw new RuntimeException("Can't fetch tables information",ex);
43
            
44
        } finally {
45
            JDBCUtils.closeQuietly(rs);
46
        }
47

    
48
    }
49
}