Search in sources :

Example 11 with ConfigurationParser

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

the class GeneratorSqlmap method generator.

public void generator() throws Exception {
    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    // 指向逆向工程配置文件
    String genCfg = "/generatorConfig.xml";
    File configFile = new File(GeneratorSqlmap.class.getResource(genCfg).getFile());
    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 12 with ConfigurationParser

use of org.mybatis.generator.config.xml.ConfigurationParser 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);
}
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) Generator(com.sun.tools.corba.se.idl.Generator) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 13 with ConfigurationParser

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

the class RunGeneratorThread method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.core.resources.IWorkspaceRunnable#run(org.eclipse.core.runtime.IProgressMonitor)
     */
public void run(IProgressMonitor monitor) throws CoreException {
    SubMonitor subMonitor = SubMonitor.convert(monitor, 1000);
    subMonitor.beginTask("Generating MyBatis/iBATIS Artifacts:", 1000);
    setClassLoader();
    try {
        subMonitor.subTask("Parsing Configuration");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(inputFile.getLocation().toFile());
        subMonitor.worked(50);
        MyBatisGenerator mybatisGenerator = new MyBatisGenerator(config, new EclipseShellCallback(), warnings);
        monitor.subTask("Generating Files from Database Tables");
        SubMonitor spm = subMonitor.newChild(950);
        mybatisGenerator.generate(new EclipseProgressCallback(spm));
    } catch (InterruptedException e) {
        throw new OperationCanceledException();
    } catch (SQLException e) {
        Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        Activator.getDefault().getLog().log(status);
        throw new CoreException(status);
    } catch (IOException e) {
        Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
        Activator.getDefault().getLog().log(status);
        throw new CoreException(status);
    } catch (XMLParserException e) {
        List<String> errors = e.getErrors();
        MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "XML Parser Errors\n  See Details for more Information", null);
        Iterator<String> iter = errors.iterator();
        while (iter.hasNext()) {
            Status message = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, iter.next(), null);
            multiStatus.add(message);
        }
        throw new CoreException(multiStatus);
    } catch (InvalidConfigurationException e) {
        List<String> errors = e.getErrors();
        MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "Invalid Configuration\n  See Details for more Information", null);
        Iterator<String> iter = errors.iterator();
        while (iter.hasNext()) {
            Status message = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, iter.next(), null);
            multiStatus.add(message);
        }
        throw new CoreException(multiStatus);
    } finally {
        monitor.done();
        restoreClassLoader();
    }
}
Also used : EclipseShellCallback(org.mybatis.generator.eclipse.core.callback.EclipseShellCallback) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Configuration(org.mybatis.generator.config.Configuration) SQLException(java.sql.SQLException) XMLParserException(org.mybatis.generator.exception.XMLParserException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus) IOException(java.io.IOException) InvalidConfigurationException(org.mybatis.generator.exception.InvalidConfigurationException) EclipseProgressCallback(org.mybatis.generator.eclipse.core.callback.EclipseProgressCallback) CoreException(org.eclipse.core.runtime.CoreException) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) MyBatisGenerator(org.mybatis.generator.api.MyBatisGenerator)

Example 14 with ConfigurationParser

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

use of org.mybatis.generator.config.xml.ConfigurationParser in project cloud-sea-towerman by huadahuang1983.

the class Generator method main.

public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    List<String> warnings = new ArrayList<String>();
    File configFile = new File("generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(configFile);
    MergeShellCallback callback = new MergeShellCallback();
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    myBatisGenerator.generate(null);
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
Also used : Configuration(org.mybatis.generator.config.Configuration) ArrayList(java.util.ArrayList) ConfigurationParser(org.mybatis.generator.config.xml.ConfigurationParser) File(java.io.File) 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