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

mybatis / generator / 1602

26 Feb 2025 05:58PM UTC coverage: 88.328% (-0.01%) from 88.339%
1602

push

github

web-flow
Merge pull request #1297 from jeffgbutler/java-17

Code Cleanup after Java 17 Update

2518 of 3412 branches covered (73.8%)

163 of 180 new or added lines in 53 files covered. (90.56%)

12 existing lines in 5 files now uncovered.

11192 of 12671 relevant lines covered (88.33%)

0.88 hits per line

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

73.08
/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(
109
            boolean deleteByPrimaryKeyStatementEnabled) {
110
        this.deleteByPrimaryKeyStatementEnabled = deleteByPrimaryKeyStatementEnabled;
×
111
    }
×
112

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

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

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

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

130
    public boolean isUpdateByPrimaryKeyStatementEnabled() {
131
        return updateByPrimaryKeyStatementEnabled;
1✔
132
    }
133

134
    public void setUpdateByPrimaryKeyStatementEnabled(
135
            boolean updateByPrimaryKeyStatementEnabled) {
136
        this.updateByPrimaryKeyStatementEnabled = updateByPrimaryKeyStatementEnabled;
×
137
    }
×
138

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

148
        for (IgnoredColumnPattern ignoredColumnPattern : ignoredColumnPatterns) {
1✔
149
            if (ignoredColumnPattern.matches(columnName)) {
1✔
150
                return true;
1✔
151
            }
152
        }
1✔
153

154
        return false;
1✔
155
    }
156

157
    public void addIgnoredColumn(IgnoredColumn ignoredColumn) {
158
        ignoredColumns.put(ignoredColumn, Boolean.FALSE);
1✔
159
    }
1✔
160

161
    public void addIgnoredColumnPattern(IgnoredColumnPattern ignoredColumnPattern) {
162
        ignoredColumnPatterns.add(ignoredColumnPattern);
1✔
163
    }
1✔
164

165
    public void addColumnOverride(ColumnOverride columnOverride) {
166
        columnOverrides.add(columnOverride);
1✔
167
    }
1✔
168

169
    @Override
170
    public boolean equals(Object obj) {
171
        if (this == obj) {
×
172
            return true;
×
173
        }
174

NEW
175
        if (!(obj instanceof TableConfiguration other)) {
×
176
            return false;
×
177
        }
178

179
        return Objects.equals(this.catalog, other.catalog)
×
UNCOV
180
                && Objects.equals(this.schema, other.schema)
×
181
                && Objects.equals(this.tableName, other.tableName);
×
182
    }
183

184
    @Override
185
    public int hashCode() {
186
        return Objects.hash(catalog, schema, tableName);
×
187
    }
188

189
    public boolean isSelectByExampleStatementEnabled() {
190
        return selectByExampleStatementEnabled;
1✔
191
    }
192

193
    public void setSelectByExampleStatementEnabled(
194
            boolean selectByExampleStatementEnabled) {
195
        this.selectByExampleStatementEnabled = selectByExampleStatementEnabled;
1✔
196
    }
1✔
197

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

218
        return null;
1✔
219
    }
220

221
    public Optional<GeneratedKey> getGeneratedKey() {
222
        return Optional.ofNullable(generatedKey);
1✔
223
    }
224

225
    public String getSelectByExampleQueryId() {
226
        return selectByExampleQueryId;
1✔
227
    }
228

229
    public void setSelectByExampleQueryId(String selectByExampleQueryId) {
230
        this.selectByExampleQueryId = selectByExampleQueryId;
×
231
    }
×
232

233
    public String getSelectByPrimaryKeyQueryId() {
234
        return selectByPrimaryKeyQueryId;
1✔
235
    }
236

237
    public void setSelectByPrimaryKeyQueryId(String selectByPrimaryKeyQueryId) {
238
        this.selectByPrimaryKeyQueryId = selectByPrimaryKeyQueryId;
×
239
    }
×
240

241
    public boolean isDeleteByExampleStatementEnabled() {
242
        return deleteByExampleStatementEnabled;
1✔
243
    }
244

245
    public void setDeleteByExampleStatementEnabled(
246
            boolean deleteByExampleStatementEnabled) {
247
        this.deleteByExampleStatementEnabled = deleteByExampleStatementEnabled;
×
248
    }
