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;
}
}
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);
}
}
}
Aggregations