Search in sources :

Example 1 with ConfigurationParser

use of org.mybatis.generator.config.xml.ConfigurationParser in project generator by mybatis.

the class MyBatisGeneratorTest method testGenerateIbatis2WithInvalidConfig.

@Test(expected = InvalidConfigurationException.class)
public void testGenerateIbatis2WithInvalidConfig() throws Exception {
    List<String> warnings = new ArrayList<String>();
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigIbatis2_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(1, e.getErrors().size());
        throw e;
    }
}
Also used : Configuration(org.mybatis.generator.config.Configuration) ConnectionFactoryConfiguration(org.mybatis.generator.config.ConnectionFactoryConfiguration) JDBCConnectionConfiguration(org.mybatis.generator.config.JDBCConnectionConfiguration) ArrayList(java.util.ArrayList) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) DefaultShellCallback(org.mybatis.generator.internal.DefaultShellCallback) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) Test(org.junit.Test)

Example 2 with ConfigurationParser

use of org.mybatis.generator.config.xml.ConfigurationParser in project MyProject by fuyuanshun.

the class GeneratorSqlmap method generator.

public void generator() throws Exception {
    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    // 指定 逆向工程配置文件
    File configFile = new File("generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(configFile);
    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    myBatisGenerator.generate(null);
}
Also used : Configuration(org.mybatis.generator.config.Configuration) ArrayList(java.util.ArrayList) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) DefaultShellCallback(org.mybatis.generator.internal.DefaultShellCallback) File(java.io.File) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 3 with ConfigurationParser

use of org.mybatis.generator.config.xml.ConfigurationParser in project jeesuite-libs by vakinge.

the class MyBatisGeneratorTool method main.

public static void main(String[] args) {
    List<String> warnings = new ArrayList<String>();
    String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
    boolean overwrite = true;
    File configFile = new File(path + "/../../src/test/resources/generator/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = null;
    try {
        config = cp.parseConfiguration(configFile);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XMLParserException e) {
        e.printStackTrace();
    }
    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    MyBatisGenerator myBatisGenerator = null;
    try {
        myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    } catch (InvalidConfigurationException e) {
        e.printStackTrace();
    }
    try {
        myBatisGenerator.generate(null);
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Configuration(org.mybatis.generator.config.Configuration) XMLParserException(org.mybatis.generator.exception.XMLParserException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DefaultShellCallback(org.mybatis.generator.internal.DefaultShellCallback) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) File(java.io.File) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 4 with ConfigurationParser

use of org.mybatis.generator.config.xml.ConfigurationParser in project spring-boot-api-seed-project by selfassu.

the class CodeGenerator method generator.

private void generator() throws Exception {
    List<String> warnings = new ArrayList<String>();
    System.out.println("====开始读取配置文件======");
    File configFile = new File(CONFIG_PATH);
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(configFile);
    DefaultShellCallback callback = new DefaultShellCallback(true);
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    myBatisGenerator.generate(null);
}
Also used : ArrayList(java.util.ArrayList) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) DefaultShellCallback(org.mybatis.generator.internal.DefaultShellCallback) File(java.io.File) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 5 with ConfigurationParser

use of org.mybatis.generator.config.xml.ConfigurationParser in project dubidubi by lzzzz4.

the class Start method generator.

public void generator() throws Exception {
    List<String> warnings = new ArrayList<>();
    boolean overwrite = true;
    // 指定 逆向工程配置文件
    // File configFile = new File("generatorConfig.xml");
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(inputStream);
    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    myBatisGenerator.generate(null);
}
Also used : Configuration(org.mybatis.generator.config.Configuration) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) DefaultShellCallback(org.mybatis.generator.internal.DefaultShellCallback) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Aggregations

ConfigurationParser (org.mybatis.generator.config.xml.ConfigurationParser)23 ArrayList (java.util.ArrayList)22 MyBatisGenerator (org.mybatis.generator.api.MyBatisGenerator)22 Configuration (org.mybatis.generator.config.Configuration)22 DefaultShellCallback (org.mybatis.generator.internal.DefaultShellCallback)19 File (java.io.File)13 InvalidConfigurationException (org.mybatis.generator.exception.InvalidConfigurationException)9 IOException (java.io.IOException)7 SQLException (java.sql.SQLException)7 XMLParserException (org.mybatis.generator.exception.XMLParserException)7 HashSet (java.util.HashSet)3 StringTokenizer (java.util.StringTokenizer)3 Properties (java.util.Properties)2 BuildException (org.apache.tools.ant.BuildException)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 Test (org.junit.Test)2 ConnectionFactoryConfiguration (org.mybatis.generator.config.ConnectionFactoryConfiguration)2 JDBCConnectionConfiguration (org.mybatis.generator.config.JDBCConnectionConfiguration)2 EclipseProgressCallback (org.mybatis.generator.eclipse.core.callback.EclipseProgressCallback)2 EclipseShellCallback (org.mybatis.generator.eclipse.core.callback.EclipseShellCallback)2