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 @ 44678
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 |
|
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 = "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES where table_type in ('TABLE','VIEW','EXTERNAL')"; |
32 |
rs = conn.createStatement().executeQuery(sql); |
33 |
while (rs.next()) {
|
34 |
JDBCStoreParameters params = baseParameters.getCopy(); |
35 |
params.setCatalog(rs.getString("TABLE_CATALOG"));
|
36 |
params.setSchema(rs.getString("TABLE_SCHEMA"));
|
37 |
params.setTable(rs.getString("TABLE_NAME"));
|
38 |
tables.add(params); |
39 |
} |
40 |
return tables;
|
41 |
|
42 |
} catch (SQLException ex) { |
43 |
throw new RuntimeException("Can't fetch tables information",ex); |
44 |
|
45 |
} finally {
|
46 |
JDBCUtils.closeQuietly(rs); |
47 |
} |
48 |
|
49 |
} |
50 |
} |