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 @ 45165
History | View | Annotate | Download (2.17 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.JDBCServerExplorerParameters; |
9 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
10 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
11 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
12 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ListTablesOperation; |
13 |
|
14 |
public class H2SpatialListTablesOperation extends ListTablesOperation { |
15 |
|
16 |
public H2SpatialListTablesOperation(JDBCHelper helper, int mode, JDBCServerExplorerParameters serverParameters, boolean informationTables) { |
17 |
super(helper, mode, serverParameters, informationTables);
|
18 |
} |
19 |
|
20 |
|
21 |
@Override
|
22 |
public List<JDBCStoreParameters> listTables( |
23 |
Connection conn,
|
24 |
int mode,
|
25 |
JDBCServerExplorerParameters serverParameters, |
26 |
boolean informationTables
|
27 |
) { |
28 |
ResultSet rs = null; |
29 |
List<JDBCStoreParameters> tables = new ArrayList<>(); |
30 |
|
31 |
try {
|
32 |
String sql;
|
33 |
if( informationTables ) {
|
34 |
sql = "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES where table_type in ('TABLE','VIEW','EXTERNAL')";
|
35 |
} else {
|
36 |
sql = "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES where table_type in ('TABLE','VIEW','EXTERNAL') AND TABLE_SCHEMA<>'INFORMATION_SCHEMA'";
|
37 |
} |
38 |
rs = conn.createStatement().executeQuery(sql); |
39 |
while (rs.next()) {
|
40 |
JDBCStoreParameters params = this.helper.createOpenStoreParameters(serverParameters);
|
41 |
params.setCatalog(rs.getString("TABLE_CATALOG"));
|
42 |
params.setSchema(rs.getString("TABLE_SCHEMA"));
|
43 |
params.setTable(rs.getString("TABLE_NAME"));
|
44 |
tables.add(params); |
45 |
} |
46 |
return tables;
|
47 |
|
48 |
} catch (SQLException ex) { |
49 |
throw new RuntimeException("Can't fetch tables information",ex); |
50 |
|
51 |
} finally {
|
52 |
JDBCUtils.closeQuietly(rs); |
53 |
} |
54 |
|
55 |
} |
56 |
} |