Search in sources :

Example 16 with DefaultShellCallback

use of org.mybatis.generator.internal.DefaultShellCallback in project PublicCMS-preview by sanluan.

the class MybatisGenerator method main.

/**
 * @param arg
 * @throws Throwable
 */
public static void main(String[] arg) throws Throwable {
    List<String> warnings = new ArrayList<>();
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(MybatisGenerator.class.getResourceAsStream("/generator/mybatis/generatorConfig.xml"));
    DefaultShellCallback shellCallback = new DefaultShellCallback(true);
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, 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) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 17 with DefaultShellCallback

use of org.mybatis.generator.internal.DefaultShellCallback in project jeesuite-libs by vakinge.

the class MyBatisGeneratorTool method main.

public static void main(String[] args) {
    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    // src的一级目录下
    String genCfg = "/generatorConfig.xml";
    File configFile = new File(MyBatisGeneratorTool.class.getResource(genCfg).getFile());
    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 18 with DefaultShellCallback

use of org.mybatis.generator.internal.DefaultShellCallback in project Resource by lovelifeming.

the class MBGTest method main.

public static void main(String[] args) throws Exception {
    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    // 配置MyBatis generator配置文件
    File configFile = new File("src/main/resources/MyBatisGenerator.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 19 with DefaultShellCallback

use of org.mybatis.generator.internal.DefaultShellCallback in project generator by mybatis.

the class GeneratorAntTask method execute.

@Override
public void execute() {
    File configurationFile = calculateConfigurationFile();
    Set<String> fullyqualifiedTables = calculateTables();
    Set<String> contexts = calculateContexts();
    List<String> warnings = new ArrayList<>();
    try {
        Properties p = propertyset == null ? null : propertyset.getProperties();
        ConfigurationParser cp = new ConfigurationParser(p, warnings);
        Configuration config = cp.parseConfiguration(configurationFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(new AntProgressCallback(this, verbose), contexts, fullyqualifiedTables);
    } catch (XMLParserException | InvalidConfigurationException e) {
        for (String error : e.getErrors()) {
            log(error, Project.MSG_ERR);
        }
        throw new BuildException(e.getMessage());
    } catch (SQLException | IOException e) {
        throw new BuildException(e.getMessage());
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        log(e, Project.MSG_ERR);
        throw new BuildException(e.getMessage());
    }
    for (String error : warnings) {
        log(error, Project.MSG_WARN);
    }
}
Also used : Configuration(org.mybatis.generator.config.Configuration) XMLParserException(org.mybatis.generator.exception.XMLParserException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) DefaultShellCallback(org.mybatis.generator.internal.DefaultShellCallback) IOException(java.io.IOException) Properties(java.util.Properties) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) SQLException(java.sql.SQLException) XMLParserException(org.mybatis.generator.exception.XMLParserException) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 20 with DefaultShellCallback

use of org.mybatis.generator.internal.DefaultShellCallback in project generator by mybatis.

the class JavaCodeGenerationTest method generateJavaFiles.

static List<GeneratedJavaFile> generateJavaFiles(String configFile) throws Exception {
    List<String> warnings = new ArrayList<>();
    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();
}
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) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

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