use of org.mybatis.generator.config.Configuration in project paascloud-master by paascloud.
the class MybatisGenerator method main.
/**
* The entry point of application.
*
* @param args the input arguments
*
* @throws Exception the exception
*/
public static void main(String[] args) throws Exception {
List<String> warnings = new ArrayList<>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(Generator.class.getResourceAsStream("/generator/generatorConfig.xml"));
DefaultShellCallback callback = new DefaultShellCallback(true);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
}
use of org.mybatis.generator.config.Configuration in project generator by mybatis.
the class MyBatisGeneratorConfigurationParser method parseConfiguration.
public Configuration parseConfiguration(Element rootNode) throws XMLParserException {
Configuration configuration = new Configuration();
NodeList nodeList = rootNode.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if ("properties".equals(childNode.getNodeName())) {
//$NON-NLS-1$
parseProperties(configuration, childNode);
} else if ("classPathEntry".equals(childNode.getNodeName())) {
//$NON-NLS-1$
parseClassPathEntry(configuration, childNode);
} else if ("context".equals(childNode.getNodeName())) {
//$NON-NLS-1$
parseContext(configuration, childNode);
}
}
return configuration;
}
use of org.mybatis.generator.config.Configuration in project generator by mybatis.
the class ConfigurationParser method parseConfiguration.
private Configuration parseConfiguration(InputSource inputSource) throws IOException, XMLParserException {
parseErrors.clear();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(new ParserEntityResolver());
ParserErrorHandler handler = new ParserErrorHandler(warnings, parseErrors);
builder.setErrorHandler(handler);
Document document = null;
try {
document = builder.parse(inputSource);
} catch (SAXParseException e) {
throw new XMLParserException(parseErrors);
} catch (SAXException e) {
if (e.getException() == null) {
parseErrors.add(e.getMessage());
} else {
parseErrors.add(e.getException().getMessage());
}
}
if (parseErrors.size() > 0) {
throw new XMLParserException(parseErrors);
}
Configuration config;
Element rootNode = document.getDocumentElement();
DocumentType docType = document.getDoctype();
if (rootNode.getNodeType() == Node.ELEMENT_NODE && docType.getPublicId().equals(XmlConstants.IBATOR_CONFIG_PUBLIC_ID)) {
config = parseIbatorConfiguration(rootNode);
} else if (rootNode.getNodeType() == Node.ELEMENT_NODE && docType.getPublicId().equals(XmlConstants.MYBATIS_GENERATOR_CONFIG_PUBLIC_ID)) {
config = parseMyBatisGeneratorConfiguration(rootNode);
} else {
//$NON-NLS-1$
throw new XMLParserException(getString("RuntimeError.5"));
}
if (parseErrors.size() > 0) {
throw new XMLParserException(parseErrors);
}
return config;
} catch (ParserConfigurationException e) {
parseErrors.add(e.getMessage());
throw new XMLParserException(parseErrors);
}
}
use of org.mybatis.generator.config.Configuration in project generator by mybatis.
the class JavaCodeGenerationTest method generateJavaFiles.
private static List<GeneratedJavaFile> generateJavaFiles(String configFile) throws Exception {
List<String> warnings = new ArrayList<String>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(JavaCodeGenerationTest.class.getResourceAsStream(configFile));
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
return myBatisGenerator.getGeneratedJavaFiles();
}
use of org.mybatis.generator.config.Configuration in project generator by mybatis.
the class MyBatisGeneratorTest method testGenerateMyBatis3WithInvalidConfig.
@Test(expected = InvalidConfigurationException.class)
public void testGenerateMyBatis3WithInvalidConfig() throws Exception {
List<String> warnings = new ArrayList<String>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigMyBatis3_badConfig.xml"));
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
} catch (InvalidConfigurationException e) {
assertEquals(2, e.getErrors().size());
throw e;
}
}
Aggregations