| 1 | |
package net.sourceforge.addam.util; |
| 2 | |
|
| 3 | |
|
| 4 | |
import java.util.List; |
| 5 | |
import java.util.ArrayList; |
| 6 | |
import java.sql.Connection; |
| 7 | |
import java.sql.DatabaseMetaData; |
| 8 | |
import java.sql.ResultSet; |
| 9 | |
import java.sql.SQLException; |
| 10 | |
|
| 11 | |
import net.sourceforge.addam.ddlgen.GeneratorSpec; |
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | 0 | public class DatabaseMetaDataUtil { |
| 21 | |
|
| 22 | |
public static List<String> getTables(String catalog, String schema, Connection connection) throws SQLException { |
| 23 | |
|
| 24 | 0 | DatabaseMetaData metadata = connection.getMetaData(); |
| 25 | 0 | if (metadata.storesUpperCaseIdentifiers()) { |
| 26 | 0 | catalog = (catalog == null) ? null : catalog.toUpperCase(); |
| 27 | 0 | schema = (schema == null) ? null : schema.toUpperCase(); |
| 28 | 0 | } else if (metadata.storesLowerCaseIdentifiers()) { |
| 29 | 0 | catalog = (catalog == null) ? null : catalog.toLowerCase(); |
| 30 | 0 | schema = (schema == null) ? null : schema.toLowerCase(); |
| 31 | |
} |
| 32 | 0 | ResultSet tablesRS = metadata.getTables(catalog, schema, "%", new String[]{"TABLE"}); |
| 33 | 0 | List<String> objects = new ArrayList<String>(); |
| 34 | 0 | while (tablesRS.next()) { |
| 35 | 0 | String dbObject = tablesRS.getString(3); |
| 36 | 0 | objects.add(dbObject); |
| 37 | 0 | } |
| 38 | 0 | return objects; |
| 39 | |
} |
| 40 | |
|
| 41 | |
} |