• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / generator / 1646

21 Apr 2025 10:17PM UTC coverage: 88.157% (-0.2%) from 88.328%
1646

push

github

hazendaz
[ci] Run auto formatting

2518 of 3412 branches covered (73.8%)

994 of 1117 new or added lines in 164 files covered. (88.99%)

23 existing lines in 12 files now uncovered.

10578 of 11999 relevant lines covered (88.16%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.68
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/config/TableConfiguration.java
1
/*
2
 *    Copyright 2006-2025 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.mybatis.generator.config;
17

18
import static org.mybatis.generator.internal.util.StringUtility.composeFullyQualifiedTableName;
19
import static org.mybatis.generator.internal.util.StringUtility.isTrue;
20
import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
21

22
import java.util.ArrayList;
23
import java.util.HashMap;
24
import java.util.List;
25
import java.util.Map;
26
import java.util.Objects;
27
import java.util.Optional;
28

29
import org.mybatis.generator.internal.util.messages.Messages;
30

31
public class TableConfiguration extends PropertyHolder {
32

33
    private boolean insertStatementEnabled;
34

35
    private boolean selectByPrimaryKeyStatementEnabled;
36

37
    private boolean selectByExampleStatementEnabled;
38

39
    private boolean updateByPrimaryKeyStatementEnabled;
40

41
    private boolean deleteByPrimaryKeyStatementEnabled;
42

43
    private boolean deleteByExampleStatementEnabled;
44

45
    private boolean countByExampleStatementEnabled;
46

47
    private boolean updateByExampleStatementEnabled;
48

49
    private final List<ColumnOverride> columnOverrides;
50

51
    private final Map<IgnoredColumn, Boolean> ignoredColumns;
52

53
    private GeneratedKey generatedKey;
54

55
    private String selectByPrimaryKeyQueryId;
56

57
    private String selectByExampleQueryId;
58

59
    private String catalog;
60

61
    private String schema;
62

63
    private String tableName;
64

65
    private String domainObjectName;
66

67
    private String alias;
68

69
    private ModelType modelType;
70

71
    private boolean wildcardEscapingEnabled;
72

73
    private boolean delimitIdentifiers;
74

75
    private DomainObjectRenamingRule domainObjectRenamingRule;
76

77
    private ColumnRenamingRule columnRenamingRule;
78

79
    private boolean isAllColumnDelimitingEnabled;
80

81
    private String mapperName;
82
    private String sqlProviderName;
83

84
    private final List<IgnoredColumnPattern> ignoredColumnPatterns = new ArrayList<>();
1✔
85

86
    public TableConfiguration(Context context) {
87
        super();
1✔
88

89
        this.modelType = context.getDefaultModelType();
1✔
90

91
        columnOverrides = new ArrayList<>();
1✔
92
        ignoredColumns = new HashMap<>();
1✔
93

94
        insertStatementEnabled = true;
1✔
95
        selectByPrimaryKeyStatementEnabled = true;
1✔
96
        selectByExampleStatementEnabled = true;
1✔
97
        updateByPrimaryKeyStatementEnabled = true;
1✔
98
        deleteByPrimaryKeyStatementEnabled = true;
1✔
99
        deleteByExampleStatementEnabled = true;
1✔
100
        countByExampleStatementEnabled = true;
1✔
101
        updateByExampleStatementEnabled = true;
1✔
102
    }
1✔
103

104
    public boolean isDeleteByPrimaryKeyStatementEnabled() {
105
        return deleteByPrimaryKeyStatementEnabled;
1✔
106
    }
107

108
    public void setDeleteByPrimaryKeyStatementEnabled(boolean deleteByPrimaryKeyStatementEnabled) {
UNCOV
109
        this.deleteByPrimaryKeyStatementEnabled = deleteByPrimaryKeyStatementEnabled;
×
110
    }
×
111

112
    public boolean isInsertStatementEnabled() {
113
        return insertStatementEnabled;
1✔
114
    }
115

116
    public void setInsertStatementEnabled(boolean insertStatementEnabled) {
117
        this.insertStatementEnabled = insertStatementEnabled;
×
118
    }
×
119

120
    public boolean isSelectByPrimaryKeyStatementEnabled() {
121
        return selectByPrimaryKeyStatementEnabled;
1✔
122
    }
123

124
    public void setSelectByPrimaryKeyStatementEnabled(boolean selectByPrimaryKeyStatementEnabled) {
UNCOV
125
        this.selectByPrimaryKeyStatementEnabled = selectByPrimaryKeyStatementEnabled;
×
126
    }
×
127

128
    public boolean isUpdateByPrimaryKeyStatementEnabled() {
129
        return updateByPrimaryKeyStatementEnabled;
1✔
130
    }
131

132
    public void setUpdateByPrimaryKeyStatementEnabled(boolean updateByPrimaryKeyStatementEnabled) {
UNCOV
133
        this.updateByPrimaryKeyStatementEnabled = updateByPrimaryKeyStatementEnabled;
×
134
    }
×
135

136
    public boolean isColumnIgnored(String columnName) {
137
        for (Map.Entry<IgnoredColumn, Boolean> entry : ignoredColumns.entrySet()) {
1✔
138
            if (entry.getKey().matches(columnName)) {
1✔
139
                entry.setValue(Boolean.TRUE);
1✔
140
                return true;
1✔
141
            }
142
        }
1✔
143

144
        for (IgnoredColumnPattern ignoredColumnPattern : ignoredColumnPatterns) {
1✔
145
            if (ignoredColumnPattern.matches(columnName)) {
1✔
146
                return true;
1✔
147
            }
148
        }
1✔
149

150
        return false;
1✔
151
    }
152

153
    public void addIgnoredColumn(IgnoredColumn ignoredColumn) {
154
        ignoredColumns.put(ignoredColumn, Boolean.FALSE);
1✔
155
    }
1✔
156

157
    public void addIgnoredColumnPattern(IgnoredColumnPattern ignoredColumnPattern) {
158
        ignoredColumnPatterns.add(ignoredColumnPattern);
1✔
159
    }
1✔
160

161
    public void addColumnOverride(ColumnOverride columnOverride) {
162
        columnOverrides.add(columnOverride);
1✔
163
    }
1✔
164

165
    @Override
166
    public boolean equals(Object obj) {
167
        if (this == obj) {
×
168
            return true;
×
169
        }
170

171
        if (!(obj instanceof TableConfiguration other)) {
×
172
            return false;
×
173
        }
174

NEW
175
        return Objects.equals(this.catalog, other.catalog) && Objects.equals(this.schema, other.schema)
×
176
                && Objects.equals(this.tableName, other.tableName);
×
177
    }
178

179
    @Override
180
    public int hashCode() {
181
        return Objects.hash(catalog, schema, tableName);
×
182
    }
183

184
    public boolean isSelectByExampleStatementEnabled() {
185
        return selectByExampleStatementEnabled;
1✔
186
    }
187

188
    public void setSelectByExampleStatementEnabled(boolean selectByExampleStatementEnabled) {
189
        this.selectByExampleStatementEnabled = selectByExampleStatementEnabled;
1✔
190
    }
1✔
191

192
    /**
193
     * May return null if the column has not been overridden.
194
     *
195
     * @param columnName
196
     *            the column name
197
     *
198
     * @return the column override (if any) related to this column
199
     */
200
    public ColumnOverride getColumnOverride(String columnName) {
201
        for (ColumnOverride co : columnOverrides) {
1✔
202
            if (co.isColumnNameDelimited()) {
1✔
203
                if (columnName.equals(co.getColumnName())) {
1✔
204
                    return co;
1✔
205
                }
206
            } else {
207
                if (columnName.equalsIgnoreCase(co.getColumnName())) {
1✔
208
                    return co;
1✔
209
                }
210
            }
211
        }
1✔
212

213
        return null;
1✔
214
    }
215

216
    public Optional<GeneratedKey> getGeneratedKey() {
217
        return Optional.ofNullable(generatedKey);
1✔
218
    }
219

220
    public String getSelectByExampleQueryId() {
221
        return selectByExampleQueryId;
1✔
222
    }
223

224
    public void setSelectByExampleQueryId(String selectByExampleQueryId) {
225
        this.selectByExampleQueryId = selectByExampleQueryId;
×
226
    }
×
227

228
    public String getSelectByPrimaryKeyQueryId() {
229
        return selectByPrimaryKeyQueryId;
1✔
230
    }
231

232
    public void setSelectByPrimaryKeyQueryId(String selectByPrimaryKeyQueryId) {
233
        this.selectByPrimaryKeyQueryId = selectByPrimaryKeyQueryId;
×
234
    }
×
235

236
    public boolean isDeleteByExampleStatementEnabled() {
237
        return deleteByExampleStatementEnabled;
1✔
238
    }
239

240
    public void setDeleteByExampleStatementEnabled(boolean deleteByExampleStatementEnabled) {
UNCOV
241
        this.deleteByExampleStatementEnabled = deleteByExampleStatementEnabled;
×
242
    }
×
243

244
    public boolean areAnyStatementsEnabled() {
245
        return selectByExampleStatementEnabled || selectByPrimaryKeyStatementEnabled || insertStatementEnabled
1!
246
                || updateByPrimaryKeyStatementEnabled || deleteByExampleStatementEnabled
247
                || deleteByPrimaryKeyStatementEnabled || countByExampleStatementEnabled
248
                || updateByExampleStatementEnabled;
249
    }
250

251
    public void setGeneratedKey(GeneratedKey generatedKey) {
252
        this.generatedKey = generatedKey;
1✔
253
    }
1✔
254

255
    public String getAlias() {
256
        return alias;
1✔
257
    }
258

259
    public void setAlias(String alias) {
260
        this.alias = alias;
1✔
261
    }
1✔
262

263
    public String getCatalog() {
264
        return catalog;
1✔
265
    }
266

267
    public void setCatalog(String catalog) {
268
        this.catalog = catalog;
×
269
    }
×
270

271
    public String getDomainObjectName() {
272
        return domainObjectName;
1✔
273
    }
274

275
    public void setDomainObjectName(String domainObjectName) {
276
        this.domainObjectName = domainObjectName;
1✔
277
    }
1✔
278

279
    public String getSchema() {
280
        return schema;
1✔
281
    }
282

283
    public void setSchema(String schema) {
284
        this.schema = schema;
1✔
285
    }
1✔
286

287
    public String getTableName() {
288
        return tableName;
1✔
289
    }
290

291
    public void setTableName(String tableName) {
292
        this.tableName = tableName;
1✔
293
    }
1✔
294

295
    public List<ColumnOverride> getColumnOverrides() {
296
        return columnOverrides;
1✔
297
    }
298

299
    /**
300
     * Returns a List of Strings. The values are the columns that were specified to be ignored in the table, but do not
301
     * exist in the table.
302
     *
303
     * @return a List of Strings - the columns that were improperly configured as ignored columns
304
     */
305
    public List<String> getIgnoredColumnsInError() {
306
        List<String> answer = new ArrayList<>();
1✔
307

308
        for (Map.Entry<IgnoredColumn, Boolean> entry : ignoredColumns.entrySet()) {
1✔
309
            if (Boolean.FALSE.equals(entry.getValue())) {
1✔
310
                answer.add(entry.getKey().getColumnName());
1✔
311
            }
312
        }
1✔
313

314
        return answer;
1✔
315
    }
316

317
    public ModelType getModelType() {
318
        return modelType;
1✔
319
    }
320

321
    public void setConfiguredModelType(String configuredModelType) {
322
        this.modelType = ModelType.getModelType(configuredModelType);
×
323
    }
×
324

325
    public boolean isWildcardEscapingEnabled() {
326
        return wildcardEscapingEnabled;
1✔
327
    }
328

329
    public void setWildcardEscapingEnabled(boolean wildcardEscapingEnabled) {
330
        this.wildcardEscapingEnabled = wildcardEscapingEnabled;
×
331
    }
×
332

333
    @Override
334
    public String toString() {
NEW
335
        return composeFullyQualifiedTableName(catalog, schema, tableName, '.');
×
336
    }
337

338
    public boolean isDelimitIdentifiers() {
339
        return delimitIdentifiers;
1✔
340
    }
341

342
    public void setDelimitIdentifiers(boolean delimitIdentifiers) {
343
        this.delimitIdentifiers = delimitIdentifiers;
×
344
    }
×
345

346
    public boolean isCountByExampleStatementEnabled() {
347
        return countByExampleStatementEnabled;
1✔
348
    }
349

350
    public void setCountByExampleStatementEnabled(boolean countByExampleStatementEnabled) {
UNCOV
351
        this.countByExampleStatementEnabled = countByExampleStatementEnabled;
×
352
    }
×
353

354
    public boolean isUpdateByExampleStatementEnabled() {
355
        return updateByExampleStatementEnabled;
1✔
356
    }
357

358
    public void setUpdateByExampleStatementEnabled(boolean updateByExampleStatementEnabled) {
UNCOV
359
        this.updateByExampleStatementEnabled = updateByExampleStatementEnabled;
×
360
    }
×
361

362
    public void validate(List<String> errors, int listPosition) {
363
        if (!stringHasValue(tableName)) {
1!
NEW
364
            errors.add(Messages.getString("ValidationError.6", Integer.toString(listPosition))); //$NON-NLS-1$
×
365
        }
366

367
        String fqTableName = composeFullyQualifiedTableName(catalog, schema, tableName, '.');
1✔
368

369
        if (generatedKey != null) {
1✔
370
            generatedKey.validate(errors, fqTableName);
1✔
371
        }
372

373
        // when using column indexes, either both or neither query ids
374
        // should be set
375
        if (isTrue(getProperty(PropertyRegistry.TABLE_USE_COLUMN_INDEXES)) && selectByExampleStatementEnabled
1!
376
                && selectByPrimaryKeyStatementEnabled) {
377
            boolean queryId1Set = stringHasValue(selectByExampleQueryId);
1✔
378
            boolean queryId2Set = stringHasValue(selectByPrimaryKeyQueryId);
1✔
379

380
            if (queryId1Set != queryId2Set) {
1!
381
                errors.add(Messages.getString("ValidationError.13", //$NON-NLS-1$
×
382
                        fqTableName));
383
            }
384
        }
385

386
        if (domainObjectRenamingRule != null) {
1✔
387
            domainObjectRenamingRule.validate(errors, fqTableName);
1✔
388
        }
389

390
        if (columnRenamingRule != null) {
1✔
391
            columnRenamingRule.validate(errors, fqTableName);
1✔
392
        }
393

394
        for (ColumnOverride columnOverride : columnOverrides) {
1✔
395
            columnOverride.validate(errors, fqTableName);
1✔
396
        }
1✔
397

398
        for (IgnoredColumn ignoredColumn : ignoredColumns.keySet()) {
1✔
399
            ignoredColumn.validate(errors, fqTableName);
1✔
400
        }
1✔
401

402
        for (IgnoredColumnPattern ignoredColumnPattern : ignoredColumnPatterns) {
1✔
403
            ignoredColumnPattern.validate(errors, fqTableName);
1✔
404
        }
1✔
405
    }
1✔
406

407
    public DomainObjectRenamingRule getDomainObjectRenamingRule() {
408
        return domainObjectRenamingRule;
1✔
409
    }
410

411
    public void setDomainObjectRenamingRule(DomainObjectRenamingRule domainObjectRenamingRule) {
412
        this.domainObjectRenamingRule = domainObjectRenamingRule;
1✔
413
    }
1✔
414

415
    public ColumnRenamingRule getColumnRenamingRule() {
416
        return columnRenamingRule;
1✔
417
    }
418

419
    public void setColumnRenamingRule(ColumnRenamingRule columnRenamingRule) {
420
        this.columnRenamingRule = columnRenamingRule;
1✔
421
    }
1✔
422

423
    public boolean isAllColumnDelimitingEnabled() {
424
        return isAllColumnDelimitingEnabled;
1✔
425
    }
426

427
    public void setAllColumnDelimitingEnabled(boolean isAllColumnDelimitingEnabled) {
UNCOV
428
        this.isAllColumnDelimitingEnabled = isAllColumnDelimitingEnabled;
×
429
    }
×
430

431
    public String getMapperName() {
432
        return mapperName;
1✔
433
    }
434

435
    public void setMapperName(String mapperName) {
436
        this.mapperName = mapperName;
1✔
437
    }
1✔
438

439
    public String getSqlProviderName() {
440
        return sqlProviderName;
1✔
441
    }
442

443
    public void setSqlProviderName(String sqlProviderName) {
444
        this.sqlProviderName = sqlProviderName;
×
445
    }
×
446

447
    public String getDynamicSqlSupportClassName() {
448
        return getProperty(PropertyRegistry.TABLE_DYNAMIC_SQL_SUPPORT_CLASS_NAME);
1✔
449
    }
450

451
    public String getDynamicSqlTableObjectName() {
452
        return getProperty(PropertyRegistry.TABLE_DYNAMIC_SQL_TABLE_OBJECT_NAME);
1✔
453
    }
454
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc