Search in sources :

Example 6 with ConfigurationParser

use of org.mybatis.generator.config.xml.ConfigurationParser 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 7 with ConfigurationParser

use of org.mybatis.generator.config.xml.ConfigurationParser 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 8 with ConfigurationParser

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

the class XmlCodeGenerationTest method generateXmlFiles.

static List<GeneratedXmlFile> generateXmlFiles(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.getGeneratedXmlFiles();
}
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 9 with ConfigurationParser

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

the class KotlinCodeGenerationTest method generateKotlinFiles.

static List<GeneratedKotlinFile> generateKotlinFiles(String configFile) throws Exception {
    List<String> warnings = new ArrayList<>();
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(KotlinCodeGenerationTest.class.getResourceAsStream(configFile));
    DefaultShellCallback shellCallback = new DefaultShellCallback(true);
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
    myBatisGenerator.generate(null, null, null, false);
    return myBatisGenerator.getGeneratedKotlinFiles();
}
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 10 with ConfigurationParser

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

the class ShellRunner method main.

public static void main(String[] args) {
    if (args.length == 0) {
        usage();
        System.exit(0);
        // only to satisfy compiler, never returns
        return;
    }
    Map<String, String> arguments = parseCommandLine(args);
    if (arguments.containsKey(HELP_1)) {
        usage();
        System.exit(0);
        // only to satisfy compiler, never returns
        return;
    }
    if (!arguments.containsKey(CONFIG_FILE)) {
        // $NON-NLS-1$
        writeLine(getString("RuntimeError.0"));
        return;
    }
    List<String> warnings = new ArrayList<>();
    String configfile = arguments.get(CONFIG_FILE);
    File configurationFile = new File(configfile);
    if (!configurationFile.exists()) {
        // $NON-NLS-1$
        writeLine(getString("RuntimeError.1", configfile));
        return;
    }
    Set<String> fullyqualifiedTables = new HashSet<>();
    if (arguments.containsKey(TABLES)) {
        // $NON-NLS-1$
        StringTokenizer st = new StringTokenizer(arguments.get(TABLES), ",");
        while (st.hasMoreTokens()) {
            String s = st.nextToken().trim();
            if (s.length() > 0) {
                fullyqualifiedTables.add(s);
            }
        }
    }
    Set<String> contexts = new HashSet<>();
    if (arguments.containsKey(CONTEXT_IDS)) {
        StringTokenizer st = new StringTokenizer(arguments.get(CONTEXT_IDS), // $NON-NLS-1$
        ",");
        while (st.hasMoreTokens()) {
            String s = st.nextToken().trim();
            if (s.length() > 0) {
                contexts.add(s);
            }
        }
    }
    try {
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configurationFile);
        DefaultShellCallback shellCallback = new DefaultShellCallback(arguments.containsKey(OVERWRITE));
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
        ProgressCallback progressCallback = arguments.containsKey(VERBOSE) ? new VerboseProgressCallback() : null;
        myBatisGenerator.generate(progressCallback, contexts, fullyqualifiedTables);
    } catch (XMLParserException e) {
        // $NON-NLS-1$
        writeLine(getString("Progress.3"));
        writeLine();
        for (String error : e.getErrors()) {
            writeLine(error);
        }
        return;
    } catch (SQLException | IOException e) {
        e.printStackTrace(System.out);
        return;
    } catch (InvalidConfigurationException e) {
        // $NON-NLS-1$
        writeLine(getString("Progress.16"));
        for (String error : e.getErrors()) {
            writeLine(error);
        }
        return;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    for (String warning : warnings) {
        writeLine(warning);
    }
    if (warnings.isEmpty()) {
        // $NON-NLS-1$
        writeLine(getString("Progress.4"));
    } else {
        writeLine();
        // $NON-NLS-1$
        writeLine(getString("Progress.5"));
    }
}
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) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) StringTokenizer(java.util.StringTokenizer) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) File(java.io.File) HashSet(java.util.HashSet)

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