×
249

250
    public boolean areAnyStatementsEnabled() {
251
        return selectByExampleStatementEnabled
1!
252
                || selectByPrimaryKeyStatementEnabled || insertStatementEnabled
253
                || updateByPrimaryKeyStatementEnabled
254
                || deleteByExampleStatementEnabled
255
                || deleteByPrimaryKeyStatementEnabled
256
                || countByExampleStatementEnabled
257
                || updateByExampleStatementEnabled;
258
    }
259

260
    public void setGeneratedKey(GeneratedKey generatedKey) {
261
        this.generatedKey = generatedKey;
1✔
262
    }
1✔
263

264
    public String getAlias() {
265
        return alias;
1✔
266
    }
267

268
    public void setAlias(String alias) {
269
        this.alias = alias;
1✔
270
    }
1✔
271

272
    public String getCatalog() {
273
        return catalog;
1✔
274
    }
275

276
    public void setCatalog(String catalog) {
277
        this.catalog = catalog;
×
278
    }
×
279

280
    public String getDomainObjectName() {
281
        return domainObjectName;
1✔
282
    }
283

284
    public void setDomainObjectName(String domainObjectName) {
285
        this.domainObjectName = domainObjectName;
1✔
286
    }
1✔
287

288
    public String getSchema() {
289
        return schema;
1✔
290
    }
291

292
    public void setSchema(String schema) {
293
        this.schema = schema;
1✔
294
    }
1✔
295

296
    public String getTableName() {
297
        return tableName;
1✔
298
    }
299

300
    public void setTableName(String tableName) {
301
        this.tableName = tableName;
1✔
302
    }
1✔
303

304
    public List<ColumnOverride> getColumnOverrides() {
305
        return columnOverrides;
1✔
306
    }
307

308
    /**
309
     * Returns a List of Strings. The values are the columns
310
     * that were specified to be ignored in the table, but do not exist in the
311
     * table.
312
     *
313
     * @return a List of Strings - the columns that were improperly configured
314
     *         as ignored columns
315
     */
316
    public List<String> getIgnoredColumnsInError() {
317
        List<String> answer = new ArrayList<>();
1✔
318

319
        for (Map.Entry<IgnoredColumn, Boolean> entry : ignoredColumns
1✔
320
                .entrySet()) {
1✔
321
            if (Boolean.FALSE.equals(entry.getValue())) {
1✔
322
                answer.add(entry.getKey().getColumnName());
1✔
323
            }
324
        }
1✔
325

326
        return answer;
1✔
327
    }
328

329
    public ModelType getModelType() {
330
        return modelType;
1✔
331
    }
332

333
    public void setConfiguredModelType(String configuredModelType) {
334
        this.modelType = ModelType.getModelType(configuredModelType);
×
335
    }
×
336

337
    public boolean isWildcardEscapingEnabled() {
338
        return wildcardEscapingEnabled;
1✔
339
    }
340

341
    public void setWildcardEscapingEnabled(boolean wildcardEscapingEnabled) {
342
        this.wildcardEscapingEnabled = wildcardEscapingEnabled;
×
343
    }
×
344

345
    @Override
346
    public String toString() {
347
        return composeFullyQualifiedTableName(catalog, schema,
×
348
                tableName, '.');
349
    }
350

351
    public boolean isDelimitIdentifiers() {
352
        return delimitIdentifiers;
1✔
353
    }
354

355
    public void setDelimitIdentifiers(boolean delimitIdentifiers) {
356
        this.delimitIdentifiers = delimitIdentifiers;
×
357
    }
×
358

359
    public boolean isCountByExampleStatementEnabled() {
360
        return countByExampleStatementEnabled;
1✔
361
    }
362

363
    public void setCountByExampleStatementEnabled(
364
            boolean countByExampleStatementEnabled) {
365
        this.countByExampleStatementEnabled = countByExampleStatementEnabled;
×
366
    }
×
367

368
    public boolean isUpdateByExampleStatementEnabled() {
369
        return updateByExampleStatementEnabled;
1✔
370
    }
371

