Search in sources :

Example 1 with ConnectionFactoryConfiguration

use of org.mybatis.generator.config.ConnectionFactoryConfiguration in project generator by mybatis.

the class MyBatisGeneratorTest method testGenerateInvalidConfigWithTwoConnectionSources.

@Test
void testGenerateInvalidConfigWithTwoConnectionSources() {
    List<String> warnings = new ArrayList<>();
    Configuration config = new Configuration();
    Context context = new Context(ModelType.HIERARCHICAL);
    context.setId("MyContext");
    context.setConnectionFactoryConfiguration(new ConnectionFactoryConfiguration());
    context.setJdbcConnectionConfiguration(new JDBCConnectionConfiguration());
    config.addContext(context);
    DefaultShellCallback shellCallback = new DefaultShellCallback(true);
    InvalidConfigurationException e = assertThrows(InvalidConfigurationException.class, () -> {
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
        myBatisGenerator.generate(null, null, null, false);
    });
    assertEquals(3, e.getErrors().size());
}
Also used : Context(org.mybatis.generator.config.Context) Configuration(org.mybatis.generator.config.Configuration) ConnectionFactoryConfiguration(org.mybatis.generator.config.ConnectionFactoryConfiguration) JDBCConnectionConfiguration(org.mybatis.generator.config.JDBCConnectionConfiguration) ArrayList(java.util.ArrayList) DefaultShellCallback(org.mybatis.generator.internal.DefaultShellCallback) JDBCConnectionConfiguration(org.mybatis.generator.config.JDBCConnectionConfiguration) ConnectionFactoryConfiguration(org.mybatis.generator.config.ConnectionFactoryConfiguration) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator) Test(org.junit.jupiter.api.Test)

Example 2 with ConnectionFactoryConfiguration

use of org.mybatis.generator.config.ConnectionFactoryConfiguration in project generator by mybatis.

the class ObjectFactory method createConnectionFactory.

public static ConnectionFactory createConnectionFactory(Context context) {
    ConnectionFactoryConfiguration config = context.getConnectionFactoryConfiguration();
    ConnectionFactory answer;
    String type;
    if (config == null || config.getConfigurationType() == null) {
        type = JDBCConnectionFactory.class.getName();
    } else {
        type = config.getConfigurationType();
    }
    answer = (ConnectionFactory) createInternalObject(type);
    if (config != null) {
        answer.addConfigurationProperties(config.getProperties());
    }
    return answer;
}
Also used : ConnectionFactory(org.mybatis.generator.api.ConnectionFactory) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) ConnectionFactoryConfiguration(org.mybatis.generator.config.ConnectionFactoryConfiguration)

Example 3 with ConnectionFactoryConfiguration

use of org.mybatis.generator.config.ConnectionFactoryConfiguration in project generator by mybatis.

the class MyBatisGeneratorConfigurationParser method parseConnectionFactory.

protected void parseConnectionFactory(Context context, Node node) {
    ConnectionFactoryConfiguration connectionFactoryConfiguration = new ConnectionFactoryConfiguration();
    context.setConnectionFactoryConfiguration(connectionFactoryConfiguration);
    Properties attributes = parseAttributes(node);
    // $NON-NLS-1$
    String type = attributes.getProperty("type");
    if (stringHasValue(type)) {
        connectionFactoryConfiguration.setConfigurationType(type);
    }
    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);
        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        if ("property".equals(childNode.getNodeName())) {
            // $NON-NLS-1$
            parseProperty(connectionFactoryConfiguration, childNode);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) Properties(java.util.Properties) ConnectionFactoryConfiguration(org.mybatis.generator.config.ConnectionFactoryConfiguration)

Aggregations

ConnectionFactoryConfiguration (org.mybatis.generator.config.ConnectionFactoryConfiguration)3 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)2 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Test (org.junit.jupiter.api.Test)1 ConnectionFactory (org.mybatis.generator.api.ConnectionFactory)1 MyBatisGenerator (org.mybatis.generator.api.MyBatisGenerator)1 Configuration (org.mybatis.generator.config.Configuration)1 Context (org.mybatis.generator.config.Context)1 JDBCConnectionConfiguration (org.mybatis.generator.config.JDBCConnectionConfiguration)1 InvalidConfigurationException (org.mybatis.generator.exception.InvalidConfigurationException)1 DefaultShellCallback (org.mybatis.generator.internal.DefaultShellCallback)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1