Skip to content

Commit 0660fc9

Browse files
committed
feat: add table name pattern selection
1 parent bdf5f2b commit 0660fc9

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/main/java/com/spawpaw/mybatis/generator/gui/DatabaseConfig.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class DatabaseConfig implements Serializable {
3333
public SimpleStringProperty databaseType = new SimpleStringProperty("MySQL");
3434
@Config(bundle = "database.dbName")
3535
public SimpleStringProperty dbName = new SimpleStringProperty("");
36+
@Config(bundle = "database.tableNamePattern", testRegex = "%", type = ConfigType.ComboBox)
37+
public SimpleStringProperty tableNamePattern = new SimpleStringProperty("%");
3638
@Config(bundle = "database.host")
3739
public SimpleStringProperty host = new SimpleStringProperty("localhost");
3840
@Config(bundle = "database.port")
@@ -96,6 +98,8 @@ public TreeItem<String> getRootTreeItem() {
9698
public void connect() throws SQLException {
9799
if (tableConfigs != null && tableConfigs.size() != 0) return;
98100
tableConfigs = new Hashtable<>();
101+
if (tableNamePattern.getValue().isEmpty())
102+
tableNamePattern.setValue("%");
99103
Connection connection = getConnection();
100104
DatabaseMetaData meta = connection.getMetaData();
101105
ResultSet rs;
@@ -105,32 +109,36 @@ public void connect() throws SQLException {
105109
//获取表列表
106110
switch (DatabaseType.valueOf(databaseType.getValue())) {
107111
case MySQL:
108-
rs = meta.getTables(null, dbName.getValue(), null, types);
112+
rs = meta.getTables(
113+
dbName.getValue().isEmpty() ? null : dbName.getValue()
114+
, "%"
115+
, tableNamePattern.getValue()
116+
, types);
109117
break;
110118
case Oracle:
111119
case Oracle_SID:
112120
case Oracle_ServiceName:
113121
case Oracle_TNSName:
114122
case Oracle_TNSEntryString:
115-
rs = meta.getTables(null, userName.getValue().toUpperCase(), null, types);
123+
rs = meta.getTables(null, userName.getValue().toUpperCase(), tableNamePattern.getValue(), types);
116124
break;
117125
case SQLServer:
118126
case SQLServer_InstanceBased:
119127
sql = "select name as TABLE_NAME from sysobjects where xtype='u' or xtype='v' ";
120128
rs = connection.createStatement().executeQuery(sql);
121129
break;
122130
case PostgreSQL:
123-
rs = meta.getTables(null, "%", "%", types);
131+
rs = meta.getTables(null, "%", tableNamePattern.getValue(), types);
124132
break;
125133
case DB2MF:
126134
case DB2:
127-
rs = meta.getTables(null, "jence_user", "%", types);
135+
rs = meta.getTables(null, "jence_user", tableNamePattern.getValue(), types);
128136
break;
129137
case SYBASE:
130-
rs = meta.getTables(null, null, "%", types);
138+
rs = meta.getTables(null, null, tableNamePattern.getValue(), types);
131139
break;
132140
case INFORMIX:
133-
rs = meta.getTables(null, null, "%", types);
141+
rs = meta.getTables(null, null, tableNamePattern.getValue(), types);
134142
break;
135143
default:
136144
throw new RuntimeException(Constants.getI18nStr("msg.unsupportedDatabase"));

0 commit comments

Comments
 (0)