public static void main(String[] args) {
   try {
     List<String> warnings = new ArrayList<String>();
     boolean overwrite = true;
     File configFile = new File(ClassLoader.getSystemResource(runXMLAUTHORITY).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);
     for (String warning : warnings) {
       System.out.println("Warning:" + warning);
     }
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (XMLParserException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (InvalidConfigurationException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
 public static void run() {
   MybatisOperation.instance().createTable();
   List<String> warnings = new ArrayList<String>();
   boolean overwrite = true;
   String genCfg = "/generator.xml"; // src的一级目录下
   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();
   }
 }
Exemple #3
0
  public static void main(String... args) {
    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    String genCfg = "mybatis-generator-config.xml";

    String projectPath = args[0];

    File configFile = new File(projectPath + genCfg);
    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();
    }
  }
Exemple #4
0
 public void run(String configfile) {
   List<String> warnings = new ArrayList<String>();
   boolean overwrite = true;
   String path = this.getClass().getResource("").getPath();
   File configFile = new File(path + configfile);
   ConfigurationParser cp = new ConfigurationParser(warnings);
   Configuration config = null;
   try {
     config = cp.parseConfiguration(configFile);
   } catch (IOException e) {
     e.printStackTrace(); // To change body of catch statement use File | Settings | File
     // Templates.
   } catch (XMLParserException e) {
     e.printStackTrace(); // To change body of catch statement use File | Settings | File
     // Templates.
   }
   DefaultShellCallback callback = new DefaultShellCallback(overwrite);
   MyBatisGenerator myBatisGenerator = null;
   try {
     myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
   } catch (Exception e) {
     e.printStackTrace(); // To change body of catch statement use File | Settings | File
     // Templates.
   }
   try {
     myBatisGenerator.generate(null);
   } catch (Exception e) {
     e.printStackTrace(); // To change body of catch statement use File | Settings | File
     // Templates.
   }
 }
Exemple #5
0
 public static void main(String[] args) 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);
 }
 public static void main(String[] args)
     throws IOException, XMLParserException, InvalidConfigurationException, SQLException,
         InterruptedException {
   List<String> warnings = new ArrayList<String>();
   boolean overwrite = true;
   File configFile =
       new File(ClassLoader.getSystemClassLoader().getResource("generatorConfig.xml").getFile());
   ConfigurationParser cp = new ConfigurationParser(warnings);
   System.out.println(configFile.getPath());
   Configuration config = cp.parseConfiguration(configFile);
   DefaultShellCallback callback = new DefaultShellCallback(overwrite);
   MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
   myBatisGenerator.generate(null);
 }
  /*
   * (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();
    }
  }