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

mybatis / generator / 1945

14 Jan 2026 02:23PM UTC coverage: 88.838% (+0.04%) from 88.799%
1945

Pull #1414

github

web-flow
Merge 5eec5583d into 5d3363986
Pull Request #1414: Major Refactoring - Context is now configuration only, Plugins Potentially Impacted

2347 of 3184 branches covered (73.71%)

490 of 582 new or added lines in 133 files covered. (84.19%)

2 existing lines in 1 file now uncovered.

11517 of 12964 relevant lines covered (88.84%)

0.89 hits per line

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

66.67
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/ConnectionUtility.java
1
/*
2
 *    Copyright 2006-2026 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.codegen;
17

18
import java.sql.Connection;
19
import java.sql.SQLException;
20

21
import org.mybatis.generator.config.ConnectionFactoryConfiguration;
22
import org.mybatis.generator.config.Context;
23
import org.mybatis.generator.config.JDBCConnectionConfiguration;
24
import org.mybatis.generator.internal.JDBCConnectionFactory;
25
import org.mybatis.generator.internal.ObjectFactory;
26

NEW
27
public class ConnectionUtility {
×
28
    /**
29
     * This method creates a new JDBC connection from the values specified in the configuration file.
30
     *
31
     * <p>If you call this method, then you are responsible for closing the connection when you are done with it.
32
     * The best practice is to call the method in a try with resources to ensure proper cleanup.
33
     *
34
     * @param context the context containing the connection configuration
35
     * @return a new connection created from the values in the configuration file
36
     *
37
     * @throws SQLException if any error occurs while creating the connection
38
     */
39
    public static Connection getConnection(Context context) throws SQLException {
40
        // if both configs are null, it is an internal error - we should have caught that with validation
41

42
        JDBCConnectionConfiguration jdbcConfig = context.getJDBCConnectionConfiguration();
1✔
43
        if (jdbcConfig != null) {
1✔
44
            return new JDBCConnectionFactory(jdbcConfig).getConnection();
1✔
45
        } else {
46
            ConnectionFactoryConfiguration config = context.getConnectionFactoryConfiguration();
1✔
47
            if (config == null) {
1!
NEW
48
                throw new RuntimeException("Internal Error - no connection configured in context: "
×
NEW
49
                        + context.getId());
×
50
            }
51

52
            return ObjectFactory.createConnectionFactory(config).getConnection();
1✔
53
        }
54
    }
55
}
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