リビジョン | 6449f9e4250a0ac0a9bfd0c4a80da15c9e690fa6 (tree) |
---|---|
日時 | 2014-11-14 22:32:13 |
作者 | argius <argius.net@gmai...> |
コミッター | argius |
[#34405] Define and use default table types not only getTableTypes (DatabaseInfoTree)
@@ -44,6 +44,13 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea | ||
44 | 44 | private static final Logger log = Logger.getLogger(DatabaseInfoTree.class); |
45 | 45 | private static final ResourceManager res = ResourceManager.getInstance(DatabaseInfoTree.class); |
46 | 46 | |
47 | + private static final String TABLE_TYPE_TABLE = "TABLE"; | |
48 | + private static final String TABLE_TYPE_VIEW = "VIEW"; | |
49 | + private static final String TABLE_TYPE_INDEX = "INDEX"; | |
50 | + private static final String TABLE_TYPE_SEQUENCE = "SEQUENCE"; | |
51 | + private static final List<String> DEFAULT_TABLE_TYPES = // | |
52 | + Arrays.asList(TABLE_TYPE_TABLE, TABLE_TYPE_VIEW, TABLE_TYPE_INDEX, TABLE_TYPE_SEQUENCE); | |
53 | + | |
47 | 54 | static volatile boolean showColumnNumber; |
48 | 55 | |
49 | 56 | private Connector currentConnector; |
@@ -710,20 +717,28 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea | ||
710 | 717 | static List<TableTypeNode> getTableTypeNodes(DatabaseMetaData dbmeta, |
711 | 718 | String catalog, |
712 | 719 | String schema) throws SQLException { |
713 | - List<TableTypeNode> a = new ArrayList<TableTypeNode>(); | |
714 | - ResultSet rs = dbmeta.getTableTypes(); | |
720 | + List<String> tableTypes = new ArrayList<String>(DEFAULT_TABLE_TYPES); | |
715 | 721 | try { |
716 | - while (rs.next()) { | |
717 | - TableTypeNode typeNode = new TableTypeNode(catalog, schema, rs.getString(1)); | |
718 | - if (typeNode.hasItems(dbmeta)) { | |
719 | - a.add(typeNode); | |
722 | + ResultSet rs = dbmeta.getTableTypes(); | |
723 | + try { | |
724 | + while (rs.next()) { | |
725 | + final String tableType = rs.getString(1); | |
726 | + if (!DEFAULT_TABLE_TYPES.contains(tableType)) { | |
727 | + tableTypes.add(tableType); | |
728 | + } | |
720 | 729 | } |
730 | + } finally { | |
731 | + rs.close(); | |
721 | 732 | } |
722 | - } finally { | |
723 | - rs.close(); | |
733 | + } catch (SQLException ex) { | |
734 | + log.warn("getTableTypes at getTableTypeNodes", ex); | |
724 | 735 | } |
725 | - if (a.isEmpty()) { | |
726 | - a.add(new TableTypeNode(catalog, schema, "TABLE")); | |
736 | + List<TableTypeNode> a = new ArrayList<TableTypeNode>(); | |
737 | + for (final String tableType : tableTypes) { | |
738 | + TableTypeNode typeNode = new TableTypeNode(catalog, schema, tableType); | |
739 | + if (typeNode.hasItems(dbmeta)) { | |
740 | + a.add(typeNode); | |
741 | + } | |
727 | 742 | } |
728 | 743 | return a; |
729 | 744 | } |
@@ -837,8 +852,7 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea | ||
837 | 852 | while (rs.next()) { |
838 | 853 | final String table = rs.getString(3); |
839 | 854 | final String type = rs.getString(4); |
840 | - final boolean kindOfTable = type.matches("TABLE|VIEW|SYNONYM"); | |
841 | - a.add(new TableNode(catalog, schema, table, kindOfTable)); | |
855 | + a.add(new TableNode(catalog, schema, table, type)); | |
842 | 856 | } |
843 | 857 | } finally { |
844 | 858 | rs.close(); |
@@ -871,14 +885,14 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea | ||
871 | 885 | private final String catalog; |
872 | 886 | private final String schema; |
873 | 887 | private final String name; |
874 | - private final boolean kindOfTable; | |
888 | + private final String tableType; | |
875 | 889 | |
876 | - TableNode(String catalog, String schema, String name, boolean kindOfTable) { | |
890 | + TableNode(String catalog, String schema, String name, String tableType) { | |
877 | 891 | super(name); |
878 | 892 | this.catalog = catalog; |
879 | 893 | this.schema = schema; |
880 | 894 | this.name = name; |
881 | - this.kindOfTable = kindOfTable; | |
895 | + this.tableType = tableType; | |
882 | 896 | } |
883 | 897 | |
884 | 898 | @Override |
@@ -901,6 +915,9 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea | ||
901 | 915 | |
902 | 916 | @Override |
903 | 917 | public boolean isLeaf() { |
918 | + if (TABLE_TYPE_SEQUENCE.equals(tableType)) { | |
919 | + return true; | |
920 | + } | |
904 | 921 | return false; |
905 | 922 | } |
906 | 923 |
@@ -921,10 +938,6 @@ final class DatabaseInfoTree extends JTree implements AnyActionListener, TextSea | ||
921 | 938 | return name; |
922 | 939 | } |
923 | 940 | |
924 | - boolean isKindOfTable() { | |
925 | - return kindOfTable; | |
926 | - } | |
927 | - | |
928 | 941 | } |
929 | 942 | |
930 | 943 | static final class ColumnNode extends InfoNode { |