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