1 package org.modeshape.connector.meta.jdbc;
2
3 import java.sql.Connection;
4 import java.sql.DatabaseMetaData;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7 import java.sql.Statement;
8 import java.util.LinkedList;
9 import java.util.List;
10
11
12
13
14
15
16
17
18 public class SqlServerMetadataCollector extends JdbcMetadataCollector {
19
20 @Override
21 public List<String> getSchemaNames( Connection conn,
22 String catalogName ) throws JdbcMetadataException {
23 Statement stmt = null;
24 ResultSet rs = null;
25 List<String> schemaNames = new LinkedList<String>();
26
27 try {
28 stmt = conn.createStatement();
29
30
31 rs = stmt.executeQuery("SELECT name AS TABLE_SCHEM FROM sys.schemas ORDER BY TABLE_SCHEM");
32 while (rs.next()) {
33 schemaNames.add(rs.getString("TABLE_SCHEM"));
34 }
35
36 return schemaNames;
37 } catch (SQLException se) {
38 throw new JdbcMetadataException(se);
39 } finally {
40 try {
41 if (rs != null) rs.close();
42 } catch (SQLException ignore) {
43 }
44 try {
45 if (stmt != null) stmt.close();
46 } catch (SQLException ignore) {
47 }
48 }
49 }
50
51 }