Search in sources :

Example 6 with DefaultShellCallback

use of org.mybatis.generator.internal.DefaultShellCallback 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 7 with DefaultShellCallback

use of org.mybatis.generator.internal.DefaultShellCallback 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)

Example 8 with DefaultShellCallback

use of org.mybatis.generator.internal.DefaultShellCallback in project java-code-show by CodeShowZz.

the class UserDaoTest method insertTest.

@Test
public void insertTest() throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
    String fileName = this.getClass().getClassLoader().getResource("generatorConfig.xml").getFile();
    File configFile = new File(fileName);
    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    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) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with DefaultShellCallback

use of org.mybatis.generator.internal.DefaultShellCallback in project tutorials-java by Artister.

the class MybatisGenerator method generateStubs.

protected void generateStubs(String... tableNames) throws Exception {
    if (ArrayUtils.isEmpty(tableNames)) {
        _LOGGER.info("no table name was specified");
        return;
    }
    makeXml(tableNames);
    File configFile = new File(mbgXmlPath);
    List<String> warnings = new ArrayList<>();
    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);
    _LOGGER.info("mybatis generated done !");
}
Also used : Configuration(org.mybatis.generator.config.Configuration) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) DefaultShellCallback(org.mybatis.generator.internal.DefaultShellCallback) File(java.io.File) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 10 with DefaultShellCallback

use of org.mybatis.generator.internal.DefaultShellCallback 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());
}
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) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultShellCallback (org.mybatis.generator.internal.DefaultShellCallback)24 MyBatisGenerator (org.mybatis.generator.api.MyBatisGenerator)23 ArrayList (java.util.ArrayList)21 Configuration (org.mybatis.generator.config.Configuration)20 ConfigurationParser (org.mybatis.generator.config.xml.ConfigurationParser)19 File (java.io.File)12 InvalidConfigurationException (org.mybatis.generator.exception.InvalidConfigurationException)8 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)4 ConnectionFactoryConfiguration (org.mybatis.generator.config.ConnectionFactoryConfiguration)4 JDBCConnectionConfiguration (org.mybatis.generator.config.JDBCConnectionConfiguration)4 XMLParserException (org.mybatis.generator.exception.XMLParserException)4 Test (org.junit.jupiter.api.Test)3 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 Context (org.mybatis.generator.config.Context)2 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)2 Generator (com.sun.tools.corba.se.idl.Generator)1 DbRemarksCommentGenerator (com.zzg.mybatis.generator.plugins.DbRemarksCommentGenerator)1 InputStream (java.io.InputStream)1