Ejemplo n.º 1
0
 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();
   }
 }
Ejemplo n.º 2
0
 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();
   }
 }
Ejemplo n.º 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();
    }
  }
  /*
   * (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();
    }
  }