org.mybatis.generator.exception.InvalidConfigurationException Java Examples
The following examples show how to use
org.mybatis.generator.exception.InvalidConfigurationException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Configuration.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
/** * This method does a simple validate, it makes sure that all required * fields have been filled in and that all implementation classes exist and * are of the proper type. It does not do any more complex operations such * as: validating that database tables exist or validating that named * columns exist */ public void validate() throws InvalidConfigurationException { List<String> errors = new ArrayList<String>(); for (String classPathEntry : classPathEntries) { if (!stringHasValue(classPathEntry)) { errors.add(getString("ValidationError.19")); //$NON-NLS-1$ // only need to state this error once break; } } if (contexts.size() == 0) { errors.add(getString("ValidationError.11")); //$NON-NLS-1$ } else { for (Context context : contexts) { context.validate(errors); } } if (errors.size() > 0) { throw new InvalidConfigurationException(errors); } }
Example #2
Source File: Configuration.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
/** * This method does a simple validate, it makes sure that all required fields have been filled in and that all * implementation classes exist and are of the proper type. It does not do any more complex operations such as: * validating that database tables exist or validating that named columns exist * * @throws InvalidConfigurationException * the invalid configuration exception */ public void validate() throws InvalidConfigurationException { List<String> errors = new ArrayList<>(); for (String classPathEntry : classPathEntries) { if (!stringHasValue(classPathEntry)) { errors.add(getString("ValidationError.19")); // only need to state this error once break; } } if (contexts.isEmpty()) { errors.add(getString("ValidationError.11")); } else { for (Context context : contexts) { context.validate(errors); } } if (!errors.isEmpty()) { throw new InvalidConfigurationException(errors); } }
Example #3
Source File: MapperGeneratorStrategyBase.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
/** * 调用 mybatis-generator * * @param document xml */ protected void generateMyBatis3(Document document, GeneratorConfig generatorConfig) { List<String> warnings = new ArrayList<>(); ConfigurationParser cp = new ConfigurationParser(warnings); try { Configuration config = cp.parseConfiguration(document); MyShellCallback shellCallback = new MyShellCallback(true, generatorConfig.isUseMerge()); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings); myBatisGenerator.generate(null, null, null); } catch (InvalidConfigurationException | XMLParserException | InterruptedException | IOException | SQLException e) { log.error("生成mapper error", e); throw new BizException("导出失败"); } if (!warnings.isEmpty()) { warnings.forEach(log::warn); } }
Example #4
Source File: MyBatisGeneratorTest.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
@Test(expected=InvalidConfigurationException.class) public void testGenerateIbatis2() throws Exception { List<String> warnings = new ArrayList<String>(); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigIbatis2.xml")); DefaultShellCallback shellCallback = new DefaultShellCallback(true); try { MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings); myBatisGenerator.generate(null); } catch (InvalidConfigurationException e) { assertEquals(1, e.getErrors().size()); throw e; } }
Example #5
Source File: MyBatisGeneratorTest.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
@Test(expected=InvalidConfigurationException.class) public void testGenerateMyBatis3() throws Exception { List<String> warnings = new ArrayList<String>(); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigMyBatis3.xml")); DefaultShellCallback shellCallback = new DefaultShellCallback(true); try { MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings); myBatisGenerator.generate(null); } catch (InvalidConfigurationException e) { assertEquals(2, e.getErrors().size()); throw e; } }
Example #6
Source File: Configuration.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
/** * This method does a simple validate, it makes sure that all required fields have been filled in and that all * implementation classes exist and are of the proper type. It does not do any more complex operations such as: * validating that database tables exist or validating that named columns exist * * @throws InvalidConfigurationException * the invalid configuration exception */ public void validate() throws InvalidConfigurationException { List<String> errors = new ArrayList<String>(); for (String classPathEntry : classPathEntries) { if (!stringHasValue(classPathEntry)) { errors.add(getString("ValidationError.19")); //$NON-NLS-1$ // only need to state this error once break; } } if (contexts.size() == 0) { errors.add(getString("ValidationError.11")); //$NON-NLS-1$ } else { for (Context context : contexts) { context.validate(errors); } } if (errors.size() > 0) { throw new InvalidConfigurationException(errors); } }
Example #7
Source File: Generator.java From mybatis-action with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException { List<String> warnings = new ArrayList<String>(); boolean overwrite = true; InputStream is = Generator.class.getResourceAsStream("/generator/generatorConfig.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration configuration = cp.parseConfiguration(is); is.close(); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(configuration, callback, warnings); myBatisGenerator.generate(null); for (String warning : warnings) { System.out.println(warning); } }
Example #8
Source File: TableRenamePluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 测试提示信息 */ @Test public void testWarnings() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { // searchString、replaceString 单独配置 MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenamePlugin/mybatis-generator-with-wrong-properties.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(0), "itfsw:插件com.itfsw.mybatis.generator.plugins.TableRenamePlugin插件的searchString、replaceString属性需配合使用,不能单独存在!"); // 和官方domainObjectName或者mapperName一起配置 tool = MyBatisGeneratorTool.create("scripts/TableRenamePlugin/mybatis-generator-with-domainObject.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(0), "itfsw:插件com.itfsw.mybatis.generator.plugins.TableRenamePlugin插件请不要配合table的domainObjectName或者mapperName一起使用!"); }
Example #9
Source File: MyBatisGenerator.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
/** * Constructs a MyBatisGenerator object. * * @param configuration * The configuration for this invocation * @param shellCallback * an instance of a ShellCallback interface. You may specify * <code>null</code> in which case the DefaultShellCallback will * be used. * @param warnings * Any warnings generated during execution will be added to this * list. Warnings do not affect the running of the tool, but they * may affect the results. A typical warning is an unsupported * data type. In that case, the column will be ignored and * generation will continue. You may specify <code>null</code> if * you do not want warnings returned. * @throws InvalidConfigurationException * if the specified configuration is invalid */ public MyBatisGenerator(Configuration configuration, ShellCallback shellCallback, List<String> warnings) throws InvalidConfigurationException { super(); if (configuration == null) { throw new IllegalArgumentException(getString("RuntimeError.2")); //$NON-NLS-1$ } else { this.configuration = configuration; } if (shellCallback == null) { this.shellCallback = new DefaultShellCallback(false); } else { this.shellCallback = shellCallback; } if (warnings == null) { this.warnings = new ArrayList<String>(); } else { this.warnings = warnings; } generatedJavaFiles = new ArrayList<GeneratedJavaFile>(); generatedXmlFiles = new ArrayList<GeneratedXmlFile>(); projects = new HashSet<String>(); this.configuration.validate(); }
Example #10
Source File: MybatisGenerator.java From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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( "D:\\01_workspace\\Project\\zp\\java\\spring-tutorial\\codes\\data\\orm\\src\\main\\resources\\mybatis\\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); }
Example #11
Source File: MyBatisGenerator.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
/** * Constructs a MyBatisGenerator object. * * @param configuration * The configuration for this invocation * @param shellCallback * an instance of a ShellCallback interface. You may specify * <code>null</code> in which case the DefaultShellCallback will * be used. * @param warnings * Any warnings generated during execution will be added to this * list. Warnings do not affect the running of the tool, but they * may affect the results. A typical warning is an unsupported * data type. In that case, the column will be ignored and * generation will continue. You may specify <code>null</code> if * you do not want warnings returned. * @throws InvalidConfigurationException * if the specified configuration is invalid */ public MyBatisGenerator(Configuration configuration, ShellCallback shellCallback, List<String> warnings) throws InvalidConfigurationException { super(); if (configuration == null) { throw new IllegalArgumentException(getString("RuntimeError.2")); //$NON-NLS-1$ } else { this.configuration = configuration; } if (shellCallback == null) { this.shellCallback = new DefaultShellCallback(false); } else { this.shellCallback = shellCallback; } if (warnings == null) { this.warnings = new ArrayList<String>(); } else { this.warnings = warnings; } generatedJavaFiles = new ArrayList<GeneratedJavaFile>(); generatedXmlFiles = new ArrayList<GeneratedXmlFile>(); projects = new HashSet<String>(); this.configuration.validate(); }
Example #12
Source File: GeneratorMain.java From spring-boot-starter-dao with Apache License 2.0 | 5 votes |
private void generate(Properties properties)throws IOException, XMLParserException, SQLException, InterruptedException, InvalidConfigurationException { ClassPathResource resource = new ClassPathResource("META-INF/generator/generatorconfig.xml"); List<String> warnings = new ArrayList<String>(); ConfigurationParser cp = new ConfigurationParser(properties, warnings); Configuration config = cp.parseConfiguration(resource.getInputStream()); System.err.println("#############################################################################################"); System.err.println("######################################开始生成##################################################"); System.err.println("#############################################################################################"); new MyBatisGenerator(config, new DefaultShellCallback(true), warnings).generate(new VerboseProgressCallback()); System.err.println("#############################################################################################"); System.err.println("#######################################生成完毕#################################################"); System.err.println("#############################################################################################"); }
Example #13
Source File: UpsertPluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 测试配置异常 */ @Test public void testWarnings() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { // 1. 没有使用mysql数据库 MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator-with-error-driver.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(1), "itfsw:插件com.itfsw.mybatis.generator.plugins.UpsertPlugin插件使用前提是数据库为MySQL!"); // 2. 普通提示 tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(0), "itfsw:插件com.itfsw.mybatis.generator.plugins.UpsertPlugin插件您开启了allowMultiQueries支持,注意在jdbc url 配置中增加“allowMultiQueries=true”支持(不怎么建议使用该功能,开启多sql提交会增加sql注入的风险,请确保你所有sql都使用MyBatis书写,请不要使用statement进行sql提交)!"); }
Example #14
Source File: LimitPluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 测试配置异常 */ @Test public void testWarnings() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LimitPlugin/mybatis-generator-with-error-driver.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(1), "itfsw:插件com.itfsw.mybatis.generator.plugins.LimitPlugin只支持MySQL数据库!"); }
Example #15
Source File: TableRenamePluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 测试替代 TablePrefixPlugin 插件 */ @Test public void testGenerateLikeTablePrefixPlugin() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenamePlugin/mybatis-generator-like-TablePrefixPlugin.xml"); MyBatisGenerator myBatisGenerator = tool.generate(); for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){ String name = file.getCompilationUnit().getType().getShortName(); Assert.assertTrue(name.matches("DB1.*")); } }
Example #16
Source File: TableRenamePluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 测试具体生成 */ @Test public void testGenerate() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { // 规则1 ^T 替换成 Test, 同时tb2 使用了tableOverride 替换成 TestOverride MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenamePlugin/mybatis-generator-rule1.xml"); MyBatisGenerator myBatisGenerator = tool.generate(); for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){ String name = file.getCompilationUnit().getType().getShortName(); if (name.matches(".*1.*")){ Assert.assertTrue(name.matches("Testb1.*")); } else { Assert.assertTrue(name.matches("TestOverride.*")); } } }
Example #17
Source File: SelectiveEnhancedPluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 测试配置异常 */ @Test public void testWarnings() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { // 1. 没有配置ModelColumnPlugin插件 MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator-without-ModelColumnPlugin.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(0), "itfsw:插件com.itfsw.mybatis.generator.plugins.SelectiveEnhancedPlugin插件需配合com.itfsw.mybatis.generator.plugins.ModelColumnPlugin插件使用!"); }
Example #18
Source File: ExampleTargetPluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 测试异常配置 */ @Test public void testWarnings() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleTargetPlugin/mybatis-generator-without-target.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(0), "请配置com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin插件的目标包名(targetPackage)!"); }
Example #19
Source File: LogicalDeletePluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 测试配置异常 */ @Test public void testWarnings() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { // 1. 不支持的类型 MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-unsupport-type.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(0), "itfsw(逻辑删除插件):tb逻辑删除列(ts_2)的类型不在支持范围(请使用数字列,字符串列,布尔列)!"); // 2. 没有找到配置的逻辑删除列 tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-unfind-column.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(0), "itfsw(逻辑删除插件):tb没有找到您配置的逻辑删除列(ts_999)!"); // 3. 没有配置逻辑删除值 tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-unconfig-logicalDeleteValue.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(0), "itfsw(逻辑删除插件):tb没有找到您配置的逻辑删除值,请全局或者局部配置logicalDeleteValue和logicalUnDeleteValue值!"); // 4. 保留关键词冲突 tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-keywords.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(0), "itfsw(逻辑删除插件):tb配置的逻辑删除列和插件保留关键字(andLogicalDeleted)冲突!"); }
Example #20
Source File: TablePrefixPluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 测试具体生成 */ @Test public void testGenerate() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { // 全局规则增加 DB, tb2 单独规则增加Tt MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TablePrefixPlugin/mybatis-generator.xml"); MyBatisGenerator myBatisGenerator = tool.generate(); for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){ String name = file.getCompilationUnit().getType().getShortName(); if (name.matches(".*1.*")){ Assert.assertTrue(name.matches("DB.*")); } else { Assert.assertTrue(name.matches("Tt.*")); } } }
Example #21
Source File: TablePrefixPluginTest.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 测试提示信息 */ @Test public void testWarnings() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { // 和官方domainObjectName或者mapperName一起配置 MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TablePrefixPlugin/mybatis-generator-with-domainObject.xml"); tool.generate(); Assert.assertEquals(tool.getWarnings().get(0), "itfsw:插件com.itfsw.mybatis.generator.plugins.TablePrefixPlugin插件请不要配合table的domainObjectName或者mapperName一起使用!"); }
Example #22
Source File: GeneratorTest.java From ManagementSystem with Apache License 2.0 | 5 votes |
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("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); }
Example #23
Source File: MybatisGenerator.java From ssm with Apache License 2.0 | 5 votes |
private static void generator() throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException { List<String> warnings = new ArrayList<String>(); boolean overwrite = true; File configFile = new File(MybatisGenerator.class.getClass().getResource("/").getPath()+ "config/generator-config.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); }
Example #24
Source File: MyBatisGenerator.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
/** * Constructs a MyBatisGenerator object. * * @param configuration The configuration for this invocation * @param shellCallback an instance of a ShellCallback interface. You may specify * <code>null</code> in which case the DefaultShellCallback will * be used. * @param warnings Any warnings generated during execution will be added to this * list. Warnings do not affect the running of the tool, but they * may affect the results. A typical warning is an unsupported * data type. In that case, the column will be ignored and * generation will continue. You may specify <code>null</code> if * you do not want warnings returned. * @throws InvalidConfigurationException if the specified configuration is invalid */ public MyBatisGenerator(Configuration configuration, ShellCallback shellCallback, List<String> warnings) throws InvalidConfigurationException { super(); if (configuration == null) { throw new IllegalArgumentException(getString("RuntimeError.2")); } else { this.configuration = configuration; } if (shellCallback == null) { this.shellCallback = new DefaultShellCallback(false); } else { this.shellCallback = shellCallback; } if (warnings == null) { this.warnings = new ArrayList<>(); } else { this.warnings = warnings; } generatedJavaFiles = new ArrayList<>(); generatedXmlFiles = new ArrayList<>(); projects = new HashSet<>(); this.configuration.validate(); }
Example #25
Source File: Generator.java From seata-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException { List<String> warnings = new ArrayList<String>(); boolean overwrite = true; InputStream inputStream = Generator.class.getClassLoader().getResourceAsStream("config/generatorConfig.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(inputStream); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate(new NullProgressCallback()); }
Example #26
Source File: Generator.java From seata-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException { List<String> warnings = new ArrayList<String>(); boolean overwrite = true; InputStream inputStream = Generator.class.getClassLoader().getResourceAsStream("config/generatorConfig.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(inputStream); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate(new NullProgressCallback()); }
Example #27
Source File: MapperGenerator.java From sc-generator with Apache License 2.0 | 4 votes |
public MapperGenerator(Configuration configuration, ShellCallback shellCallback, List<String> warnings) throws InvalidConfigurationException { super(configuration, shellCallback, warnings); }
Example #28
Source File: GenService.java From MybatisGenerator-UI with MIT License | 4 votes |
public String genCode(HttpServletRequest request) { String ip = request.getParameter("ip"); String db = request.getParameter("db"); String port = request.getParameter("port"); String userName = request.getParameter("username"); String password = request.getParameter("password"); String modelPackageName = request.getParameter("modelpackagename"); String daoPackageName = request.getParameter("daopackagename"); String mapperPath = request.getParameter("mapperpath"); String tableNames[] = request.getParameterValues("tablenames"); String tableModels[] = request.getParameterValues("tablemodels"); String path = "mbg"; // 清空临时文件夹下所有内容 deleteDir(new File(System.getProperty("user.dir") + "/mbg")); try { List<String> warnings = new ArrayList<>(); boolean overwrite = true; File dirFile = new File(path); if (!dirFile.exists()) { dirFile.mkdirs(); } File conf = new File(System.getProperty("user.dir") + "/conf/Configuration.xml"); ConfigurationParser parser = new ConfigurationParser(warnings); Configuration config = parser.parseConfiguration(conf); Context context = config.getContexts().get(0); // db JDBCConnectionConfiguration jdbcConnectionConfiguration = context.getJdbcConnectionConfiguration(); String connection = "jdbc:mysql://" + ip + ":" + port + "/" + db; jdbcConnectionConfiguration.setConnectionURL(connection); jdbcConnectionConfiguration.setUserId(userName); jdbcConnectionConfiguration.setPassword(password); // model 配置 JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = context.getJavaModelGeneratorConfiguration(); javaModelGeneratorConfiguration.setTargetPackage(modelPackageName); javaModelGeneratorConfiguration.setTargetProject(path); // DAO 配置 JavaClientGeneratorConfiguration javaClientGeneratorConfiguration = context.getJavaClientGeneratorConfiguration(); javaClientGeneratorConfiguration.setTargetPackage(daoPackageName); javaClientGeneratorConfiguration.setTargetProject(path); // Mapper SqlMapGeneratorConfiguration sqlMapGeneratorConfiguration = context.getSqlMapGeneratorConfiguration(); sqlMapGeneratorConfiguration.setTargetPackage(mapperPath); sqlMapGeneratorConfiguration.setTargetProject(path); // 表 List<TableConfiguration> tableConfigurations = context.getTableConfigurations(); tableConfigurations.clear(); for (int i = 0; i < tableNames.length; i++) { if (!tableNames[i].isEmpty() && !tableModels[i].isEmpty()) { TableConfiguration tableConfiguration = new TableConfiguration(context); tableConfiguration.setTableName(tableNames[i]); tableConfiguration.setDomainObjectName(tableModels[i]); tableConfiguration.setCountByExampleStatementEnabled(false); tableConfiguration.setDeleteByExampleStatementEnabled(false); tableConfiguration.setSelectByExampleStatementEnabled(false); tableConfiguration.setUpdateByExampleStatementEnabled(false); tableConfiguration.getProperties().setProperty("useActualColumnNames", "false"); tableConfigurations.add(tableConfiguration); } } DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate(null); FileUtil.compress("mbg", System.getProperty("user.dir") + "/result/", "mbg.zip"); } catch (SQLException e) { e.printStackTrace(); return "01"; } catch (IOException ioe) { ioe.printStackTrace(); return "02"; } catch (InterruptedException ite) { ite.printStackTrace(); return "03"; } catch (InvalidConfigurationException ice) { ice.printStackTrace(); return "04"; } catch (XMLParserException xmle) { xmle.printStackTrace(); return "05"; } return "00"; }
Example #29
Source File: Dashboard.java From mybatis-generator-gui with MIT License | 4 votes |
/** * 生成XML */ private void generate() { src = txtSrc.getText().trim(); modelPkg = txtModelPkg.getText().trim(); mapPkg = txtMapPkg.getText().trim(); daoPkg = txtDaoPkg.getText().trim(); overwrite = checkBoxOverwrite.isSelected(); entitySuffix = txtEntity.getText().trim(); if (src.equals("请选择生成的src根目录") || modelPkg.isEmpty() || mapPkg.isEmpty() || daoPkg.isEmpty()) { JOptionPane.showMessageDialog(frame, "请将信息填写完整"); return; } labelStatus.setText("生成中"); btnGenerate.setEnabled(false); btnRefreshTable.setEnabled(false); try { GenerateWorker worker = new GenerateWorker(src, modelPkg, mapPkg, daoPkg, tables, labelStatus, overwrite, dbUtil); worker.setListener(new GenerateWorker.OnGenerateCompleteListener() { @Override public void onSuccess(String msg) { labelStatus.setText(msg); btnGenerate.setEnabled(true); btnRefreshTable.setEnabled(true); JOptionPane.showMessageDialog(null, "生成成功!"); } @Override public void onError(String message, Throwable ex) { labelStatus.setText(message); btnGenerate.setEnabled(true); btnRefreshTable.setEnabled(true); logger.error(message, ex); } }); worker.execute(); } catch (InterruptedException | InvalidConfigurationException | SQLException | IOException e) { logger.error(e); labelStatus.setText(e.getMessage()); btnGenerate.setEnabled(true); btnRefreshTable.setEnabled(true); } }
Example #30
Source File: MyBatisGeneratorTool.java From mybatis-generator-plugin with Apache License 2.0 | 2 votes |
/** * 执行MyBatisGenerator(不生成文件) * @return * @throws SQLException * @throws IOException * @throws InterruptedException */ public MyBatisGenerator generate() throws InvalidConfigurationException, InterruptedException, SQLException, IOException { MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, new DefaultShellCallback(true), warnings); myBatisGenerator.generate(null, null, null, false); return myBatisGenerator; }