Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.h2spatial / org.gvsig.h2spatial.h2gis132 / org.gvsig.h2spatial.h2gis132.provider / src / main / java / org / gvsig / fmap / dal / store / h2 / operations / H2SpatialListTablesOperation.java @ 46315

History | View | Annotate | Download (2.86 KB)

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

    
3
import java.sql.ResultSet;
4
import java.sql.SQLException;
5
import java.util.ArrayList;
6
import java.util.List;
7
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
8
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
9
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection;
10
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
11
import static org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer.SHOW_TABLES;
12
import static org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer.SHOW_TABLES_AND_VIEWS;
13
import static org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer.SHOW_VIEWS;
14
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
15
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ListTablesOperation;
16

    
17
public class H2SpatialListTablesOperation extends ListTablesOperation {
18

    
19
    public H2SpatialListTablesOperation(JDBCHelper helper, int mode, JDBCServerExplorerParameters serverParameters, boolean informationTables, int tablesOrViews) {
20
        super(helper, mode, serverParameters, informationTables, tablesOrViews);
21
    }
22

    
23
    
24
    @Override
25
    public List<JDBCStoreParameters> listTables(
26
            JDBCConnection conn,
27
            int mode,
28
            JDBCServerExplorerParameters serverParameters,
29
            boolean informationTables,
30
            int tablesOrViews
31
    ) {
32
        ResultSet rs = null;
33
        List<JDBCStoreParameters> tables = new ArrayList<>();
34

    
35
        try {
36
            StringBuilder builder = new StringBuilder();
37
            builder.append("SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES where table_type in ");
38
            switch(tablesOrViews){
39
                default:
40
                case SHOW_TABLES_AND_VIEWS:
41
                    builder.append("('TABLE','VIEW','EXTERNAL')");
42
                    break;
43
                case SHOW_TABLES:
44
                    builder.append("('TABLE')");
45
                    break;
46
                case SHOW_VIEWS:
47
                    builder.append("('VIEW','EXTERNAL')");
48
                    break;
49
            }
50
            
51
            if( !informationTables ) {
52
                builder.append(" AND TABLE_SCHEMA<>'INFORMATION_SCHEMA'");
53
            }
54
            String sql = builder.toString();
55
            rs = conn.createStatement().executeQuery(sql);
56
            while (rs.next()) {
57
                JDBCStoreParameters params = this.helper.createOpenStoreParameters(serverParameters);
58
                params.setCatalog(rs.getString("TABLE_CATALOG"));
59
                params.setSchema(rs.getString("TABLE_SCHEMA"));
60
                params.setTable(rs.getString("TABLE_NAME"));
61
                tables.add(params);
62
            }
63
            return tables;
64
            
65
        } catch (SQLException ex) {
66
            throw new RuntimeException("Can't fetch tables information",ex);
67
            
68
        } finally {
69
            JDBCUtils.closeQuietly(rs);
70
        }
71

    
72
    }
73
}