372
    public void setUpdateByExampleStatementEnabled(
373
            boolean updateByExampleStatementEnabled) {
374
        this.updateByExampleStatementEnabled = updateByExampleStatementEnabled;
×
375
    }
×
376

377
    public void validate(List<String> errors, int listPosition) {
378
        if (!stringHasValue(tableName)) {
1!
379
            errors.add(Messages.getString(
×
380
                    "ValidationError.6", Integer.toString(listPosition))); //$NON-NLS-1$
×
381
        }
382

383
        String fqTableName = composeFullyQualifiedTableName(
1✔
384
                catalog, schema, tableName, '.');
385

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

390
        // when using column indexes, either both or neither query ids
391
        // should be set
392
        if (isTrue(getProperty(PropertyRegistry.TABLE_USE_COLUMN_INDEXES))
1!
393
                && selectByExampleStatementEnabled
394
                && selectByPrimaryKeyStatementEnabled) {
395
            boolean queryId1Set = stringHasValue(selectByExampleQueryId);
1✔
396
            boolean queryId2Set = stringHasValue(selectByPrimaryKeyQueryId);
1✔
397

398
            if (queryId1Set != queryId2Set) {
1!
399
                errors.add(Messages.getString("ValidationError.13", //$NON-NLS-1$
×
400
                        fqTableName));
401
            }
402
        }
403

404
        if (domainObjectRenamingRule != null) {
1✔
405
            domainObjectRenamingRule.validate(errors, fqTableName);
1✔
406
        }
407

408
        if (columnRenamingRule != null) {
1✔
409
            columnRenamingRule.validate(errors, fqTableName);
1✔
410
        }
411

412
        for (ColumnOverride columnOverride : columnOverrides) {
1✔
413
            columnOverride.validate(errors, fqTableName);
1✔
414
        }
1✔
415

416
        for (IgnoredColumn ignoredColumn : ignoredColumns.keySet()) {
1✔
417
            ignoredColumn.validate(errors, fqTableName);
1✔
418
        }
1✔
419

420
        for (IgnoredColumnPattern ignoredColumnPattern : ignoredColumnPatterns) {
1✔
421
            ignoredColumnPattern.validate(errors, fqTableName);
1✔
422
        }
1✔
423
    }
1✔
424

425
    public DomainObjectRenamingRule getDomainObjectRenamingRule() {
426
        return domainObjectRenamingRule;
1✔
427
    }
428

429
    public void setDomainObjectRenamingRule(DomainObjectRenamingRule domainObjectRenamingRule) {
430
        this.domainObjectRenamingRule = domainObjectRenamingRule;
1✔
431
    }
1✔
432

433
    public ColumnRenamingRule getColumnRenamingRule() {
434
        return columnRenamingRule;
1✔
435
    }
436

437
    public void setColumnRenamingRule(ColumnRenamingRule columnRenamingRule) {
438
        this.columnRenamingRule = columnRenamingRule;
1✔
439
    }
1✔
440

441
    public boolean isAllColumnDelimitingEnabled() {
442
        return isAllColumnDelimitingEnabled;
1✔
443
    }
444

445
    public void setAllColumnDelimitingEnabled(
446
            boolean isAllColumnDelimitingEnabled) {
447
        this.isAllColumnDelimitingEnabled = isAllColumnDelimitingEnabled;
×
448
    }
×
449

450
    public String getMapperName() {
451
        return mapperName;
1✔
452
    }
453

454
    public void setMapperName(String mapperName) {
455
        this.mapperName = mapperName;
1✔
456
    }
1✔
457

458
    public String getSqlProviderName() {
459
        return sqlProviderName;
1✔
460
    }
461

462
    public void setSqlProviderName(String sqlProviderName) {
463
        this.sqlProviderName = sqlProviderName;
×
464
    }
×
465

466
    public String getDynamicSqlSupportClassName() {
467
        return getProperty(PropertyRegistry.TABLE_DYNAMIC_SQL_SUPPORT_CLASS_NAME);
1✔
468
    }
469

470
    public String getDynamicSqlTableObjectName() {
471
        return getProperty(PropertyRegistry.TABLE_DYNAMIC_SQL_TABLE_OBJECT_NAME);
1✔
472
    }
473
}
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