Search in sources :

Example 1 with JDBCConnectionConfiguration

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

the class MyBatisGeneratorTest method testGenerateInvalidConfigWithTwoConnectionSources.

@Test(expected = InvalidConfigurationException.class)
public void testGenerateInvalidConfigWithTwoConnectionSources() throws Exception {
    List<String> warnings = new ArrayList<String>();
    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);
    try {
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
        myBatisGenerator.generate(null, null, null, false);
    } catch (InvalidConfigurationException e) {
        assertEquals(3, e.getErrors().size());
        throw e;
    }
}
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) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) Test(org.junit.Test)

Example 2 with JDBCConnectionConfiguration

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

the class MyBatisGeneratorConfigurationParser method parseJdbcConnection.

protected void parseJdbcConnection(Context context, Node node) {
    JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();
    context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);
    Properties attributes = parseAttributes(node);
    //$NON-NLS-1$
    String driverClass = attributes.getProperty("driverClass");
    //$NON-NLS-1$
    String connectionURL = attributes.getProperty("connectionURL");
    //$NON-NLS-1$
    String userId = attributes.getProperty("userId");
    //$NON-NLS-1$
    String password = attributes.getProperty("password");
    jdbcConnectionConfiguration.setDriverClass(driverClass);
    jdbcConnectionConfiguration.setConnectionURL(connectionURL);
    if (stringHasValue(userId)) {
        jdbcConnectionConfiguration.setUserId(userId);
    }
    if (stringHasValue(password)) {
        jdbcConnectionConfiguration.setPassword(password);
    }
    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(jdbcConnectionConfiguration, childNode);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) JDBCConnectionConfiguration(org.mybatis.generator.config.JDBCConnectionConfiguration) Properties(java.util.Properties)

Aggregations

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