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 @ 44949

History | View | Annotate | Download (2.05 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
    
20
    @Override
21
    public List<JDBCStoreParameters> listTables(
22
            Connection conn,
23
            int mode,
24
            JDBCStoreParameters baseParameters,
25
            boolean informationTables
26
    ) {
27
        ResultSet rs = null;
28
        List<JDBCStoreParameters> tables = new ArrayList<>();
29

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

    
54
    }
55
}