├── .gitignore ├── LICENSE ├── README.md ├── pom.xml ├── screw-driver-docs ├── .gitignore ├── README.md ├── dist │ ├── 404.html │ ├── assets │ │ ├── css │ │ │ └── 0.styles.fc5a33c2.css │ │ ├── img │ │ │ └── search.83621669.svg │ │ └── js │ │ │ ├── 10.4df5c369.js │ │ │ ├── 11.6b42f21f.js │ │ │ ├── 12.4410723a.js │ │ │ ├── 13.736ddd64.js │ │ │ ├── 14.02238de3.js │ │ │ ├── 15.49eb6595.js │ │ │ ├── 2.84e40db9.js │ │ │ ├── 3.78213f14.js │ │ │ ├── 4.7d75b37f.js │ │ │ ├── 5.dcb78602.js │ │ │ ├── 6.0a49403f.js │ │ │ ├── 7.85e1e42d.js │ │ │ ├── 8.377f9d6b.js │ │ │ ├── 9.1b20cf40.js │ │ │ └── app.b753bbce.js │ ├── favicon.ico │ ├── index.html │ ├── logo.png │ └── start │ │ ├── core-class-intro.html │ │ ├── expand.html │ │ ├── ide-code-block.html │ │ ├── introduction.html │ │ ├── license.html │ │ ├── sd-type.html │ │ ├── sql-assist.html │ │ ├── template-attr.html │ │ └── template-rule.html ├── docs │ ├── .vuepress │ │ ├── config.js │ │ └── public │ │ │ ├── favicon.ico │ │ │ └── logo.png │ ├── README.md │ └── start │ │ ├── core-class-intro.md │ │ ├── expand.md │ │ ├── ide-code-block.md │ │ ├── introduction.md │ │ ├── license.md │ │ ├── sd-type.md │ │ ├── sql-assist.md │ │ ├── template-attr.md │ │ └── template-rule.md └── package.json └── src ├── main ├── java │ └── org │ │ └── mirrentools │ │ └── sd │ │ ├── ScrewDriver.java │ │ ├── ScrewDriverCode.java │ │ ├── ScrewDriverDbUtil.java │ │ ├── ScrewDriverException.java │ │ ├── ScrewDriverProject.java │ │ ├── ScrewDriverSQL.java │ │ ├── ScrewDriverTemplateEngine.java │ │ ├── SdType.java │ │ ├── common │ │ ├── SdIoUtil.java │ │ ├── SdTemplatePathUtil.java │ │ └── SdUtil.java │ │ ├── constant │ │ ├── DB2.java │ │ ├── Java.java │ │ ├── MySQL.java │ │ ├── Oracle.java │ │ ├── PostgreSQL.java │ │ ├── SQL.java │ │ ├── SQLite.java │ │ ├── SdConstant.java │ │ └── SqlServer.java │ │ ├── converter │ │ ├── SdAbstractClassConverter.java │ │ ├── SdAbstractTableContentConverter.java │ │ ├── SdAbstractTableToClassConverter.java │ │ ├── SdAbstractTypeConverter.java │ │ ├── SdBasicClassConverter.java │ │ ├── SdBasicTableToClassConverter.java │ │ ├── SdBasicTypeConverter.java │ │ ├── SdClassConverter.java │ │ ├── SdDatabaseContentConverter.java │ │ ├── SdTableContentConverter.java │ │ ├── SdTableToClassConverter.java │ │ ├── SdTemplateContentConverter.java │ │ ├── SdTypeConverter.java │ │ └── impl │ │ │ ├── SdTemplateContentConverterDefaultImpl.java │ │ │ ├── db2 │ │ │ ├── SdClassConverterDB2Impl.java │ │ │ ├── SdTableContentConverterDB2Impl.java │ │ │ └── SdTableToClassConverterDB2Impl.java │ │ │ ├── mysql │ │ │ ├── SdClassConverterMySqlImpl.java │ │ │ ├── SdDatabaseConverterMySqlImpl.java │ │ │ ├── SdTableContentConverterMySqlImpl.java │ │ │ └── SdTableToClassConverterMySqlImpl.java │ │ │ ├── oracle │ │ │ ├── SdClassConverterOracleImpl.java │ │ │ ├── SdTableContentConverterOracleImpl.java │ │ │ └── SdTableToClassConverterOracleImpl.java │ │ │ ├── postgresql │ │ │ ├── SdClassConverterPostgreSqlImpl.java │ │ │ ├── SdDatabaseConverterPostgreSqlImpl.java │ │ │ ├── SdTableContentConverterPostgreSqlImpl.java │ │ │ └── SdTableToClassConverterPostgreSqlImpl.java │ │ │ ├── sqlite │ │ │ ├── SdClassConverterSqliteImpl.java │ │ │ ├── SdTableContentConverterSqliteImpl.java │ │ │ └── SdTableToClassConverterSqliteImpl.java │ │ │ └── sqlserver │ │ │ ├── SdClassConverterSqlServerImpl.java │ │ │ ├── SdDatabaseConverterSqlServerImpl.java │ │ │ ├── SdTableContentConverterSqlServerImpl.java │ │ │ └── SdTableToClassConverterSqlServerImpl.java │ │ ├── enums │ │ ├── Relational.java │ │ └── SdTypeMode.java │ │ ├── impl │ │ ├── ScrewDriverCodeImpl.java │ │ ├── ScrewDriverImpl.java │ │ ├── ScrewDriverSqlImpl.java │ │ ├── ScrewDriverTemplateFreeMarkerImpl.java │ │ ├── ScrewDriverTemplateMvelImpl.java │ │ └── dbutil │ │ │ ├── SdAbstractDbUtil.java │ │ │ ├── SdDbUtilDB2Impl.java │ │ │ ├── SdDbUtilMySqlImpl.java │ │ │ ├── SdDbUtilOracleImpl.java │ │ │ ├── SdDbUtilPostgreSqlImpl.java │ │ │ ├── SdDbUtilSqlServerImpl.java │ │ │ └── SdDbUtilSqliteImpl.java │ │ ├── models │ │ ├── SdBean.java │ │ ├── SdClassContent.java │ │ ├── SdColumn.java │ │ ├── SdDatabase.java │ │ ├── SdRelational.java │ │ ├── SdRelationalContent.java │ │ ├── SdRenderContent.java │ │ ├── SdSequence.java │ │ ├── SdTemplate.java │ │ ├── SdTemplateAttribute.java │ │ ├── SdTemplateContent.java │ │ └── db │ │ │ ├── query │ │ │ ├── SdTable.java │ │ │ ├── SdTableAttribute.java │ │ │ ├── SdTableColumnAttribute.java │ │ │ ├── SdTableIndexKeyAttribute.java │ │ │ ├── SdTablePortedKeysAttribute.java │ │ │ └── SdTablePrimaryKeyAttribute.java │ │ │ └── update │ │ │ ├── SdAbstractColumnContent.java │ │ │ ├── SdAbstractConstraintContent.java │ │ │ ├── SdAbstractDatabaseContent.java │ │ │ ├── SdAbstractForeignKeyContent.java │ │ │ ├── SdAbstractIndexKeyContent.java │ │ │ ├── SdAbstractPrimaryKeyContent.java │ │ │ ├── SdAbstractSequenceContent.java │ │ │ ├── SdAbstractTableContent.java │ │ │ ├── SdBasicColumnContent.java │ │ │ ├── SdBasicConstraintContent.java │ │ │ ├── SdBasicForeignKeyContent.java │ │ │ ├── SdBasicIndexKeyContent.java │ │ │ ├── SdBasicPrimaryKeyContent.java │ │ │ ├── SdBasicSequenceContent.java │ │ │ ├── SdBasicTableContent.java │ │ │ └── impl │ │ │ ├── db2 │ │ │ ├── SdColumnContentByDB2.java │ │ │ ├── SdConstraintContentByDB2.java │ │ │ ├── SdDatabaseContentByDB2.java │ │ │ ├── SdForeignKeyContentByDB2.java │ │ │ ├── SdIndexKeyContentByDB2.java │ │ │ ├── SdPrimaryKeyContentByDB2.java │ │ │ ├── SdSequenceContentByDB2.java │ │ │ └── SdTableContentByDB2.java │ │ │ ├── mysql │ │ │ ├── SdColumnContentByMySQL.java │ │ │ ├── SdConstraintContentByMySQL.java │ │ │ ├── SdDatabaseContentByMySQL.java │ │ │ ├── SdForeignKeyContentByMySQL.java │ │ │ ├── SdIndexKeyContentByMySQL.java │ │ │ ├── SdPrimaryKeyContentByMySQL.java │ │ │ └── SdTableContentByMySQL.java │ │ │ ├── oracle │ │ │ ├── SdColumnContentByOracle.java │ │ │ ├── SdConstraintContentByOracle.java │ │ │ ├── SdDatabaseContentByOracle.java │ │ │ ├── SdForeignKeyContentByOracle.java │ │ │ ├── SdIndexKeyContentByOracle.java │ │ │ ├── SdPrimaryKeyContentByOracle.java │ │ │ ├── SdSequenceContentByOracle.java │ │ │ └── SdTableContentByOracle.java │ │ │ ├── postgresql │ │ │ ├── SdColumnContentByPostgreSQL.java │ │ │ ├── SdConstraintContentByPostgreSQL.java │ │ │ ├── SdDatabaseContentByPostgreSql.java │ │ │ ├── SdForeignKeyContentByPostgreSQL.java │ │ │ ├── SdIndexKeyContentByPostgreSQL.java │ │ │ ├── SdPrimaryKeyContentByPostgreSQL.java │ │ │ ├── SdSequenceContentByPostgreSQL.java │ │ │ └── SdTableContentByPostgreSQL.java │ │ │ ├── sqlite │ │ │ ├── SdColumnContentBySqlite.java │ │ │ ├── SdConstraintContentBySqlite.java │ │ │ ├── SdDatabaseContentBySqlite.java │ │ │ ├── SdForeignKeyContentBySqlite.java │ │ │ ├── SdIndexKeyContentBySqlite.java │ │ │ ├── SdPrimaryKeyContentBySqlite.java │ │ │ └── SdTableContentBySqlite.java │ │ │ └── sqlserver │ │ │ ├── SdColumnContentBySqlServer.java │ │ │ ├── SdConstraintContentBySqlServer.java │ │ │ ├── SdDatabaseContentBySqlServer.java │ │ │ ├── SdForeignKeyContentBySqlServer.java │ │ │ ├── SdIndexKeyContentBySqlServer.java │ │ │ ├── SdPrimaryKeyContentBySqlServer.java │ │ │ └── SdTableContentBySqlServer.java │ │ └── options │ │ ├── ScrewDriverOptions.java │ │ ├── SdDatabaseOptions.java │ │ └── def │ │ ├── ScrewDriverDB2Options.java │ │ ├── ScrewDriverMySqlOptions.java │ │ ├── ScrewDriverOracleOptions.java │ │ ├── ScrewDriverPostgreSqlOptions.java │ │ ├── ScrewDriverSqlServerOptions.java │ │ └── ScrewDriverSqliteOptions.java └── resources │ └── SdTemplates │ ├── Controller.ftl │ ├── Dao.ftl │ ├── JavaEntity.ftl │ ├── JavaFluentEntity.ftl │ ├── JavaLombokEntity.ftl │ ├── Service.ftl │ ├── jpa │ ├── Controller.ftl │ ├── Dao.ftl │ ├── Entity.ftl │ ├── EntityLombok.ftl │ ├── Service.ftl │ ├── ServiceImpl.ftl │ └── Test.ftl │ ├── mybatis-plus │ ├── Controller.ftl │ ├── Dao.ftl │ ├── Entity.ftl │ ├── EntityLombok.ftl │ ├── Service.ftl │ ├── ServiceImpl.ftl │ └── Test.ftl │ ├── mybatis │ ├── Controller.ftl │ ├── DB2Mapper.ftl │ ├── Dao.ftl │ ├── Entity.ftl │ ├── EntityLombok.ftl │ ├── MySqlMapper.ftl │ ├── OracleMapper.ftl │ ├── PostgreSqlMapper.ftl │ ├── Service.ftl │ ├── ServiceImpl.ftl │ ├── SqlAssist.ftl │ ├── SqlServerMapper.ftl │ ├── SqliteMapper.ftl │ └── Test.ftl │ ├── vertx │ ├── Entity.ftl │ ├── EntityLombok.ftl │ ├── Router.ftl │ ├── RouterEmpty.ftl │ ├── SQL.ftl │ ├── Service.ftl │ ├── ServiceEmpty.ftl │ ├── ServiceImpl.ftl │ ├── ServiceImplEmpty.ftl │ └── Test.ftl │ └── vertx3 │ ├── Entity.ftl │ ├── EntityLombok.ftl │ ├── Router.ftl │ ├── RouterEmpty.ftl │ ├── SQL.ftl │ ├── Service.ftl │ ├── ServiceEmpty.ftl │ ├── ServiceImpl.ftl │ ├── ServiceImplEmpty.ftl │ └── Test.ftl └── test └── java └── org └── mirrentools └── sd ├── .gitignore ├── Db2Test.java ├── OracleTest2.java ├── ScrewDriverCreateCodeOnlyExample.java ├── ScrewDriverCreateExample.java ├── ScrewDriverReadExample.java ├── SdUtilTest.java ├── constant ├── CommonConstant.java ├── MySqlConstant.java ├── PostgreSqlConstant.java ├── SqlServerConstant.java └── SqliteConstant.java ├── converter ├── SdClassConverterMySQLTest.java ├── SdTableToClassConverterTest.java └── SdTemplateContentConverterTest.java ├── dbutil ├── mysql │ ├── SdDbUtilMySqlExecuteTest.java │ └── SdDbUtilMySqlQueryTest.java ├── postgresql │ ├── SdDbUtilPostgreSqlExecuteTest.java │ └── SdDbUtilPostgreSqlQueryTest.java ├── sqlite │ ├── SdDbUtilSqliteExecuteTest.java │ └── SdDbUtilSqliteQueryTest.java └── sqlserver │ ├── SdDbUtilSqlServerExecuteTest.java │ └── SdDbUtilSqlServerQueryTest.java ├── templateutil ├── Constant.java ├── FreeMarkerTest.java ├── FreeMarkerTestJpa.java ├── FreeMarkerTestMB.java ├── FreeMarkerTestMP.java └── MvelTest.java └── util ├── CodeUtilByFreeMarkerTest.java ├── ScrewDriverMySQLTest.java ├── ScrewDriverPostgreSQLTest.java ├── ScrewDriverSqlServerTest.java └── ScrewDriverSqliteTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | /target/ 25 | /.settings/ 26 | /.classpath 27 | /.project 28 | /SdTemplates/ 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 MirrenTools 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /screw-driver-docs/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ -------------------------------------------------------------------------------- /screw-driver-docs/README.md: -------------------------------------------------------------------------------- 1 | # 本文档使用vuepress进行编写 2 | # 启动方法yarn docs:dev 或 npm run docs:dev 3 | # 编译使用yarn docs:build 或 npm run docs:build 4 | # dist为编译后的文档,文档地址: -------------------------------------------------------------------------------- /screw-driver-docs/dist/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ScrewDriver V1.2.5 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

404

How did we get here?
Take me home.
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /screw-driver-docs/dist/assets/img/search.83621669.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /screw-driver-docs/dist/assets/js/15.49eb6595.js: -------------------------------------------------------------------------------- 1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[15],{9:function(n,w,o){}}]); -------------------------------------------------------------------------------- /screw-driver-docs/dist/assets/js/3.78213f14.js: -------------------------------------------------------------------------------- 1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[3],{202:function(t,e,n){"use strict";var a=n(72);n.n(a).a},215:function(t,e,n){"use strict";n.r(e);var a={functional:!0,props:{type:{type:String,default:"tip"},text:String,vertical:{type:String,default:"top"}},render:function(t,e){var n=e.props,a=e.slots;return t("span",{class:["badge",n.type],style:{verticalAlign:n.vertical}},n.text||a().default)}},i=(n(202),n(0)),r=Object(i.a)(a,void 0,void 0,!1,null,"5fd9ae70",null);e.default=r.exports},72:function(t,e,n){}}]); -------------------------------------------------------------------------------- /screw-driver-docs/dist/assets/js/4.7d75b37f.js: -------------------------------------------------------------------------------- 1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[4],{204:function(t,e,s){"use strict";s.r(e);var o=["There's nothing here.","How did we get here?","That's a Four-Oh-Four.","Looks like we've got some broken links."],n={methods:{getMsg:function(){return o[Math.floor(Math.random()*o.length)]}}},i=s(0),h=Object(i.a)(n,(function(){var t=this.$createElement,e=this._self._c||t;return e("div",{staticClass:"theme-container"},[e("div",{staticClass:"theme-default-content"},[e("h1",[this._v("404")]),this._v(" "),e("blockquote",[this._v(this._s(this.getMsg()))]),this._v(" "),e("router-link",{attrs:{to:"/"}},[this._v("Take me home.")])],1)])}),[],!1,null,null,null);e.default=h.exports}}]); -------------------------------------------------------------------------------- /screw-driver-docs/dist/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirrenTools/screw-driver/f9fc86418ba2dc67c7a54d8fb63a777c7b57a882/screw-driver-docs/dist/favicon.ico -------------------------------------------------------------------------------- /screw-driver-docs/dist/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirrenTools/screw-driver/f9fc86418ba2dc67c7a54d8fb63a777c7b57a882/screw-driver-docs/dist/logo.png -------------------------------------------------------------------------------- /screw-driver-docs/docs/.vuepress/config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | base: '/screw-driver-docs/', 3 | title: 'ScrewDriver V1.2.5', 4 | description: '用于生成代码、创建或读取数据库表的工具包', 5 | dest: 'dist', 6 | themeConfig: { 7 | nav: [{ 8 | text: 'MirrenTools', 9 | link: 'https://mirrentools.org' 10 | }, 11 | { 12 | text: 'github', 13 | link: 'https://github.com/MirrenTools/screw-driver' 14 | }, 15 | { 16 | text: 'gitee', 17 | link: 'https://gitee.com/mirren/screw-driver' 18 | } 19 | ], 20 | sidebar: { 21 | '/': [{ 22 | title: '使用说明', 23 | collapsable: false, 24 | children: ['/start/introduction', '/start/core-class-intro','/start/sd-type','/start/ide-code-block','/start/template-rule','/start/template-attr','/start/sql-assist','/start/expand','/start/license'] 25 | }] 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /screw-driver-docs/docs/.vuepress/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirrenTools/screw-driver/f9fc86418ba2dc67c7a54d8fb63a777c7b57a882/screw-driver-docs/docs/.vuepress/public/favicon.ico -------------------------------------------------------------------------------- /screw-driver-docs/docs/.vuepress/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirrenTools/screw-driver/f9fc86418ba2dc67c7a54d8fb63a777c7b57a882/screw-driver-docs/docs/.vuepress/public/logo.png -------------------------------------------------------------------------------- /screw-driver-docs/docs/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | home: true 3 | heroImage: logo.png 4 | actionText: 使用文档 5 | actionLink: /start/introduction 6 | features: 7 | - title: 基于模板引擎 8 | details: 生成代码的风格由你自由编写模板,已实现FreeMarker、MVEL等模板引擎 9 | - title: 支持多种数据库 10 | details: 支持MySQL、PostgreSQL、Oracle、DB2、SQL Server、SQLite等数据库 11 | - title: 插拔式 12 | details: 插拔式设计二次开发、拓展更简单 13 | footer: MIT Licensed | Copyright © 2019-present mirrentools.org 14 | --- 15 | ## 快速了解ScrewDriver的作用 16 | 如果不能观看你可以在 [哔哩哔哩中查看视频](https://www.bilibili.com/video/BV1h54y1s7Zr) 17 | 18 | 19 | 20 | ScrewDriver是一个用于生成代码、创建或读取数据库表信息的工具包,可用于IDE编程式生成代码(包括数据库表的读取与创建)或作为其他工具的支持包! 21 | ``` XML 22 | 23 | org.mirrentools 24 | screw-driver 25 | [1.0.0,2.0.0) 26 | 27 | ``` 28 | ::: warning 运行环境要求 29 | java >= 1.6 30 | ::: -------------------------------------------------------------------------------- /screw-driver-docs/docs/start/expand.md: -------------------------------------------------------------------------------- 1 | # 拓展与自定义 2 | ## 目录结构 3 | ``` 4 | screw-driver 5 | ┣━ screw-driver-docs 工具的使用帮助文档,使用vuepress编写(https://www.vuepress.cn/) 6 | ┣━ src/main/resources/SdTemplates 为模板目录,模板通常不会被直接使用,因为当需要该目录的模板时就会copy模板到根目录的SdTemplates文件夹中,如果不存在就创建 7 | ┗━ src/main/java/org/mirrentools/sd/ 代码,基于java1.6编写,maven管理 8 | ┣━ common [包]一些通用的工具 9 | ┣━ constant [包]一些常量 10 | ┣━ converter [包]转换器的接口与实现,分别为接口 > 抽象类(SdAbstract) > 基础实现(SdBasic) > 具体实现(impl包) 11 | ┣━ enums [包]一些枚举类 12 | ┣━ impl [包]核心工具的基础实现 13 | ┣━ models [包]工具的实体类其中db包中update用于创建或修改数据库表信息,query用于查询数据库表信息 14 | ┣━ options [包]一些配置信息,其中def包为不同数据库的默认配置 15 | ┣━ ScrewDriver (类)核心接口 16 | ┣━ ScrewDriverCode (类)生成代码的接口 17 | ┣━ ScrewDriverDbUtil (类)数据库相关操作工具 18 | ┣━ ScrewDriverException (类)异常类 19 | ┣━ ScrewDriverProject (类)创建项目的接口 20 | ┣━ ScrewDriverSQL (类)创建或读取操作数据库的接口 21 | ┣━ ScrewDriverTemplateEngine (类)模板渲染引擎(生成文件)的接口 22 | ┗━ SdType (类)自适应数据类型 23 | ``` 24 | 25 | ## 数据库支持 26 | 如果数据库相关操作不兼容,你可以继承ScrewDriverDbUtil接口的实现或converter包中的实现,并重写不兼容的方法后设置 [ScrewDriverOptions](./core-class-intro.md#screwdriveroptions-工具配置) 为你重写后的实现。 27 | 28 | 如果你想新增其他数据库支持,大楷你需要做这些操作 29 | 1. 在org.mirrentools.sd.impl.dbutil包中创建ScrewDriverDbUtil的实现类,可继承SdAbstractDbUtil抽象类,重写抽象类不兼容的方法,可以参考同级实现,推荐命名规则为SdDbUtil新数据库名Impl 30 | 2. 在org.mirrentools.sd.converter.impl中创建新数据库名相同的包名,并实现converter中的几个转换器,可以参考同级实现,推荐命名SdXxxConverter新数据库名称Impl 31 | 3. 在org.mirrentools.sd.options.def中创建新数据库配置文件,并在ScrewDriverOptions的init方法中判断配置并初始化新数据库配置,可以参考同级实现,推荐命名规则为ScrewDriver新数据库名Options 32 | 4. 在org.mirrentools.sd.constant中添加新数据库的常量类 33 | 5. 在org.mirrentools.sd.enums.SdTypeMode枚举类中添加新数据库类型,并在 [SdType](./sd-type.md) 类中添加新数据库词典以及对应的数据类型 34 | 35 | 36 | ## 自定义模板引擎 37 | 软件目前提供了FreeMarker与MVEL开箱即用的模板引擎,如果这两个不满足或需要自定义模板, 38 | 39 | 你可以继承**org.mirrentools.sd.ScrewDriverTemplateEngine**抽象类并实现render方法, 40 | 41 | 具体实现可以参考**org.mirrentools.sd.impl.ScrewDriverTemplateFreeMarkerImpl** 或 **ScrewDriverTemplateMvelImpl**。 42 | 43 | 启用自定义模板渲染引擎需要设置 [ScrewDriverOptions](./core-class-intro.md#screwdriveroptions) 的templateEngine属性,既调用setTemplateEngine(你的实现类) -------------------------------------------------------------------------------- /screw-driver-docs/docs/start/license.md: -------------------------------------------------------------------------------- 1 | # 关于我们 2 | ## 联系我们 3 | QQ交流群: 519714660 QQ交流群
4 | 联系邮箱: mirrentools@vip.qq.com
5 | github : [https://github.com/MirrenTools/screw-driver](https://github.com/MirrenTools/screw-driver)
6 | 码云 : [https://gitee.com/mirren/screw-driver](https://gitee.com/mirren/screw-driver)
7 | 8 | ## 维护者 9 | [Mirren](https://github.com/shenzhenMirren) 10 | [likangkang](https://github.com/likangkang1) 11 | ## 贡献者 12 | [Jossc](https://github.com/Jossc) 13 | [zhangceven](https://github.com/zhangceven) 14 | 15 | ## 文档框架 16 | [vuepress](https://www.vuepress.cn/) 17 | ## 文档网页服务 18 | [码云](https://gitee.com/) 19 | ## License 20 | ``` 21 | The MIT License (MIT) 22 | 23 | Copyright (c) 2019-Present https://mirrentools.org 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a copy 26 | of this software and associated documentation files (the "Software"), to deal 27 | in the Software without restriction, including without limitation the rights 28 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 29 | copies of the Software, and to permit persons to whom the Software is 30 | furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in all 33 | copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 41 | SOFTWARE. 42 | ``` -------------------------------------------------------------------------------- /screw-driver-docs/docs/start/sql-assist.md: -------------------------------------------------------------------------------- 1 | # SqlAssist帮助类说明 2 | SqlAssist是为ScrewDriver生成SQL所定制的查询帮助类,可以用于简化工具生成的Vert.x或MyBatis的SQL查询,在Vert.x于MyBatis中具体方法可能存在差异,但使用方法基本一致! 3 | 4 | 具体使用方式可以查看SqlAssist类的方法注释,如果不清楚的可以在群里咨询 5 | ## 方法说明 6 | * **setOrders** 设置排序,通过SqlAssist.order(列名,排序方式) 7 | * **setGroupBy** 设置分组 8 | * **setHaving** 设置分组条件 9 | * **setDistincts** 设置是否去重,true去重 10 | * **setPage** 设置第几页,该值仅在limitAll方法中有效,最终会被转换为startRow 11 | * **setStartRow** 设置从第几行开始取数据 12 | * **setRowSize** 设置每次取多少很数据 13 | * **setResultColumn** 设置返回指定列多个列以,逗号隔开 14 | * **setJoinOrReference** 设置连接查询或多表查询语句 15 | * **and** 添加并且条件 16 | * **or** 添加或者条件 17 | * **andEq** 添加并且等于条件 18 | * **orEq** 添加或者等于条件 19 | * **andNeq** 添加并且不等于条件 20 | * **orNeq** 添加或者不等于条件 21 | * **andLt** 添加并且小于条件 22 | * **orLt** 添加或者小于条件 23 | * **andLte** 添加并且小于等于条件 24 | * **orLte** 添加或者小于等于条件 25 | * **andGt** 添加并且大于条件 26 | * **orGt** 添加或者大于条件 27 | * **andGte** 添加并且大于等于条件 28 | * **orGte** 添加或者大于等于条件 29 | * **andLike** 添加并且like条件 30 | * **orLike** 添加或者like条件 31 | * **andNotLike** 添加并且not like条件 32 | * **orNotLike** 添加或者not like条件 33 | * **andIsNull** 添加并且is null条件 34 | * **orIsNull** 添加或者is null条件 35 | * **andIsNotNull** 添加并且is not null条件 36 | * **orIsNotNull** 添加或者is not null条件 37 | * **setConditions** 添加查询条件 38 | * **customCondition** 添加自定义查询条件 39 | ## 使用示例 40 | ``` java 41 | // (1)创建Assist帮助类 42 | SqlAssist assist = new SqlAssist(); 43 | // (2)添加条件type=1或3,相当于SQL: where type=1 or type=3 44 | assist.orEq("type", 1).orEq("type", 3); 45 | // (3)去掉重复的数据,相当于SQL: select distinct ... 46 | assist.setDistincts(true); 47 | // (4)自定义只返回id,type,name,seq列 48 | assist.setResultColumn("id,type,name,seq"); 49 | // (5)通过seq类倒序排序,相当于SQL: order by seq desc 50 | assist.setOrders(SqlAssist.order("seq", false)); 51 | // (6)获取数据库中第20-35行的数据,你也可以使用setPage(第几页)的方式进行分页获取,相当于SQL: limit 20,15 52 | assist.setStartRow(20).setRowSize(15); 53 | // (7)执行获取数据 54 | List result = itemsDao.selectAll(assist); 55 | ``` 56 | -------------------------------------------------------------------------------- /screw-driver-docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "screw-driver-docs", 3 | "version": "1.2.6", 4 | "description": "screw-driver的文档", 5 | "scripts": { 6 | "docs:dev": "vuepress dev docs", 7 | "docs:build": "vuepress build docs" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/MirrenTools/screw-driver.git" 12 | }, 13 | "keywords": [ 14 | "screw-driver","数据库与代码生成" 15 | ], 16 | "author": "Mirren", 17 | "license": "MIT" 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/ScrewDriver.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | import java.util.Map; 4 | 5 | import org.mirrentools.sd.impl.ScrewDriverImpl; 6 | import org.mirrentools.sd.models.SdBean; 7 | import org.mirrentools.sd.models.SdClassContent; 8 | import org.mirrentools.sd.models.SdDatabase; 9 | import org.mirrentools.sd.models.SdTemplate; 10 | import org.mirrentools.sd.options.ScrewDriverOptions; 11 | 12 | /** 13 | * ScrewDriver的核心,用于生成代码与数据库操作 14 | * 15 | * @author Mirren 16 | * 17 | */ 18 | public abstract class ScrewDriver { 19 | 20 | /** 21 | * 根据配置文件实例化ScrewDriver 22 | * 23 | * @param options 24 | * @return 25 | */ 26 | public static ScrewDriver instance(ScrewDriverOptions options) { 27 | return new ScrewDriverImpl(options); 28 | } 29 | 30 | // /** 31 | // * 生成项目 32 | // * 33 | // * @return 34 | // */ 35 | // public abstract boolean createProject(); 36 | 37 | /** 38 | * 生成代码 39 | * 40 | * @param bean 类或表属性的描述 41 | * @param templateMaps 生成类需要用到的模板 42 | * @return 43 | */ 44 | public abstract boolean createCode(SdBean bean, Map templateMaps); 45 | 46 | /** 47 | * 生成代码 48 | * 49 | * @param classContent 类属性的描述 50 | * @param templateMaps 生成类需要用到的模板 51 | * @return 52 | */ 53 | public abstract boolean createCode(SdClassContent classContent, Map templateMaps); 54 | 55 | /** 56 | * 创建数据库 57 | * 58 | * @param database 数据库属性描述 59 | * @return 60 | */ 61 | public abstract boolean createDatabase(SdDatabase database); 62 | 63 | /** 64 | * 创建表 65 | * 66 | * @param bean 表属性的描述 67 | * @return 68 | */ 69 | public abstract boolean createTable(SdBean bean); 70 | 71 | /** 72 | * 读取表信息 73 | * 74 | * @param tableName 表的名称 75 | * @return 76 | */ 77 | public abstract SdClassContent readTable(String tableName); 78 | 79 | /** 80 | * 修改表 81 | * 82 | * @param bean 表属性的描述 83 | * @return 84 | */ 85 | public abstract boolean updateTable(SdBean bean); 86 | 87 | /** 88 | * 删除表 89 | * 90 | * @param bean 表属性的描述 91 | * @return 92 | */ 93 | public abstract boolean deleteTable(SdBean bean); 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/ScrewDriverException.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | /** 4 | * 代码生成器的异常类 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class ScrewDriverException extends RuntimeException { 10 | private static final long serialVersionUID = 5236581232824826486L; 11 | 12 | /** 13 | * 初始化一个异常 14 | * 15 | * @param msg 16 | */ 17 | public ScrewDriverException(String msg) { 18 | super(msg); 19 | } 20 | 21 | /** 22 | * 初始化一个异常 23 | * 24 | * @param throwable 25 | */ 26 | public ScrewDriverException(Throwable throwable) { 27 | super(throwable); 28 | } 29 | 30 | /** 31 | * 初始化一个异常 32 | * 33 | * @param msg 34 | */ 35 | public ScrewDriverException(String msg, Throwable throwable) { 36 | super(msg, throwable); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/ScrewDriverProject.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | /** 4 | * 项目生成工具 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public interface ScrewDriverProject { 10 | /** 11 | * 执行生成 12 | * 13 | * @return 14 | */ 15 | boolean execute(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/ScrewDriverSQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | import java.util.Map; 4 | 5 | import org.mirrentools.sd.converter.SdTableContentConverter; 6 | import org.mirrentools.sd.models.SdBean; 7 | import org.mirrentools.sd.models.SdClassContent; 8 | import org.mirrentools.sd.models.SdDatabase; 9 | import org.mirrentools.sd.options.SdDatabaseOptions; 10 | 11 | /** 12 | * 数据库生成工具 13 | * 14 | * @author Mirren 15 | * 16 | */ 17 | public interface ScrewDriverSQL { 18 | /** 19 | * 创建数据库 20 | * 21 | * @param database 22 | * 数据库属性描述 23 | * @return 24 | */ 25 | boolean createDatabase(SdDatabase database); 26 | 27 | /** 28 | * 创建表 29 | * 30 | * @param bean 31 | * 表属性的描述 32 | * @return 33 | */ 34 | boolean createTable(SdBean bean); 35 | 36 | /** 37 | * 读取表信息 38 | * 39 | * @param tableName 40 | * 表的名称 41 | * @return 42 | */ 43 | SdClassContent readTable(String tableName); 44 | 45 | /** 46 | * 修改表 47 | * 48 | * @param bean 49 | * 表属性的描述 50 | * @return 51 | */ 52 | boolean alterTable(SdBean bean); 53 | 54 | /** 55 | * 删除表 56 | * 57 | * @param bean 58 | * 表属性的描述 59 | * @return 60 | */ 61 | boolean deleteTable(SdBean bean); 62 | 63 | /** 64 | * 获取数据库连接属性 65 | * 66 | * @return 67 | */ 68 | SdDatabaseOptions getDatabaseOptions(); 69 | 70 | /** 71 | * 设置数据库连接属性 72 | * 73 | * @param dbOptions 74 | * @return 75 | */ 76 | ScrewDriverSQL setDatabaseOptions(SdDatabaseOptions dbOptions); 77 | 78 | /** 79 | * 获取数据库操作工具 80 | * 81 | * @return 82 | */ 83 | ScrewDriverDbUtil getDbUtil(); 84 | 85 | /** 86 | * 数据库操作工具 87 | * 88 | * @param dbUtil 89 | * @return 90 | */ 91 | ScrewDriverSQL setDbUtil(ScrewDriverDbUtil dbUtil); 92 | 93 | /** 94 | * 获取转换器 95 | * 96 | * @return 97 | */ 98 | SdTableContentConverter getConverter(); 99 | 100 | /** 101 | * 设置转换器 102 | * 103 | * @param converter 104 | * @return 105 | */ 106 | ScrewDriverSQL setConverter(SdTableContentConverter converter); 107 | 108 | /** 109 | * 添加附加属性 110 | * 111 | * @param key 112 | * @param value 113 | * @return 114 | */ 115 | ScrewDriverSQL addExtension(String key, Object value); 116 | 117 | /** 118 | * 获取附加属性集合 119 | * 120 | * @return 121 | */ 122 | Map getExtensions(); 123 | 124 | /** 125 | * 设置附加属性集合 126 | * 127 | * @param extensions 128 | * @return 129 | */ 130 | ScrewDriverSQL setExtensions(Map extensions); 131 | 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/ScrewDriverTemplateEngine.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.common.SdUtil; 7 | import org.mirrentools.sd.models.SdRenderContent; 8 | import org.mirrentools.sd.models.SdTemplate; 9 | 10 | /** 11 | * 模板渲染引擎(生成文件) 12 | * 13 | * @author Mirren 14 | * 15 | */ 16 | public abstract class ScrewDriverTemplateEngine { 17 | /** 拓展属性 */ 18 | private Map extensions; 19 | 20 | /** 21 | * 渲染模板,规范建议:
22 | * 1.遵循 {@link org.mirrentools.sd.common.SdTemplatePathUtil}中的获取path与获取file规则
23 | * 2.SdRenderContent使用content添加既然模板上下文的名称为content 24 | * 25 | * @param outputPath 26 | * 输出文件夹 27 | * @param format 28 | * 编码格式 29 | * @param content 30 | * 模板生成所需要的内容 31 | * @param template 32 | * 模板信息 33 | * @return 34 | */ 35 | public abstract boolean render(String outputPath, String format, SdRenderContent content, SdTemplate template); 36 | 37 | /** 38 | * 获得拓展属性值 39 | * 40 | * @return 41 | */ 42 | public Object getExtension(String key) { 43 | if (SdUtil.isNullOrEmpty(getExtensions())) { 44 | return null; 45 | } 46 | return getExtensions().get(key); 47 | } 48 | 49 | /** 50 | * 添加附加属性 51 | * 52 | * @param key 53 | * @param value 54 | * @return 55 | */ 56 | public ScrewDriverTemplateEngine addExtension(String key, Object value) { 57 | if (getExtensions() == null) { 58 | setExtensions(new LinkedHashMap()); 59 | } 60 | this.extensions.put(key, value); 61 | return this; 62 | } 63 | 64 | /** 65 | * 获取拓展属性 66 | * 67 | * @return 68 | */ 69 | public Map getExtensions() { 70 | return extensions; 71 | } 72 | 73 | /** 74 | * 设置拓展属性 75 | * 76 | * @param extensions 77 | * @return 78 | */ 79 | public ScrewDriverTemplateEngine setExtensions(Map extensions) { 80 | this.extensions = extensions; 81 | return this; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/common/SdIoUtil.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.common; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.BufferedOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.OutputStream; 8 | 9 | /** 10 | * Io相关工具,如果JDK大于等于1.7其实用Files也很方便的 11 | * 12 | * @author Mirren 13 | * 14 | */ 15 | public class SdIoUtil { 16 | /** 17 | * 写数据后同时将流关闭 18 | * 19 | * @param inputStream 20 | * @param outputStream 21 | * @throws Exception 22 | */ 23 | public static void writeAndClose(InputStream inputStream, OutputStream outputStream) throws Exception { 24 | BufferedInputStream input = null; 25 | BufferedOutputStream output = null; 26 | try { 27 | input = new BufferedInputStream(inputStream); 28 | output = new BufferedOutputStream(outputStream); 29 | byte[] bs = new byte[1024]; 30 | int len = 0; 31 | while ((len = input.read(bs)) != -1) { 32 | output.write(bs, 0, len); 33 | } 34 | output.flush(); 35 | } catch (Exception e) { 36 | throw e; 37 | } finally { 38 | try { 39 | if (input != null) { 40 | input.close(); 41 | } 42 | } catch (IOException e) { 43 | e.printStackTrace(); 44 | } 45 | try { 46 | if (inputStream != null) { 47 | inputStream.close(); 48 | } 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } 52 | try { 53 | if (output != null) { 54 | output.close(); 55 | } 56 | } catch (IOException e) { 57 | e.printStackTrace(); 58 | } 59 | try { 60 | if (outputStream != null) { 61 | outputStream.close(); 62 | } 63 | } catch (IOException e) { 64 | e.printStackTrace(); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/constant/DB2.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.constant; 2 | 3 | /** 4 | * DB2的常量 5 | * 6 | * @author likk 7 | * 8 | */ 9 | public interface DB2 { 10 | /** DB2名字常量=DB2 */ 11 | public final static String DB2 = "DB2"; 12 | /** DB2数据库驱动包常量=com.mysql.jdbc.Driver */ 13 | public final static String DB2_DERVER = "com.ibm.db2.jcc.DB2Driver"; 14 | /** DB2索引类型=key */ 15 | public final static String INDEX_KEY = "KEY"; 16 | /** DB2索引类型=unique index */ 17 | public final static String INDEX_UNIQUE = "UNIQUE INDEX"; 18 | /** DB2数据类型blob */ 19 | public final static String BLOB = "BLOB"; 20 | /** DB2数据类型blob */ 21 | public final static String BIGINT = "BIGINT"; 22 | /** DB2数据类型char */ 23 | public final static String CLOB = "CLOB"; 24 | /** DB2数据类型char */ 25 | public final static String CHAR = "CHAR"; 26 | /** DB2数据类型date */ 27 | public final static String DATE = "DATE"; 28 | /** DB2数据类型decimal */ 29 | public final static String DECIMAL = "DECIMAL"; 30 | /** DB2数据类型double */ 31 | public final static String DOUBLE = "DOUBLE"; 32 | /** DB2数据类型double */ 33 | public final static String GRAPHIC = "GRAPHIC"; 34 | /** DB2数据类型integer */ 35 | public final static String INTEGER = "INTEGER"; 36 | /** DB2数据类型longvarg */ 37 | public final static String LONGVARG = "LONGVARG"; 38 | /** DB2数据类型NVARCHAR */ 39 | public final static String NVARCHAR = "NVARCHAR"; 40 | /** DB2数据类型real */ 41 | public final static String REAL = "REAL"; 42 | /** DB2数据类型smallint */ 43 | public final static String SMALLINT = "SMALLINT"; 44 | /** DB2数据类型time */ 45 | public final static String TIME = "TIME"; 46 | /** DB2数据类型timestamp */ 47 | public final static String TIMESTAMP = "TIMESTAMP"; 48 | /** DB2数据类型varchar */ 49 | public final static String VARCHAR = "VARCHAR"; 50 | /** DB2数据类型distinct */ 51 | public final static String DISTINCT = "DISTINCT"; 52 | /** DB2数据类型xml */ 53 | public final static String XML = "XML"; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/constant/Oracle.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.constant; 2 | 3 | /** 4 | * Oracle的常量 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public interface Oracle { 10 | /** ORACLE名字常量=Oracle */ 11 | public final static String ORACLE = "Oracle"; 12 | /** ORACLE数据库驱动包常量=oracle.jdbc.driver.OracleDriver */ 13 | public final static String ORACLE_DERVER = "oracle.jdbc.driver.OracleDriver"; 14 | 15 | 16 | public static final String CHAR = "char"; 17 | 18 | public static final String NCHAR = "nchar"; 19 | 20 | public static final String VARCHAR2 = "varchar2"; 21 | 22 | public static final String NVARCHAR2 = "nvarchar2"; 23 | 24 | public static final String CLOB = "clob"; 25 | 26 | public static final String BLOB = "blob"; 27 | 28 | public static final String NCLOB = "nclob"; 29 | 30 | public static final String LONG = "long"; 31 | 32 | public static final String DATE = "date"; 33 | 34 | public static final String TIMESTAMP = "timestamp"; 35 | 36 | public static final String RAW = "raw"; 37 | 38 | public static final String NUMBER = "number"; 39 | 40 | public static final String DECIMAL = "decimal"; 41 | 42 | public static final String INTEGER = "integer"; 43 | 44 | public static final String FLOAT = "float"; 45 | 46 | public static final String REAL = "real"; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/constant/SQLite.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.constant; 2 | 3 | /** 4 | * Sqlite常量 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public interface SQLite { 10 | /** SQLite名字常量=SQLite */ 11 | public final static String SQLITE = "SQLite"; 12 | /** SQLite数据库驱动包常量=org.sqlite.JDBC */ 13 | public final static String SQLITE_DERVER = "org.sqlite.JDBC"; 14 | 15 | /** SQLite数据类型null */ 16 | public final static String NULL = "NULL"; 17 | /** SQLite数据类型bool */ 18 | public final static String BOOL = "BOOL"; 19 | /** SQLite数据类型boolean */ 20 | public final static String BOOLEAN = "BOOLEAN"; 21 | /** SQLite数据类型binary */ 22 | public final static String BINARY = "BINARY"; 23 | /** SQLite数据类型int */ 24 | public final static String INT = "INT"; 25 | /** SQLite数据类型integer */ 26 | public final static String INTEGER = "INTEGER"; 27 | /** SQLite数据类型tinyint */ 28 | public final static String TINYINT = "TINYINT"; 29 | /** SQLite数据类型smallint */ 30 | public final static String SMALLINT = "SMALLINT"; 31 | /** SQLite数据类型mediumint */ 32 | public final static String MEDIUMINT = "MEDIUMINT"; 33 | /** SQLite数据类型bigint */ 34 | public final static String BIGINT = "BIGINT"; 35 | /** SQLite数据类型unsigned big int */ 36 | public final static String UNSIGNED_BIG_INT = "UNSIGNED BIG INT"; 37 | /** SQLite数据类型int2 */ 38 | public final static String INT2 = "INT2"; 39 | /** SQLite数据类型int8 */ 40 | public final static String INT8 = "INT8"; 41 | /** SQLite数据类型char */ 42 | public final static String CHAR = "CHAR"; 43 | /** SQLite数据类型nchar */ 44 | public final static String NCHAR = "NCHAR"; 45 | /** SQLite数据类型varchar */ 46 | public final static String VARCHAR = "VARCHAR"; 47 | /** SQLite数据类型varchar2 */ 48 | public final static String VARCHAR2 = "VARCHAR2"; 49 | /** SQLite数据类型nvarchar */ 50 | public final static String NVARCHAR = "NVARCHAR"; 51 | /** SQLite数据类型nvarchar2 */ 52 | public final static String NVARCHAR2 = "NVARCHAR2"; 53 | /** SQLite数据类型text */ 54 | public final static String TEXT = "TEXT"; 55 | /** SQLite数据类型blob */ 56 | public final static String BLOB = "BLOB"; 57 | /** SQLite数据类型clob */ 58 | public final static String CLOB = "CLOB"; 59 | 60 | /** SQLite数据类型real */ 61 | public final static String REAL = "REAL"; 62 | /** SQLite数据类型float */ 63 | public final static String FLOAT = "FLOAT"; 64 | /** SQLite数据类型double */ 65 | public final static String DOUBLE = "DOUBLE"; 66 | /** SQLite数据类型double precision */ 67 | public final static String DOUBLE_PRECISION = "DOUBLE PRECISION"; 68 | /** SQLite数据类型numeric */ 69 | public final static String NUMERIC = "NUMERIC"; 70 | /** SQLite数据类型decimal */ 71 | public final static String DECIMAL = "DECIMAL"; 72 | /** SQLite数据类型money */ 73 | public final static String MONEY = "MONEY"; 74 | 75 | /** SQLite数据类型date */ 76 | public final static String DATE = "DATE"; 77 | /** SQLite数据类型time */ 78 | public final static String TIME = "TIME"; 79 | /** SQLite数据类型datetime */ 80 | public final static String DATETIME = "DATETIME"; 81 | /** SQLite数据类型timestamp */ 82 | public final static String TIMESTAMP = "TIMESTAMP"; 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/constant/SdConstant.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.constant; 2 | 3 | /** 4 | * 常用字符串常量 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public interface SdConstant { 10 | 11 | /** UTF-8 */ 12 | public static final String UTF_8 = "UTF-8"; 13 | /** src/main/java/ */ 14 | public static final String MAVEN_SRC = "src/main/java/"; 15 | /** src/test/java/ */ 16 | public static final String MAVEN_TEST = "src/test/java/"; 17 | /** java的文件后缀名 */ 18 | public static final String JAVA_SUFFIX = ".java"; 19 | 20 | /** 2个空白缩进 */ 21 | public static final String TAG2 = " "; 22 | /** 4个空白缩进的数量 */ 23 | public static final String TAG4 = " "; 24 | /** 6个空白缩进的数量 */ 25 | public static final String TAG6 = " "; 26 | /** 7个空白缩进的数量 */ 27 | public static final String TAG8 = " "; 28 | /** 1个换行 */ 29 | public static final String RN = "\r\n"; 30 | /** 2个换行 */ 31 | public static final String RN2 = "\r\n\r\n"; 32 | /** 3个换行 */ 33 | public static final String RN3 = "\r\n\r\n\r\n"; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/SdAbstractTypeConverter.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * 数据类型转换的抽象实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public abstract class SdAbstractTypeConverter implements SdTypeConverter { 12 | /** 基类的数据类型 */ 13 | private String baseType; 14 | 15 | public SdAbstractTypeConverter(String baseType) { 16 | super(); 17 | this.baseType = baseType; 18 | } 19 | 20 | @Override 21 | public String converter(String type) { 22 | String result = getDict().get(type); 23 | return result == null ? baseType : result; 24 | } 25 | 26 | @Override 27 | public String converter(String type, String defaultt) { 28 | String result = getDict().get(type); 29 | return result == null ? defaultt : result; 30 | } 31 | 32 | @Override 33 | public SdAbstractTypeConverter putDict(String key, String value) { 34 | if (getDict() == null) { 35 | setDict(new HashMap()); 36 | } 37 | getDict().put(key, value); 38 | return this; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/SdBasicClassConverter.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | /** 4 | * SdBean转换器的基本实现 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class SdBasicClassConverter extends SdAbstractClassConverter { 10 | /** 将数据库数据类型转换为Java类型 */ 11 | private SdTypeConverter typeConverter; 12 | 13 | /** 14 | * 初始化 15 | * 16 | * @param typeConverter 17 | * 类型转换器 18 | */ 19 | public SdBasicClassConverter(SdTypeConverter typeConverter) { 20 | super(); 21 | this.typeConverter = typeConverter; 22 | } 23 | 24 | @Override 25 | public SdTypeConverter getTypeConverter() { 26 | return typeConverter; 27 | } 28 | 29 | @Override 30 | public SdBasicClassConverter setTypeConverter(SdTypeConverter typeConverter) { 31 | this.typeConverter = typeConverter; 32 | return this; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/SdBasicTableToClassConverter.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | /** 4 | * 将SdTable转换为SdClassContent的基本实现 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class SdBasicTableToClassConverter extends SdAbstractTableToClassConverter { 10 | /** 将Bean转换为内容的类转换器 */ 11 | private SdClassConverter classConverter; 12 | 13 | /** 14 | * 初始化 15 | * 16 | * @param classConverter 17 | * 实体类转换器 18 | */ 19 | public SdBasicTableToClassConverter(SdClassConverter classConverter) { 20 | super(); 21 | this.classConverter = classConverter; 22 | } 23 | 24 | @Override 25 | public SdClassConverter getClassConverter() { 26 | return classConverter; 27 | } 28 | 29 | @Override 30 | public SdTableToClassConverter setClassConverter(SdClassConverter classConverter) { 31 | this.classConverter = classConverter; 32 | return this; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/SdBasicTypeConverter.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.common.SdUtil; 7 | 8 | /** 9 | * 数据类型转换的基本实现 10 | * 11 | * @author Mirren 12 | * 13 | */ 14 | public class SdBasicTypeConverter extends SdAbstractTypeConverter { 15 | /** 数据类型对应的字典 */ 16 | private Map dictionaryMap = new HashMap(); 17 | 18 | /** 19 | * 初始化 20 | * 21 | * @param baseType 22 | * 基础数据类型,既如果dictionary中找不到时就使用该类型 23 | * @param dictionary 24 | * 数据类型对应的字典 25 | */ 26 | public SdBasicTypeConverter(String baseType, Map dictionary) { 27 | super(baseType); 28 | SdUtil.requireNonNull(dictionary, "The dictionary cannot be null"); 29 | this.dictionaryMap = dictionary; 30 | } 31 | 32 | @Override 33 | public Map getDict() { 34 | return dictionaryMap; 35 | } 36 | 37 | @Override 38 | public SdTypeConverter setDict(Map typeMaps) { 39 | this.dictionaryMap = typeMaps; 40 | return this; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/SdClassConverter.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | import org.mirrentools.sd.models.SdBean; 4 | import org.mirrentools.sd.models.SdClassContent; 5 | 6 | /** 7 | * 将SdBean转换成类属性 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public interface SdClassConverter { 13 | /** 14 | * 转换属性 15 | * 16 | * @param bean 17 | * @return 18 | */ 19 | SdClassContent converter(SdBean bean); 20 | /** 21 | * 获取数据类型转换器 22 | * 23 | * @return 24 | */ 25 | SdTypeConverter getTypeConverter(); 26 | /** 27 | * 设置数据类型转换器 28 | * 29 | * @param typeConverter 30 | * @return 31 | */ 32 | SdClassConverter setTypeConverter(SdTypeConverter typeConverter); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/SdDatabaseContentConverter.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | import org.mirrentools.sd.models.SdDatabase; 4 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 5 | 6 | /** 7 | * 将SdDatabase转换为数据库的操作属性 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public interface SdDatabaseContentConverter { 13 | /** 14 | * 转换属性 15 | * 16 | * @param database 17 | * @return 18 | */ 19 | SdAbstractDatabaseContent converter(SdDatabase database); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/SdTableContentConverter.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | import java.util.Map; 4 | 5 | import org.mirrentools.sd.models.SdBean; 6 | import org.mirrentools.sd.models.db.update.SdAbstractTableContent; 7 | 8 | /** 9 | * 将SdBean转换为数据库表的操作属性 10 | * 11 | * @author Mirren 12 | * 13 | */ 14 | public interface SdTableContentConverter { 15 | 16 | /** 17 | * 转换属性 18 | * 19 | * @param bean 20 | * @return 21 | */ 22 | SdAbstractTableContent converter(SdBean bean); 23 | 24 | /** 25 | * 获取数据库引擎 26 | * 27 | * @return 28 | */ 29 | String getEngine(); 30 | 31 | /** 32 | * 设置数据库引擎 33 | * 34 | * @param characterSet 35 | * @return 36 | */ 37 | SdTableContentConverter setEngine(String engine); 38 | 39 | /** 40 | * 获取字符集 41 | * 42 | * @return 43 | */ 44 | String getCharacterSet(); 45 | 46 | /** 47 | * 设置字符集 48 | * 49 | * @param characterSet 50 | * @return 51 | */ 52 | SdTableContentConverter setCharacterSet(String characterSet); 53 | 54 | /** 55 | * 获取排序规则 56 | * 57 | * @return 58 | */ 59 | String getCollate(); 60 | 61 | /** 62 | * 设置数据库排序规则 63 | * 64 | * @param collate 65 | * @return 66 | */ 67 | SdTableContentConverter setCollate(String collate); 68 | 69 | /** 70 | * 获取模式 71 | * 72 | * @return 73 | */ 74 | String getSchemas(); 75 | 76 | /** 77 | * 设置模式 78 | * 79 | * @param schemas 80 | * @return 81 | */ 82 | SdTableContentConverter setSchemas(String schemas); 83 | 84 | /** 85 | * 获取SdType转换为SQL类型 86 | * 87 | * @return 88 | */ 89 | SdTypeConverter getTypeConverter(); 90 | 91 | /** 92 | * 设置SdType转换为SQL类型 93 | * 94 | * @param typeConverter 95 | * @return 96 | */ 97 | SdTableContentConverter setTypeConverter(SdTypeConverter typeConverter); 98 | 99 | /** 100 | * 获取拓展属性 101 | * 102 | * @return 103 | */ 104 | Map getExtensions(); 105 | 106 | /** 107 | * 获取拓展属性值 108 | * 109 | * @param key 110 | * @return 111 | */ 112 | Object getExtension(String key); 113 | 114 | /** 115 | * 添加拓展属性 116 | * 117 | * @param key 118 | * @param value 119 | * @return 120 | */ 121 | SdTableContentConverter putExtension(String key, Object value); 122 | 123 | /** 124 | * 设置拓展属性 125 | * 126 | * @param extensions 127 | * @return 128 | */ 129 | SdTableContentConverter setExtensions(Map extensions); 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/SdTableToClassConverter.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | import org.mirrentools.sd.models.SdClassContent; 4 | import org.mirrentools.sd.models.db.query.SdTable; 5 | 6 | /** 7 | * 将SdTable转换为SdClassContent的转换器 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public interface SdTableToClassConverter { 13 | /** 14 | * 转换属性 15 | * 16 | * @param table 17 | * @return 18 | */ 19 | SdClassContent converter(SdTable table); 20 | /** 21 | * 获取数据类型转换器 22 | * 23 | * @return 24 | */ 25 | SdClassConverter getClassConverter(); 26 | /** 27 | * 设置数据类型转换器 28 | * 29 | * @param classConverter 30 | * @return 31 | */ 32 | SdTableToClassConverter setClassConverter(SdClassConverter classConverter); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/SdTemplateContentConverter.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | import java.util.Map; 4 | 5 | import org.mirrentools.sd.models.SdClassContent; 6 | import org.mirrentools.sd.models.SdTemplate; 7 | import org.mirrentools.sd.models.SdTemplateContent; 8 | import org.mirrentools.sd.options.SdDatabaseOptions; 9 | 10 | /** 11 | * 将实体属性与模板属性转换为模板生成所需要的材料 12 | * 13 | * @author Mirren 14 | * 15 | */ 16 | public interface SdTemplateContentConverter { 17 | /** 18 | * 转换属性 19 | * 20 | * @param bean 21 | * 创建类与表所需要的属性 22 | * @param databaseOptions 23 | * 数据库连接属性 24 | * @param templates 25 | * 模板属性集 26 | * @return 27 | */ 28 | Map converter(SdClassContent bean, SdDatabaseOptions databaseOptions, Map templates); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/SdTypeConverter.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * 数据类型转换用于将不同语言之间的转换,比如SQL数据类型转换为Java数据类型,或反过来 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public interface SdTypeConverter { 12 | /** 13 | * 将类型进行转换,如果不存在转换类型就返回基类 14 | * 15 | * @param type 16 | * 数据类型 17 | * @return 18 | */ 19 | String converter(String type); 20 | /** 21 | * 将类型进行转换,并设置不存在的默认值 22 | * 23 | * @param type 24 | * 数据类型 25 | * @param defaultt 26 | * 如果词典中没有找到该类型对应的值就返回 defaultt 27 | * @return 28 | */ 29 | String converter(String type, String defaultt); 30 | 31 | /** 32 | * 获取类型集,key为SQL的数据类型,value为类的数据类型 33 | * 34 | * @return 35 | */ 36 | Map getDict(); 37 | /** 38 | * 添加类型集,如果key已经存在将其覆盖 39 | * 40 | * @param key 41 | * 数据类型 42 | * @param value 43 | * 转换目标类型数据类型 44 | * @return 45 | */ 46 | SdTypeConverter putDict(String key, String value); 47 | /** 48 | * 设置类型集 49 | * 50 | * @param type 51 | * key为数据类型,value为转换目标类型的数据类型 52 | * @return 53 | */ 54 | SdTypeConverter setDict(Map typeMaps); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/db2/SdClassConverterDB2Impl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.db2; 2 | 3 | import org.mirrentools.sd.SdType; 4 | import org.mirrentools.sd.constant.Java; 5 | import org.mirrentools.sd.converter.SdBasicClassConverter; 6 | import org.mirrentools.sd.converter.SdBasicTypeConverter; 7 | import org.mirrentools.sd.converter.SdTypeConverter; 8 | import org.mirrentools.sd.enums.SdTypeMode; 9 | 10 | public class SdClassConverterDB2Impl extends SdBasicClassConverter { 11 | 12 | /** 13 | * 使用默认的SQL数据类型转换器初始化 14 | */ 15 | public SdClassConverterDB2Impl() { 16 | super(new SdBasicTypeConverter(Java.OBJECT, SdType.getDictionary(SdTypeMode.JAVA))); 17 | } 18 | /** 19 | * 使用自定义的SQL转实体类转换器初始化 20 | * 21 | * @param typeConverter 22 | */ 23 | public SdClassConverterDB2Impl(SdTypeConverter typeConverter) { 24 | super(typeConverter); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/db2/SdTableToClassConverterDB2Impl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.db2; 2 | 3 | import org.mirrentools.sd.converter.SdBasicTableToClassConverter; 4 | import org.mirrentools.sd.converter.SdClassConverter; 5 | 6 | public class SdTableToClassConverterDB2Impl extends SdBasicTableToClassConverter { 7 | 8 | /** 9 | * 实例化一个默认的类型转换 10 | */ 11 | public SdTableToClassConverterDB2Impl() { 12 | super(new SdClassConverterDB2Impl()); 13 | } 14 | 15 | /** 16 | * 实例化一个指定类转换器 17 | * 18 | * @param classConverter 19 | */ 20 | public SdTableToClassConverterDB2Impl(SdClassConverter classConverter) { 21 | super(classConverter); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/mysql/SdClassConverterMySqlImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.mysql; 2 | 3 | import org.mirrentools.sd.SdType; 4 | import org.mirrentools.sd.constant.Java; 5 | import org.mirrentools.sd.converter.SdBasicClassConverter; 6 | import org.mirrentools.sd.converter.SdBasicTypeConverter; 7 | import org.mirrentools.sd.converter.SdTypeConverter; 8 | import org.mirrentools.sd.enums.SdTypeMode; 9 | 10 | /** 11 | * SdBean转换器转换为为Java类属性MySQL版实现 12 | * 13 | * @author Mirren 14 | * 15 | */ 16 | public class SdClassConverterMySqlImpl extends SdBasicClassConverter { 17 | 18 | /** 19 | * 使用默认的SQL数据类型转换器初始化 20 | */ 21 | public SdClassConverterMySqlImpl() { 22 | super(new SdBasicTypeConverter(Java.OBJECT, SdType.getDictionary(SdTypeMode.JAVA))); 23 | } 24 | 25 | /** 26 | * 使用自定义的SQL转实体类转换器初始化 27 | * 28 | * @param typeConverter 29 | */ 30 | public SdClassConverterMySqlImpl(SdTypeConverter typeConverter) { 31 | super(typeConverter); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/mysql/SdDatabaseConverterMySqlImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.mysql; 2 | 3 | import org.mirrentools.sd.converter.SdDatabaseContentConverter; 4 | import org.mirrentools.sd.models.SdDatabase; 5 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 6 | import org.mirrentools.sd.models.db.update.impl.mysql.SdDatabaseContentByMySQL; 7 | 8 | /** 9 | * 将SdDatabase转换为数据库的操作属性MySQL版实现 10 | * 11 | * @author Mirren 12 | * 13 | */ 14 | public class SdDatabaseConverterMySqlImpl implements SdDatabaseContentConverter { 15 | @Override 16 | public SdAbstractDatabaseContent converter(SdDatabase database) { 17 | if (database == null) { 18 | return null; 19 | } 20 | return new SdDatabaseContentByMySQL(database.getDatabase(), database.getEncoding(), database.getCollate()).setExtensions(database.getExtensions()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/mysql/SdTableToClassConverterMySqlImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.mysql; 2 | 3 | import org.mirrentools.sd.converter.SdBasicTableToClassConverter; 4 | import org.mirrentools.sd.converter.SdClassConverter; 5 | 6 | /** 7 | * 将SdTable转换为SdClassContent的转换器的PostgreSql版 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class SdTableToClassConverterMySqlImpl extends SdBasicTableToClassConverter { 13 | public SdTableToClassConverterMySqlImpl() { 14 | super(new SdClassConverterMySqlImpl()); 15 | } 16 | 17 | public SdTableToClassConverterMySqlImpl(SdClassConverter classConverter) { 18 | super(classConverter); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/oracle/SdClassConverterOracleImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.oracle; 2 | 3 | import org.mirrentools.sd.SdType; 4 | import org.mirrentools.sd.constant.Java; 5 | import org.mirrentools.sd.converter.SdBasicClassConverter; 6 | import org.mirrentools.sd.converter.SdBasicTypeConverter; 7 | import org.mirrentools.sd.converter.SdTypeConverter; 8 | import org.mirrentools.sd.enums.SdTypeMode; 9 | 10 | public class SdClassConverterOracleImpl extends SdBasicClassConverter { 11 | 12 | /** 13 | * 使用默认的SQL数据类型转换器初始化 14 | */ 15 | public SdClassConverterOracleImpl() { 16 | super(new SdBasicTypeConverter(Java.OBJECT, SdType.getDictionary(SdTypeMode.JAVA))); 17 | } 18 | /** 19 | * 使用自定义的SQL转实体类转换器初始化 20 | * 21 | * @param typeConverter 22 | */ 23 | public SdClassConverterOracleImpl(SdTypeConverter typeConverter) { 24 | super(typeConverter); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/oracle/SdTableToClassConverterOracleImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.oracle; 2 | 3 | import org.mirrentools.sd.converter.SdBasicTableToClassConverter; 4 | import org.mirrentools.sd.converter.SdClassConverter; 5 | 6 | public class SdTableToClassConverterOracleImpl extends SdBasicTableToClassConverter { 7 | 8 | /** 9 | * 实例化一个默认的类型转换 10 | */ 11 | public SdTableToClassConverterOracleImpl() { 12 | super(new SdClassConverterOracleImpl()); 13 | } 14 | 15 | /** 16 | * 实例化一个指定类转换器 17 | * 18 | * @param classConverter 19 | */ 20 | public SdTableToClassConverterOracleImpl(SdClassConverter classConverter) { 21 | super(classConverter); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/postgresql/SdClassConverterPostgreSqlImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.postgresql; 2 | 3 | import org.mirrentools.sd.SdType; 4 | import org.mirrentools.sd.constant.Java; 5 | import org.mirrentools.sd.converter.SdBasicClassConverter; 6 | import org.mirrentools.sd.converter.SdBasicTypeConverter; 7 | import org.mirrentools.sd.converter.SdTypeConverter; 8 | import org.mirrentools.sd.enums.SdTypeMode; 9 | 10 | /** 11 | * SdBean转换器转换为Java类属性PostgreSql版实现 12 | * 13 | * @author Mirren 14 | * 15 | */ 16 | public class SdClassConverterPostgreSqlImpl extends SdBasicClassConverter { 17 | 18 | public SdClassConverterPostgreSqlImpl() { 19 | super(new SdBasicTypeConverter(Java.OBJECT, SdType.getDictionary(SdTypeMode.JAVA))); 20 | } 21 | 22 | public SdClassConverterPostgreSqlImpl(SdTypeConverter typeConverter) { 23 | super(typeConverter); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/postgresql/SdDatabaseConverterPostgreSqlImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.postgresql; 2 | 3 | import org.mirrentools.sd.converter.SdDatabaseContentConverter; 4 | import org.mirrentools.sd.models.SdDatabase; 5 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 6 | import org.mirrentools.sd.models.db.update.impl.postgresql.SdDatabaseContentByPostgreSql; 7 | 8 | /** 9 | * 将SdDatabase转换为数据库的操作属性PostgreSQL版实现 10 | * 11 | * @author Mirren 12 | * 13 | */ 14 | public class SdDatabaseConverterPostgreSqlImpl implements SdDatabaseContentConverter { 15 | @Override 16 | public SdAbstractDatabaseContent converter(SdDatabase database) { 17 | if (database == null) { 18 | return null; 19 | } 20 | return new SdDatabaseContentByPostgreSql(database); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/postgresql/SdTableToClassConverterPostgreSqlImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.postgresql; 2 | 3 | import org.mirrentools.sd.converter.SdBasicTableToClassConverter; 4 | import org.mirrentools.sd.converter.SdClassConverter; 5 | 6 | /** 7 | * 将SdTable转换为SdClassContent的转换器的PostgreSql版 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class SdTableToClassConverterPostgreSqlImpl extends SdBasicTableToClassConverter { 13 | 14 | public SdTableToClassConverterPostgreSqlImpl() { 15 | super(new SdClassConverterPostgreSqlImpl()); 16 | } 17 | 18 | public SdTableToClassConverterPostgreSqlImpl(SdClassConverter classConverter) { 19 | super(classConverter); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/sqlite/SdClassConverterSqliteImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.sqlite; 2 | 3 | import org.mirrentools.sd.SdType; 4 | import org.mirrentools.sd.constant.Java; 5 | import org.mirrentools.sd.converter.SdBasicClassConverter; 6 | import org.mirrentools.sd.converter.SdBasicTypeConverter; 7 | import org.mirrentools.sd.converter.SdTypeConverter; 8 | import org.mirrentools.sd.enums.SdTypeMode; 9 | 10 | /** 11 | * SdBean转换器转换为Java类属性SQLite版实现 12 | * 13 | * @author Mirren 14 | * 15 | */ 16 | public class SdClassConverterSqliteImpl extends SdBasicClassConverter { 17 | 18 | public SdClassConverterSqliteImpl() { 19 | super(new SdBasicTypeConverter(Java.OBJECT, SdType.getDictionary(SdTypeMode.JAVA))); 20 | } 21 | 22 | public SdClassConverterSqliteImpl(SdTypeConverter typeConverter) { 23 | super(typeConverter); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/sqlite/SdTableContentConverterSqliteImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.sqlite; 2 | 3 | import org.mirrentools.sd.SdType; 4 | import org.mirrentools.sd.converter.SdAbstractTableContentConverter; 5 | import org.mirrentools.sd.converter.SdBasicTypeConverter; 6 | import org.mirrentools.sd.converter.SdTypeConverter; 7 | import org.mirrentools.sd.enums.SdTypeMode; 8 | import org.mirrentools.sd.models.SdBean; 9 | import org.mirrentools.sd.models.SdColumn; 10 | import org.mirrentools.sd.models.SdSequence; 11 | import org.mirrentools.sd.models.db.update.SdAbstractColumnContent; 12 | import org.mirrentools.sd.models.db.update.SdAbstractConstraintContent; 13 | import org.mirrentools.sd.models.db.update.SdAbstractForeignKeyContent; 14 | import org.mirrentools.sd.models.db.update.SdAbstractIndexKeyContent; 15 | import org.mirrentools.sd.models.db.update.SdAbstractPrimaryKeyContent; 16 | import org.mirrentools.sd.models.db.update.SdAbstractSequenceContent; 17 | import org.mirrentools.sd.models.db.update.SdAbstractTableContent; 18 | import org.mirrentools.sd.models.db.update.impl.sqlite.SdColumnContentBySqlite; 19 | import org.mirrentools.sd.models.db.update.impl.sqlite.SdConstraintContentBySqlite; 20 | import org.mirrentools.sd.models.db.update.impl.sqlite.SdForeignKeyContentBySqlite; 21 | import org.mirrentools.sd.models.db.update.impl.sqlite.SdIndexKeyContentBySqlite; 22 | import org.mirrentools.sd.models.db.update.impl.sqlite.SdPrimaryKeyContentBySqlite; 23 | import org.mirrentools.sd.models.db.update.impl.sqlite.SdTableContentBySqlite; 24 | 25 | /** 26 | * 将SdBean转换为SQLite数据库创建表需要的内容 27 | * 28 | * @author Mirren 29 | * 30 | */ 31 | public class SdTableContentConverterSqliteImpl extends SdAbstractTableContentConverter { 32 | 33 | public SdTableContentConverterSqliteImpl() { 34 | super(new SdBasicTypeConverter("ScrewDriver UNKNOWN TYPE", SdType.getDictionary(SdTypeMode.SQLITE))); 35 | } 36 | 37 | public SdTableContentConverterSqliteImpl(SdTypeConverter typeConverter) { 38 | super(typeConverter); 39 | } 40 | 41 | @Override 42 | public SdAbstractTableContent newTableContent(SdBean bean) { 43 | return new SdTableContentBySqlite(); 44 | } 45 | 46 | @Override 47 | public SdAbstractColumnContent newColumnContent(SdColumn col) { 48 | return new SdColumnContentBySqlite(); 49 | } 50 | 51 | @Override 52 | public SdAbstractPrimaryKeyContent newPrimaryKeyContent(SdColumn col) { 53 | return new SdPrimaryKeyContentBySqlite(); 54 | } 55 | 56 | @Override 57 | public SdAbstractIndexKeyContent newIndexKeyContent(SdColumn col) { 58 | return new SdIndexKeyContentBySqlite(); 59 | } 60 | 61 | @Override 62 | public SdAbstractForeignKeyContent newForeignKeyContent(SdColumn col) { 63 | return new SdForeignKeyContentBySqlite(); 64 | } 65 | 66 | @Override 67 | public SdAbstractConstraintContent newConstraintContent(SdColumn col) { 68 | return new SdConstraintContentBySqlite(); 69 | } 70 | 71 | @Override 72 | public SdAbstractSequenceContent newSequenceContent(SdSequence sequence) { 73 | return null; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/sqlite/SdTableToClassConverterSqliteImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.sqlite; 2 | 3 | import org.mirrentools.sd.converter.SdBasicTableToClassConverter; 4 | import org.mirrentools.sd.converter.SdClassConverter; 5 | 6 | /** 7 | * 将SdTable转换为SdClassContent的转换器的SQLite版 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class SdTableToClassConverterSqliteImpl extends SdBasicTableToClassConverter { 13 | 14 | public SdTableToClassConverterSqliteImpl() { 15 | super(new SdClassConverterSqliteImpl()); 16 | } 17 | 18 | public SdTableToClassConverterSqliteImpl(SdClassConverter classConverter) { 19 | super(classConverter); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/sqlserver/SdClassConverterSqlServerImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.sqlserver; 2 | 3 | import org.mirrentools.sd.SdType; 4 | import org.mirrentools.sd.constant.Java; 5 | import org.mirrentools.sd.converter.SdBasicClassConverter; 6 | import org.mirrentools.sd.converter.SdBasicTypeConverter; 7 | import org.mirrentools.sd.converter.SdTypeConverter; 8 | import org.mirrentools.sd.enums.SdTypeMode; 9 | 10 | /** 11 | * SdBean转换器转换为Java类属性SQL Server版实现 12 | * 13 | * @author Mirren 14 | * 15 | */ 16 | public class SdClassConverterSqlServerImpl extends SdBasicClassConverter { 17 | 18 | public SdClassConverterSqlServerImpl() { 19 | super(new SdBasicTypeConverter(Java.OBJECT, SdType.getDictionary(SdTypeMode.JAVA))); 20 | } 21 | 22 | public SdClassConverterSqlServerImpl(SdTypeConverter typeConverter) { 23 | super(typeConverter); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/sqlserver/SdDatabaseConverterSqlServerImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.sqlserver; 2 | 3 | import org.mirrentools.sd.converter.SdDatabaseContentConverter; 4 | import org.mirrentools.sd.models.SdDatabase; 5 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 6 | import org.mirrentools.sd.models.db.update.impl.sqlserver.SdDatabaseContentBySqlServer; 7 | 8 | /** 9 | * 将SdDatabase转换为数据库的操作属性SQL Server版实现 10 | * 11 | * @author Mirren 12 | * 13 | */ 14 | public class SdDatabaseConverterSqlServerImpl implements SdDatabaseContentConverter { 15 | @Override 16 | public SdAbstractDatabaseContent converter(SdDatabase database) { 17 | if (database == null) { 18 | return null; 19 | } 20 | return new SdDatabaseContentBySqlServer(database); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/converter/impl/sqlserver/SdTableToClassConverterSqlServerImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter.impl.sqlserver; 2 | 3 | import org.mirrentools.sd.converter.SdBasicTableToClassConverter; 4 | import org.mirrentools.sd.converter.SdClassConverter; 5 | 6 | /** 7 | * 将SdTable转换为SdClassContent的转换器的PostgreSql版 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class SdTableToClassConverterSqlServerImpl extends SdBasicTableToClassConverter { 13 | 14 | public SdTableToClassConverterSqlServerImpl() { 15 | super(new SdClassConverterSqlServerImpl()); 16 | } 17 | 18 | public SdTableToClassConverterSqlServerImpl(SdClassConverter classConverter) { 19 | super(classConverter); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/enums/Relational.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.enums; 2 | 3 | /** 4 | * 关系类型 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public enum Relational { 10 | OneToOne("OneToOne"), OneToMany("OneToMany"), ManyToOne("ManyToOne"), ManyToMany("ManyToMany"); 11 | /** 关系的值 */ 12 | public String val; 13 | 14 | private Relational(String val) { 15 | this.val = val; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/enums/SdTypeMode.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.enums; 2 | 3 | /** 4 | * SdColumn数据类型的模式 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public enum SdTypeMode { 10 | /** common通用数据库数据类型,该类型最低级会被其他类型覆盖 */ 11 | COMMON, 12 | /** Java数据类型 */ 13 | JAVA, 14 | /** MySQL数据类型 */ 15 | MYSQL, 16 | /** PostgreSQL数据类型 */ 17 | POSTGRE_SQL, 18 | /** DB2数据类型 */ 19 | DB2, 20 | /** Oracle数据类型 */ 21 | ORACLE, 22 | /** SQL Server数据类型 */ 23 | SQL_SERVER, 24 | /** Sqlite数据类型 */ 25 | SQLITE, 26 | /** 自定义数据类型,该类型最高级会覆盖其他类型 */ 27 | CUSTOM; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/impl/ScrewDriverImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.impl; 2 | 3 | import java.util.Map; 4 | 5 | import org.mirrentools.sd.ScrewDriver; 6 | import org.mirrentools.sd.ScrewDriverCode; 7 | import org.mirrentools.sd.ScrewDriverSQL; 8 | import org.mirrentools.sd.common.SdUtil; 9 | import org.mirrentools.sd.models.SdBean; 10 | import org.mirrentools.sd.models.SdClassContent; 11 | import org.mirrentools.sd.models.SdDatabase; 12 | import org.mirrentools.sd.models.SdTemplate; 13 | import org.mirrentools.sd.options.ScrewDriverOptions; 14 | 15 | /** 16 | * 螺丝刀核心类 17 | * 18 | * @author Mirren 19 | * 20 | */ 21 | public class ScrewDriverImpl extends ScrewDriver { 22 | // /** 项目工具 */ 23 | // private ScrewDriverProject projectUtil; 24 | /** 代码工具 */ 25 | private ScrewDriverCode codeUtil; 26 | /** 数据库工具 */ 27 | private ScrewDriverSQL sqlUtil; 28 | 29 | /** 30 | * 用过配置文件初始化ScrewDriver的默认实现 31 | * 32 | * @param options 33 | */ 34 | public ScrewDriverImpl(ScrewDriverOptions options) { 35 | SdUtil.requireNonNull(options, "The ScrewDriverOptions cannot be null , you can new ScrewDriverOptions"); 36 | this.codeUtil = new ScrewDriverCodeImpl(options); 37 | this.sqlUtil = new ScrewDriverSqlImpl(options); 38 | } 39 | 40 | // @Override 41 | // public boolean createProject() { 42 | // return projectUtil.execute(); 43 | // } 44 | 45 | @Override 46 | public boolean createCode(SdBean bean, Map templateMaps) { 47 | return codeUtil.execute(bean, templateMaps); 48 | } 49 | 50 | @Override 51 | public boolean createCode(SdClassContent classContent, Map templateMaps) { 52 | return codeUtil.execute(classContent, templateMaps); 53 | } 54 | 55 | @Override 56 | public boolean createDatabase(SdDatabase database) { 57 | return sqlUtil.createDatabase(database); 58 | } 59 | 60 | @Override 61 | public boolean createTable(SdBean bean) { 62 | return sqlUtil.createTable(bean); 63 | } 64 | 65 | @Override 66 | public SdClassContent readTable(String tableName) { 67 | return sqlUtil.readTable(tableName); 68 | } 69 | 70 | @Override 71 | public boolean updateTable(SdBean bean) { 72 | return sqlUtil.alterTable(bean); 73 | } 74 | 75 | @Override 76 | public boolean deleteTable(SdBean bean) { 77 | return sqlUtil.deleteTable(bean); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/impl/dbutil/SdDbUtilDB2Impl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.impl.dbutil; 2 | 3 | import java.sql.Connection; 4 | import java.sql.ResultSet; 5 | import java.util.logging.Logger; 6 | 7 | import org.mirrentools.sd.models.db.query.SdTableAttribute; 8 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 9 | import org.mirrentools.sd.options.SdDatabaseOptions; 10 | 11 | public class SdDbUtilDB2Impl extends SdAbstractDbUtil { 12 | private final Logger LOG = Logger.getLogger(this.getClass().getName()); 13 | 14 | /** 15 | * 初始化 16 | * 17 | * @param options 18 | */ 19 | public SdDbUtilDB2Impl(SdDatabaseOptions options) { 20 | super(options); 21 | } 22 | 23 | @Override 24 | public boolean createDatabase(SdAbstractDatabaseContent content) throws Exception { 25 | super.createDatabase(getBaseUrlConfig(), content); 26 | return true; 27 | } 28 | 29 | @Override 30 | public boolean existDatabase(String dbName) throws Exception { 31 | return existDatabase(getBaseUrlConfig(), dbName); 32 | } 33 | 34 | @Override 35 | public boolean existDatabase(SdDatabaseOptions config, String dbName) throws Exception { 36 | Connection connection = null; 37 | ResultSet rs = null; 38 | try { 39 | connection = getConnection(config); 40 | String sql = String.format("select count(*) from pg_database where datname='%s'", dbName); 41 | LOG.info("执行SQL语句:\n" + sql); 42 | ResultSet res = connection.createStatement().executeQuery(sql); 43 | res.next(); 44 | int result = res.getInt(1); 45 | try { 46 | res.close(); 47 | } catch (Exception e) { 48 | e.printStackTrace(); 49 | } 50 | return result == 1 ? true : false; 51 | } finally { 52 | if (rs != null) { 53 | rs.close(); 54 | } 55 | if (connection != null) { 56 | connection.close(); 57 | } 58 | } 59 | } 60 | 61 | @Override 62 | public SdTableAttribute getTableAttribute(String tableName) throws Exception { 63 | Connection connection = null; 64 | ResultSet rs = null; 65 | try { 66 | connection = getConnection(); 67 | SdTableAttribute result = null; 68 | String sql = String.format("select relname as name,cast(obj_description(relfilenode,'pg_class') as varchar) as remarks from pg_class where relname ='%s'", tableName); 69 | LOG.info("执行SQL语句:\n" + sql); 70 | ResultSet res = connection.createStatement().executeQuery(sql); 71 | if (res.next()) { 72 | result = new SdTableAttribute(); 73 | result.setTableName(res.getString("name")); 74 | result.setRemarks(res.getString("remarks")); 75 | try { 76 | res.close(); 77 | } catch (Exception e) { 78 | e.printStackTrace(); 79 | } 80 | } 81 | return result; 82 | } finally { 83 | if (rs != null) { 84 | rs.close(); 85 | } 86 | if (connection != null) { 87 | connection.close(); 88 | } 89 | } 90 | } 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/impl/dbutil/SdDbUtilOracleImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.impl.dbutil; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DatabaseMetaData; 5 | import java.sql.ResultSet; 6 | 7 | import org.mirrentools.sd.models.db.query.SdTableAttribute; 8 | import org.mirrentools.sd.options.SdDatabaseOptions; 9 | 10 | /** 11 | * 数据库操作相关的工具接口,Oracle的抽象实现,其他数据库或者不兼容可以重写该类 12 | * 13 | * @author Mirren 14 | * 15 | */ 16 | public class SdDbUtilOracleImpl extends SdAbstractDbUtil { 17 | 18 | // private final Logger LOG = Logger.getLogger(this.getClass().getName()); 19 | 20 | /** 21 | * 初始化 22 | * 23 | * @param options 24 | */ 25 | public SdDbUtilOracleImpl(SdDatabaseOptions options) { 26 | super(options); 27 | } 28 | 29 | @Override 30 | public boolean existDatabase(SdDatabaseOptions config, String dbName) throws Exception { 31 | return false; 32 | } 33 | 34 | @Override 35 | public SdTableAttribute getTableAttribute(String tableName) throws Exception { 36 | 37 | Connection connection = null; 38 | ResultSet rs = null; 39 | try { 40 | connection = getConnection(); 41 | DatabaseMetaData md = connection.getMetaData(); 42 | String catalog = connection.getCatalog() == null ? null : connection.getCatalog(); 43 | String[] types = { "TABLE", "VIEW" }; 44 | rs = md.getTables(catalog, null, tableName.toUpperCase(), types); 45 | SdTableAttribute result = null; 46 | if (rs.next()) { 47 | result = new SdTableAttribute(); 48 | converterTableAttribute(rs, result); 49 | } 50 | return result; 51 | } finally { 52 | if (rs != null) { 53 | rs.close(); 54 | } 55 | if (connection != null) { 56 | connection.close(); 57 | } 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/impl/dbutil/SdDbUtilSqliteImpl.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.impl.dbutil; 2 | 3 | import java.io.File; 4 | import java.sql.Connection; 5 | 6 | import org.mirrentools.sd.ScrewDriverException; 7 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 8 | import org.mirrentools.sd.options.SdDatabaseOptions; 9 | 10 | /** 11 | * 数据库操作相关的工具接口,SQLite的抽象实现,其他数据库或者不兼容可以重写该类 12 | * 13 | * @author Mirren 14 | * 15 | */ 16 | public class SdDbUtilSqliteImpl extends SdAbstractDbUtil { 17 | 18 | /** 19 | * 初始化 20 | * 21 | * @param options 22 | */ 23 | public SdDbUtilSqliteImpl(SdDatabaseOptions options) { 24 | super(options); 25 | } 26 | 27 | @Override 28 | public boolean existDatabase(String dbName) throws Exception { 29 | return existDatabase(getBaseUrlConfig(), dbName); 30 | } 31 | 32 | @Override 33 | public boolean existDatabase(SdDatabaseOptions config, String dbName) throws Exception { 34 | int index = config.getUrl().indexOf(":", config.getUrl().indexOf(":") + 1) + 1; 35 | String name = dbName.trim().endsWith(".db") ? dbName.trim() : dbName + ".db"; 36 | String url = config.getUrl().substring(index) + name; 37 | return new File(url).exists(); 38 | } 39 | 40 | @Override 41 | public boolean createDatabase(SdAbstractDatabaseContent content) throws Exception { 42 | return createDatabase(getBaseUrlConfig(), content); 43 | } 44 | 45 | @Override 46 | public boolean createDatabase(SdDatabaseOptions config, SdAbstractDatabaseContent content) throws Exception { 47 | boolean urlHasDb = config.getUrl().trim().endsWith(".db"); 48 | if (!urlHasDb) { 49 | if (!config.getUrl().trim().endsWith("/")) { 50 | config.setUrl(config.getUrl().trim() + "/"); 51 | } 52 | config.setUrl(config.getUrl().trim() + content.getDatabaseName() + ".db"); 53 | } 54 | Connection connection = null; 55 | try { 56 | connection = getConnection(config); 57 | return true; 58 | } finally { 59 | if (connection != null) { 60 | connection.close(); 61 | } 62 | } 63 | } 64 | @Override 65 | public boolean updateDatabase(SdDatabaseOptions config, SdAbstractDatabaseContent content) throws Exception { 66 | throw new ScrewDriverException("The SQLite DB in ScrewDriver does not support update,you can modify it through the SQLite client "); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/SdTemplateAttribute.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models; 2 | 3 | /** 4 | * 模板中需要使用到的属性值 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class SdTemplateAttribute { 10 | /** 属性值的key */ 11 | private String key; 12 | /** 属性值的value SdBean名字占位符{c}=驼峰命名,{p}=帕斯卡命名,{u}=下划线命名,{h}=连字符命名 */ 13 | private String value; 14 | /** 属性值的描述 SdBean名字占位符{c}=驼峰命名,{p}=帕斯卡命名,{u}=下划线命名,{h}=连字符命名 */ 15 | private String describe; 16 | /** 17 | * 初始化 18 | * 19 | * @param key 20 | * @param value 21 | * 如果值中需要用到SdBean名字可以使用占位符{c}=驼峰命名,{p}=帕斯卡命名,{u}=下划线命名,{h}=连字符命名 22 | */ 23 | public SdTemplateAttribute(String key, String value) { 24 | super(); 25 | this.key = key; 26 | this.value = value; 27 | } 28 | /** 29 | * 初始化 30 | * 31 | * @param key 32 | * @param value 33 | * 如果值中需要用到SdBean名字可以使用占位符{c}=驼峰命名,{p}=帕斯卡命名,{u}=下划线命名,{h}=连字符命名 34 | * @param describe 35 | * 如果值中需要用到SdBean名字可以使用占位符{c}=驼峰命名,{p}=帕斯卡命名,{u}=下划线命名,{h}=连字符命名 36 | */ 37 | public SdTemplateAttribute(String key, String value, String describe) { 38 | super(); 39 | this.key = key; 40 | this.value = value; 41 | this.describe = describe; 42 | } 43 | /** 44 | * 获取属性值的键 45 | * 46 | * @return 47 | */ 48 | public String getKey() { 49 | return key; 50 | } 51 | /** 52 | * 设置属性值的键 53 | * 54 | * @param key 55 | * @return 56 | */ 57 | public SdTemplateAttribute setKey(String key) { 58 | this.key = key; 59 | return this; 60 | } 61 | /** 62 | * 获取属性值 63 | * 64 | * @return 65 | */ 66 | public String getValue() { 67 | return value; 68 | } 69 | /** 70 | * 设置属性值 71 | * 72 | * @param value 73 | * 如果值中需要用到SdBean名字可以使用占位符{c}=驼峰命名,{p}=帕斯卡命名,{u}=下划线命名,{h}=连字符命名 74 | * @return 75 | */ 76 | public SdTemplateAttribute setValue(String value) { 77 | this.value = value; 78 | return this; 79 | } 80 | /** 81 | * 获取属性的描述 82 | * 83 | * @return 84 | */ 85 | public String getDescribe() { 86 | return describe; 87 | } 88 | /** 89 | * 设置属性值的描述 90 | * 91 | * @param describe 92 | * 如果值中需要用到SdBean名字可以使用占位符{c}=驼峰命名,{p}=帕斯卡命名,{u}=下划线命名,{h}=连字符命名 93 | * @return 94 | */ 95 | public SdTemplateAttribute setDescribe(String describe) { 96 | this.describe = describe; 97 | return this; 98 | } 99 | @Override 100 | public String toString() { 101 | return "SdTemplateAttribute [key=" + key + ", value=" + value + ", describe=" + describe + "]"; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/SdAbstractDatabaseContent.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.common.SdUtil; 7 | 8 | /** 9 | * 抽象数据库属性用于做为数据库的创建与修改使用,需要继承该类后重写sql方法 10 | * 11 | * @author Mirren 12 | * 13 | */ 14 | public abstract class SdAbstractDatabaseContent { 15 | /** 数据库的名字 */ 16 | private String databaseName; 17 | /** 拓展属性 */ 18 | private Map extensions; 19 | 20 | public SdAbstractDatabaseContent(String databaseName) { 21 | super(); 22 | SdUtil.requireNonEmpty(databaseName, "数据库的名称不能为空"); 23 | this.databaseName = databaseName; 24 | } 25 | 26 | /** 27 | * 新增数据库的语句 28 | * 29 | * @return 30 | */ 31 | public abstract String createSQL(); 32 | 33 | /** 34 | * 更新数据库的语句 35 | * 36 | * @return 37 | * @throws UnsupportedOperationException 38 | * 如果数据库不支持或者没有实现则抛出该异常 39 | */ 40 | public abstract String updateSQL() throws UnsupportedOperationException; 41 | 42 | /** 43 | * 删除数据库的语句 44 | * 45 | * @return 46 | */ 47 | public abstract String deleteSQL(); 48 | 49 | /** 50 | * 转换拓展字段,该方法用户转换拓展字段,如果基础的getBasicSQL方法可以用但是需要用到拓展字段时可以重写该方法,给方法的内容如果不为空会被追加到最后 51 | * 52 | * @return 53 | */ 54 | public String converterExtensions() { 55 | return null; 56 | } 57 | 58 | /** 59 | * 获取数据库的名字 60 | * 61 | * @return 62 | */ 63 | public String getDatabaseName() { 64 | return databaseName; 65 | } 66 | 67 | /** 68 | * 设置数据库的名字 69 | * 70 | * @param databaseName 71 | */ 72 | public SdAbstractDatabaseContent setDatabaseName(String databaseName) { 73 | this.databaseName = databaseName; 74 | return this; 75 | } 76 | 77 | /** 78 | * 获得拓展属性 79 | * 80 | * @return 81 | */ 82 | public Map getExtensions() { 83 | return extensions; 84 | } 85 | 86 | /** 87 | * 获得拓展属性值 88 | * 89 | * @return 90 | */ 91 | public Object getExtension(String key) { 92 | return getExtensions().get(key); 93 | } 94 | 95 | /** 96 | * 添加附加属性 97 | * 98 | * @param key 99 | * @param value 100 | * @return 101 | */ 102 | public SdAbstractDatabaseContent addExtension(String key, Object value) { 103 | if (getExtensions() == null) { 104 | setExtensions(new LinkedHashMap()); 105 | } 106 | getExtensions().put(key, value); 107 | return this; 108 | } 109 | 110 | /** 111 | * 设置附加属性 112 | * 113 | * @param extensions 114 | * @return 115 | */ 116 | public SdAbstractDatabaseContent setExtensions(Map extensions) { 117 | this.extensions = extensions; 118 | return this; 119 | } 120 | 121 | @Override 122 | public String toString() { 123 | return "AbstractDatabaseContent [databaseName=" + databaseName + ", extensions=" + extensions + "]"; 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/SdBasicColumnContent.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update; 2 | 3 | /** 4 | * 数据列属性的基本实现版实现,实际数据库如果操作相同可以继承该类,不同可以选择重写 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public abstract class SdBasicColumnContent extends SdAbstractColumnContent { 10 | 11 | @Override 12 | public String createSQL() { 13 | StringBuilder sb = new StringBuilder(); 14 | sb.append(getName()); 15 | sb.append(" " + getType()); 16 | if (getLength() != null) { 17 | sb.append("(" + getLength() + ")"); 18 | } 19 | if (isUnsigned()) { 20 | sb.append(" UNSIGNED"); 21 | } 22 | if (isNotNull()) { 23 | sb.append(" NOT NULL"); 24 | } 25 | if (getDefault() != null) { 26 | if (getDefault() instanceof Number) { 27 | sb.append(" DEFAULT " + getDefault()); 28 | } else { 29 | sb.append(" DEFAULT '" + getDefault() + "'"); 30 | } 31 | } 32 | if (converterExtensions() != null) { 33 | sb.append(" " + converterExtensions()); 34 | } 35 | return sb.toString(); 36 | } 37 | 38 | @Override 39 | public String updateSQL() { 40 | return " ADD COLUMN " + createSQL(); 41 | } 42 | 43 | @Override 44 | public String deleteSQL() { 45 | return " DROP COLUMN IF EXISTS " + getName(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/SdBasicConstraintContent.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update; 2 | 3 | /** 4 | * 约束的基本实现版实现,实际数据库如果操作相同可以继承该类,不同可以选择重写 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class SdBasicConstraintContent extends SdAbstractConstraintContent { 10 | 11 | @Override 12 | public String createSQL() { 13 | return String.format(" CONSTRAINT %s %s (%s) ", getName(), getType(), getExp()); 14 | } 15 | 16 | @Override 17 | public String updateSQL() { 18 | return " ADD " + createSQL(); 19 | } 20 | 21 | @Override 22 | public String deleteSQL() { 23 | if (getRemoveConstraint() == null) { 24 | return null; 25 | } 26 | return String.format(" DROP CONSTRAINT IF EXISTS " + getRemoveConstraint()); 27 | } 28 | 29 | @Override 30 | public String getType() { 31 | return super.getType() == null ? "" : super.getType(); 32 | } 33 | 34 | @Override 35 | public String getName() { 36 | return super.getName() == null ? "" : super.getName(); 37 | } 38 | 39 | @Override 40 | public String getExp() { 41 | return super.getExp() == null ? "" : super.getExp(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/SdBasicForeignKeyContent.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update; 2 | 3 | /** 4 | * 外键属性的基本实现版实现,实际数据库如果操作相同可以继承该类,不同可以选择重写 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class SdBasicForeignKeyContent extends SdAbstractForeignKeyContent { 10 | 11 | @Override 12 | public String createSQL() { 13 | StringBuilder sb = new StringBuilder(); 14 | if (getConstraint() != null) { 15 | sb.append(" CONSTRAINT " + getConstraint()); 16 | } 17 | sb.append(" FOREIGN KEY ("); 18 | for (int i = 0; i < getForeignKeys().size(); i++) { 19 | sb.append(getForeignKeys().get(i)); 20 | if (i != getForeignKeys().size() - 1) { 21 | sb.append(","); 22 | } 23 | } 24 | sb.append(")"); 25 | 26 | sb.append(" REFERENCES "); 27 | if (getReferencesDB() != null) { 28 | sb.append(" " + getReferencesDB() + "." + getReferencesTable()); 29 | } else { 30 | sb.append(" " + getReferencesTable()); 31 | } 32 | sb.append("("); 33 | for (int i = 0; i < getReferencesColumns().size(); i++) { 34 | sb.append(" " + getReferencesColumns().get(i)); 35 | if (i != getReferencesColumns().size() - 1) { 36 | sb.append(","); 37 | } 38 | } 39 | sb.append(")"); 40 | if (converterExtensions() != null) { 41 | sb.append(" " + converterExtensions()); 42 | } 43 | return sb.toString(); 44 | } 45 | 46 | @Override 47 | public String updateSQL() { 48 | return " ADD " + createSQL(); 49 | } 50 | 51 | @Override 52 | public String deleteSQL() { 53 | if (getRemoveConstraint() == null) { 54 | return null; 55 | } 56 | return " DROP CONSTRAINT IF EXISTS " + getRemoveConstraint(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/SdBasicIndexKeyContent.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update; 2 | 3 | /** 4 | * 索引属性的基本实现版实现,实际数据库如果操作相同可以继承该类,不同可以选择重写 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public abstract class SdBasicIndexKeyContent extends SdAbstractIndexKeyContent { 10 | 11 | @Override 12 | public String updateSQL() { 13 | return " ADD " + createSQL(); 14 | } 15 | 16 | @Override 17 | public String deleteSQL() { 18 | if (getRemoveIndexName() == null) { 19 | return null; 20 | } 21 | return " DROP CONSTRAINT IF EXISTS " + getRemoveIndexName(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/SdBasicPrimaryKeyContent.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update; 2 | 3 | /** 4 | * 主键属性的基本实现版实现,实际数据库如果操作相同可以继承该类,不同可以选择重写 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class SdBasicPrimaryKeyContent extends SdAbstractPrimaryKeyContent { 10 | 11 | @Override 12 | public String createSQL() { 13 | StringBuilder sb = new StringBuilder(); 14 | if (getName() != null) { 15 | sb.append(" CONSTRAINT " + getName() + " PRIMARY KEY ("); 16 | } else { 17 | sb.append(" PRIMARY KEY ("); 18 | } 19 | for (int i = 0; i < getColumns().size(); i++) { 20 | sb.append(getColumns().get(i)); 21 | if (i != getColumns().size() - 1) { 22 | sb.append(","); 23 | } 24 | } 25 | sb.append(")"); 26 | if (converterExtensions() != null) { 27 | sb.append(" " + converterExtensions()); 28 | } 29 | return sb.toString(); 30 | } 31 | 32 | @Override 33 | public String updateSQL() { 34 | return " ADD " + createSQL(); 35 | } 36 | 37 | @Override 38 | public String deleteSQL() { 39 | return " DROP CONSTRAINT IF EXISTS " + (getName() == null ? "" : getName()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/SdBasicSequenceContent.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update; 2 | 3 | /** 4 | * 序列的基本实现版实现,实际数据库如果操作相同可以继承该类,不同可以选择重写 5 | * 6 | * @author Mirren 7 | * 8 | */ 9 | public class SdBasicSequenceContent extends SdAbstractSequenceContent { 10 | 11 | @Override 12 | public String createSQL() { 13 | StringBuilder sb = new StringBuilder(); 14 | sb.append(" CREATE SEQUENCE IF NOT EXISTS " + getName()); 15 | if (getDataType() != null) { 16 | sb.append(" AS " + getDataType()); 17 | } 18 | if (getIncrementBy() != null) { 19 | sb.append(" INCREMENT BY " + getIncrementBy()); 20 | } 21 | if (getMinValue() != null) { 22 | sb.append(" MINVALUE " + getMinValue()); 23 | } 24 | if (getMaxValue() != null) { 25 | sb.append(" MAXVALUE " + getMaxValue()); 26 | } 27 | if (getStart() != null) { 28 | sb.append(" START WITH " + getStart()); 29 | } 30 | if (getCache() != null) { 31 | sb.append(" CACHE " + getCache()); 32 | } 33 | if (getCycle() != null && getCycle()) { 34 | sb.append(" CYCLE "); 35 | } 36 | if (getOwnedBy() != null) { 37 | sb.append(" OWNED BY " + getOwnedBy()); 38 | } 39 | return sb.toString(); 40 | } 41 | 42 | @Override 43 | public String updateSQL() { 44 | StringBuilder sb = new StringBuilder(); 45 | sb.append("ALTER SEQUENCE " + getName()); 46 | if (getDataType() != null) { 47 | sb.append(" AS " + getDataType()); 48 | } 49 | if (getIncrementBy() != null) { 50 | sb.append(" INCREMENT BY " + getIncrementBy()); 51 | } 52 | if (getMinValue() != null) { 53 | sb.append(" MINVALUE " + getMinValue()); 54 | } 55 | if (getMaxValue() != null) { 56 | sb.append(" MAXVALUE " + getMaxValue()); 57 | } 58 | if (getStart() != null) { 59 | sb.append(" START WITH " + getStart()); 60 | } 61 | if (getRestart() != null) { 62 | sb.append(" RESTART WITH " + getRestart()); 63 | } 64 | if (getCache() != null) { 65 | sb.append(" CACHE " + getCache()); 66 | } 67 | if (getCycle() != null && getCycle()) { 68 | sb.append(" CYCLE "); 69 | } 70 | if (getOwnedBy() != null) { 71 | sb.append(" OWNED BY " + getOwnedBy()); 72 | } 73 | return sb.toString(); 74 | } 75 | 76 | @Override 77 | public String deleteSQL() { 78 | return String.format("DROP SEQUENCE IF EXISTS %s", getName()); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/db2/SdColumnContentByDB2.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.db2; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicColumnContent; 4 | /** 5 | * 数据列属性的DB2实现 6 | * 7 | * @author likk 8 | * 9 | */ 10 | 11 | public class SdColumnContentByDB2 extends SdBasicColumnContent{ 12 | /** 字符排序 */ 13 | private String collate; 14 | 15 | @Override 16 | public String createSQL() { 17 | StringBuilder sb = new StringBuilder(); 18 | sb.append("" + getName() + ""); 19 | sb.append(" " + getType()); 20 | if (getLength() != null) { 21 | sb.append("(" + getLength() + ")"); 22 | } 23 | if (isNotNull()) { 24 | sb.append(" NOT NULL"); 25 | } 26 | if (isPrimary()) { 27 | sb.append(" PRIMARY KEY"); 28 | } 29 | if (isAutoIncrement()) { 30 | sb.append(" GENERATED ALWAYS AS IDENTITY "); 31 | } 32 | if (getDefault() != null) { 33 | if (getDefault() instanceof Number) { 34 | sb.append(" DEFAULT " + getDefault()); 35 | } else { 36 | sb.append(" DEFAULT '" + getDefault() + "'"); 37 | } 38 | } 39 | 40 | if (converterExtensions() != null) { 41 | sb.append(" " + converterExtensions()); 42 | } 43 | return sb.toString(); 44 | } 45 | 46 | public String getCollate() { 47 | return collate; 48 | } 49 | public SdColumnContentByDB2 setCollate(String collate) { 50 | this.collate = collate; 51 | return this; 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/db2/SdConstraintContentByDB2.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.db2; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicConstraintContent; 4 | 5 | public class SdConstraintContentByDB2 extends SdBasicConstraintContent { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/db2/SdForeignKeyContentByDB2.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.db2; 2 | 3 | import org.mirrentools.sd.common.SdUtil; 4 | import org.mirrentools.sd.models.db.update.SdBasicForeignKeyContent; 5 | 6 | public class SdForeignKeyContentByDB2 extends SdBasicForeignKeyContent { 7 | @Override 8 | public String createSQL() { 9 | return "ALTER TABLE " + getSchema() + "." + getTable() + " ADD CONSTRAINT " + getConstraint() + " FOREIGN KEY(" + SdUtil.join(getForeignKeys(), ",") + ") REFERENCES " + getSchema() + "." 10 | + getReferencesTable() + "(" + SdUtil.join(getReferencesColumns(), ",") + ")"; 11 | } 12 | 13 | @Override 14 | public String updateSQL() { 15 | return deleteSQL() == null ? " ADD " + createSQL() : deleteSQL() + ", ADD " + createSQL(); 16 | } 17 | 18 | @Override 19 | public String deleteSQL() { 20 | if (getRemoveConstraint() == null) { 21 | return null; 22 | } 23 | return " DROP CONSTRAINT " + getRemoveConstraint(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/db2/SdIndexKeyContentByDB2.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.db2; 2 | 3 | import org.mirrentools.sd.common.SdUtil; 4 | import org.mirrentools.sd.models.db.update.SdBasicIndexKeyContent; 5 | 6 | public class SdIndexKeyContentByDB2 extends SdBasicIndexKeyContent{ 7 | @Override 8 | public String createSQL() { 9 | return "CREATE INDEX "+ getSchema() + "."+getName() + " ON " + getSchema() + "." + getTable()+"("+ 10 | SdUtil.join(getColumns(),",") 11 | +")"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/db2/SdPrimaryKeyContentByDB2.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.db2; 2 | 3 | import org.mirrentools.sd.common.SdUtil; 4 | import org.mirrentools.sd.models.db.update.SdAbstractPrimaryKeyContent; 5 | 6 | public class SdPrimaryKeyContentByDB2 extends SdAbstractPrimaryKeyContent { 7 | @Override 8 | public String createSQL() { 9 | return "ALTER TABLE "+getSchema()+"."+getTable() +" ADD constraint "+getName()+" primary key("+ SdUtil.join(getColumns(),",")+")"; 10 | } 11 | @Override 12 | public String updateSQL() { 13 | return deleteSQL() + " , " + createSQL(); 14 | } 15 | @Override 16 | public String deleteSQL() { 17 | return " DROP PRIMARY KEY"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/db2/SdSequenceContentByDB2.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.db2; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicSequenceContent; 4 | 5 | /** 6 | * 序列属性的DB2版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdSequenceContentByDB2 extends SdBasicSequenceContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/mysql/SdColumnContentByMySQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.mysql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicColumnContent; 4 | 5 | /** 6 | * 数据列属性的MySQL实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdColumnContentByMySQL extends SdBasicColumnContent { 12 | /** 字符排序 */ 13 | private String collate; 14 | 15 | @Override 16 | public String createSQL() { 17 | StringBuilder sb = new StringBuilder(); 18 | sb.append(getName()); 19 | sb.append(" " + getType()); 20 | if (getLength() != null) { 21 | sb.append("(" + getLength() + ")"); 22 | } 23 | if (getCollate() != null) { 24 | sb.append(" COLLATE " + getCollate()); 25 | } 26 | if (isUnsigned()) { 27 | sb.append(" UNSIGNED"); 28 | } 29 | if (isNotNull()) { 30 | sb.append(" NOT NULL"); 31 | } 32 | if (isAutoIncrement()) { 33 | sb.append(" AUTO_INCREMENT"); 34 | } 35 | if (getDefault() != null) { 36 | if (getDefault() instanceof Number) { 37 | sb.append(" DEFAULT " + getDefault()); 38 | } else { 39 | sb.append(" DEFAULT '" + getDefault() + "'"); 40 | } 41 | } 42 | if (getRemark() != null) { 43 | sb.append(" COMMENT '" + getRemark() + "'"); 44 | } 45 | if (converterExtensions() != null) { 46 | sb.append(" " + converterExtensions()); 47 | } 48 | return sb.toString(); 49 | } 50 | 51 | public String getCollate() { 52 | return collate; 53 | } 54 | public SdColumnContentByMySQL setCollate(String collate) { 55 | this.collate = collate; 56 | return this; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/mysql/SdConstraintContentByMySQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.mysql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdAbstractConstraintContent; 4 | 5 | /** 6 | * 外键属性的MySQL版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdConstraintContentByMySQL extends SdAbstractConstraintContent { 12 | 13 | @Override 14 | public String createSQL() { 15 | return String.format(" CONSTRAINT %s %s (%s) ", getName(), getType(), getExp()); 16 | } 17 | 18 | @Override 19 | public String updateSQL() { 20 | return 21 | deleteSQL() == null 22 | ? " ADD " + createSQL() 23 | : deleteSQL() + ", ADD " + createSQL() ; 24 | } 25 | 26 | @Override 27 | public String deleteSQL() { 28 | if (getRemoveConstraint() == null) { 29 | return null; 30 | } 31 | return String.format(" DROP %s %s", getType(), getName()); 32 | } 33 | 34 | @Override 35 | public String getType() { 36 | return super.getType() == null ? "" : super.getType(); 37 | } 38 | 39 | @Override 40 | public String getName() { 41 | return super.getName() == null ? "" : super.getName(); 42 | } 43 | 44 | @Override 45 | public String getExp() { 46 | return super.getExp() == null ? "" : super.getExp(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/mysql/SdDatabaseContentByMySQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.mysql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 4 | 5 | /** 6 | * MySQL数据库的数据库属性 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdDatabaseContentByMySQL extends SdAbstractDatabaseContent { 12 | /** 字符集 */ 13 | private String characterSet; 14 | /** 数据库排序规则 */ 15 | private String collate; 16 | 17 | /** 18 | * 初始化一个数据库SQL类 19 | * 20 | * @param databaseName 21 | * 数据库的名字 22 | */ 23 | public SdDatabaseContentByMySQL(String databaseName) { 24 | super(databaseName); 25 | } 26 | 27 | /** 28 | * 初始化一个数据库SQL类 29 | * 30 | * @param databaseName 31 | * 数据库的名字 32 | * @param characterSet 33 | * 数据的字符集 34 | * @param collate 35 | * 数据库的排序规则 36 | */ 37 | public SdDatabaseContentByMySQL(String databaseName, String characterSet, String collate) { 38 | super(databaseName); 39 | this.characterSet = characterSet; 40 | this.collate = collate; 41 | } 42 | 43 | @Override 44 | public String createSQL() { 45 | if (getDatabaseName() == null) { 46 | throw new NullPointerException("数据库的名字不能为空"); 47 | } 48 | StringBuilder sb = new StringBuilder("CREATE DATABASE "); 49 | sb.append(getDatabaseName()); 50 | if (getCharacterSet() != null) { 51 | sb.append(" DEFAULT CHARACTER SET "); 52 | sb.append(getCharacterSet()); 53 | } 54 | if (getCollate() != null) { 55 | sb.append(" COLLATE "); 56 | sb.append(getCollate()); 57 | } 58 | sb.append(";"); 59 | return sb.toString(); 60 | } 61 | 62 | @Override 63 | public String updateSQL() throws UnsupportedOperationException { 64 | throw new UnsupportedOperationException("该方法未实现"); 65 | } 66 | 67 | @Override 68 | public String deleteSQL() { 69 | return "DROP DATABASE " + getDatabaseName(); 70 | } 71 | 72 | /** 73 | * 获取字符集 74 | * 75 | * @return 76 | */ 77 | public String getCharacterSet() { 78 | return characterSet; 79 | } 80 | 81 | /** 82 | * 设置字符集 83 | * 84 | * @param characterSet 85 | */ 86 | public SdDatabaseContentByMySQL setCharacterSet(String characterSet) { 87 | this.characterSet = characterSet; 88 | return this; 89 | } 90 | 91 | /** 92 | * 获取字符集核对 93 | * 94 | * @return 95 | */ 96 | public String getCollate() { 97 | return collate; 98 | } 99 | 100 | /** 101 | * 设置字符集核对 102 | * 103 | * @param collate 104 | */ 105 | public SdDatabaseContentByMySQL setCollate(String collate) { 106 | this.collate = collate; 107 | return this; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/mysql/SdForeignKeyContentByMySQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.mysql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdAbstractForeignKeyContent; 4 | 5 | /** 6 | * 外键属性的MySQL版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdForeignKeyContentByMySQL extends SdAbstractForeignKeyContent { 12 | 13 | @Override 14 | public String createSQL() { 15 | StringBuilder sb = new StringBuilder(); 16 | if (getConstraint() != null) { 17 | sb.append(" CONSTRAINT " + getConstraint()); 18 | } 19 | sb.append(" FOREIGN KEY ("); 20 | for (int i = 0; i < getForeignKeys().size(); i++) { 21 | sb.append(getForeignKeys().get(i)); 22 | if (i != getForeignKeys().size() - 1) { 23 | sb.append(","); 24 | } 25 | } 26 | sb.append(")"); 27 | 28 | sb.append(" REFERENCES "); 29 | if (getReferencesDB() != null) { 30 | sb.append(getReferencesDB() + "." + getReferencesTable()); 31 | } else { 32 | sb.append(getReferencesTable()); 33 | } 34 | sb.append("("); 35 | for (int i = 0; i < getReferencesColumns().size(); i++) { 36 | sb.append(getReferencesColumns().get(i)); 37 | if (i != getReferencesColumns().size() - 1) { 38 | sb.append(","); 39 | } 40 | } 41 | sb.append(")"); 42 | if (converterExtensions() != null) { 43 | sb.append(" " + converterExtensions()); 44 | } 45 | return sb.toString(); 46 | } 47 | 48 | @Override 49 | public String updateSQL() { 50 | return deleteSQL() == null ? " ADD " + createSQL() : deleteSQL() + ", ADD " + createSQL(); 51 | } 52 | 53 | @Override 54 | public String deleteSQL() { 55 | if (getRemoveConstraint() == null) { 56 | return null; 57 | } 58 | return " DROP FOREIGN KEY " + getRemoveConstraint(); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/mysql/SdIndexKeyContentByMySQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.mysql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdAbstractIndexKeyContent; 4 | 5 | /** 6 | * 索引属性MySQL版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdIndexKeyContentByMySQL extends SdAbstractIndexKeyContent { 12 | 13 | @Override 14 | public String createSQL() { 15 | StringBuilder sb = new StringBuilder(); 16 | sb.append(" " + getType()); 17 | sb.append(" " + getName()); 18 | sb.append(" ("); 19 | for (int i = 0; i < getColumns().size(); i++) { 20 | sb.append(" " + getColumns().get(i)); 21 | if (i != getColumns().size() - 1) { 22 | sb.append(","); 23 | } 24 | } 25 | sb.append(")"); 26 | if (converterExtensions() != null) { 27 | sb.append(" " + converterExtensions()); 28 | } 29 | return sb.toString(); 30 | } 31 | 32 | @Override 33 | public String updateSQL() { 34 | return deleteSQL() == null ? " ADD " + createSQL() : deleteSQL() + " , ADD " + createSQL(); 35 | } 36 | 37 | @Override 38 | public String deleteSQL() { 39 | if (getRemoveIndexName() == null) { 40 | return null; 41 | } 42 | return " DROP INDEX " + getRemoveIndexName(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/mysql/SdPrimaryKeyContentByMySQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.mysql; 2 | 3 | import org.mirrentools.sd.common.SdUtil; 4 | import org.mirrentools.sd.models.db.update.SdBasicPrimaryKeyContent; 5 | 6 | /** 7 | * 主键属性的MySQL版实现 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class SdPrimaryKeyContentByMySQL extends SdBasicPrimaryKeyContent { 13 | 14 | @Override 15 | public String createSQL() { 16 | StringBuilder sb = new StringBuilder(); 17 | sb.append(" PRIMARY KEY ("); 18 | sb.append(SdUtil.join(getColumns(), ",")); 19 | sb.append(")"); 20 | if (converterExtensions() != null) { 21 | sb.append(" " + converterExtensions()); 22 | } 23 | return sb.toString(); 24 | } 25 | 26 | @Override 27 | public String updateSQL() { 28 | return deleteSQL() + " , ADD " + createSQL(); 29 | } 30 | 31 | @Override 32 | public String deleteSQL() { 33 | return " DROP PRIMARY KEY " + (getName() == null ? "" : getName()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/oracle/SdColumnContentByOracle.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.oracle; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicColumnContent; 4 | /** 5 | * 数据列属性的Oracle实现 6 | * 7 | * @author likk 8 | * 9 | */ 10 | 11 | public class SdColumnContentByOracle extends SdBasicColumnContent{ 12 | /** 字符排序 */ 13 | private String collate; 14 | 15 | @Override 16 | public String createSQL() { 17 | StringBuilder sb = new StringBuilder(); 18 | sb.append("" + getName() + ""); 19 | sb.append(" " + getType()); 20 | if (getLength() != null) { 21 | sb.append("(" + getLength() + ")"); 22 | } 23 | if (isNotNull()) { 24 | sb.append(" NOT NULL"); 25 | } 26 | if (isPrimary()) { 27 | sb.append(" PRIMARY KEY"); 28 | } 29 | if (isAutoIncrement()) { 30 | sb.append(" GENERATED ALWAYS AS IDENTITY "); 31 | } 32 | if (getDefault() != null) { 33 | if (getDefault() instanceof Number) { 34 | sb.append(" DEFAULT " + getDefault()); 35 | } else { 36 | sb.append(" DEFAULT '" + getDefault() + "'"); 37 | } 38 | } 39 | 40 | if (converterExtensions() != null) { 41 | sb.append(" " + converterExtensions()); 42 | } 43 | return sb.toString(); 44 | } 45 | 46 | public String getCollate() { 47 | return collate; 48 | } 49 | public SdColumnContentByOracle setCollate(String collate) { 50 | this.collate = collate; 51 | return this; 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/oracle/SdConstraintContentByOracle.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.oracle; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicConstraintContent; 4 | 5 | public class SdConstraintContentByOracle extends SdBasicConstraintContent { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/oracle/SdForeignKeyContentByOracle.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.oracle; 2 | 3 | import org.mirrentools.sd.common.SdUtil; 4 | import org.mirrentools.sd.models.db.update.SdBasicForeignKeyContent; 5 | 6 | public class SdForeignKeyContentByOracle extends SdBasicForeignKeyContent { 7 | @Override 8 | public String createSQL() { 9 | return "ALTER TABLE "+getSchema()+"."+getTable() +" ADD CONSTRAINT "+getConstraint() 10 | +" FOREIGN KEY("+ SdUtil.join(getForeignKeys(),",")+") REFERENCES " 11 | +getSchema()+"."+getReferencesTable()+"("+SdUtil.join(getReferencesColumns(),",")+")"; 12 | } 13 | 14 | @Override 15 | public String updateSQL() { 16 | return deleteSQL() == null 17 | ? " ADD " + createSQL() 18 | : deleteSQL() + ", ADD " + createSQL(); 19 | } 20 | 21 | @Override 22 | public String deleteSQL() { 23 | if (getRemoveConstraint() == null) { 24 | return null; 25 | } 26 | return " DROP CONSTRAINT " + getRemoveConstraint(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/oracle/SdIndexKeyContentByOracle.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.oracle; 2 | 3 | import org.mirrentools.sd.common.SdUtil; 4 | import org.mirrentools.sd.models.db.update.SdBasicIndexKeyContent; 5 | 6 | public class SdIndexKeyContentByOracle extends SdBasicIndexKeyContent { 7 | @Override 8 | public String createSQL() { 9 | return "CREATE INDEX " + getSchema() + "." + getName() + " ON " + getSchema() + "." + getTable() + "(" + SdUtil.join(getColumns(), ",") + ")"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/oracle/SdPrimaryKeyContentByOracle.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.oracle; 2 | 3 | import org.mirrentools.sd.common.SdUtil; 4 | import org.mirrentools.sd.models.db.update.SdAbstractPrimaryKeyContent; 5 | 6 | public class SdPrimaryKeyContentByOracle extends SdAbstractPrimaryKeyContent { 7 | @Override 8 | public String createSQL() { 9 | return "ALTER TABLE "+getSchema()+"."+getTable() +" ADD constraint "+getName()+" primary key("+ SdUtil.join(getColumns(),",")+")"; 10 | } 11 | @Override 12 | public String updateSQL() { 13 | return deleteSQL() + " , " + createSQL(); 14 | } 15 | @Override 16 | public String deleteSQL() { 17 | return " DROP PRIMARY KEY"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/oracle/SdSequenceContentByOracle.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.oracle; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicSequenceContent; 4 | 5 | /** 6 | * 序列属性的Oracle版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdSequenceContentByOracle extends SdBasicSequenceContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/postgresql/SdColumnContentByPostgreSQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.postgresql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicColumnContent; 4 | 5 | /** 6 | * 数据列属性的PostgreSQL实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdColumnContentByPostgreSQL extends SdBasicColumnContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/postgresql/SdConstraintContentByPostgreSQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.postgresql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicConstraintContent; 4 | 5 | /** 6 | * 外键属性的PostgreSQL版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdConstraintContentByPostgreSQL extends SdBasicConstraintContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/postgresql/SdForeignKeyContentByPostgreSQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.postgresql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicForeignKeyContent; 4 | 5 | /** 6 | * 外键属性的PostgreSQL版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdForeignKeyContentByPostgreSQL extends SdBasicForeignKeyContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/postgresql/SdIndexKeyContentByPostgreSQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.postgresql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicIndexKeyContent; 4 | 5 | /** 6 | * 索引属性PostgreSQL版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdIndexKeyContentByPostgreSQL extends SdBasicIndexKeyContent { 12 | 13 | @Override 14 | public String createSQL() { 15 | //该方法已经在TableContent中实现 16 | return null; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/postgresql/SdPrimaryKeyContentByPostgreSQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.postgresql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicPrimaryKeyContent; 4 | 5 | /** 6 | * 主键属性的PostgreSQL版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdPrimaryKeyContentByPostgreSQL extends SdBasicPrimaryKeyContent { 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/postgresql/SdSequenceContentByPostgreSQL.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.postgresql; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicSequenceContent; 4 | 5 | /** 6 | * 序列属性的PostgreSQL版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdSequenceContentByPostgreSQL extends SdBasicSequenceContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlite/SdColumnContentBySqlite.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlite; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicColumnContent; 4 | 5 | /** 6 | * 数据列属性的SQLite实现,当列采用自增时生成列的SQL语句在TableContent中完成,对应TableConten的getColumnSQL方法 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdColumnContentBySqlite extends SdBasicColumnContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlite/SdConstraintContentBySqlite.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlite; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicConstraintContent; 4 | 5 | /** 6 | * 外键属性的SQLite版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdConstraintContentBySqlite extends SdBasicConstraintContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlite/SdDatabaseContentBySqlite.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlite; 2 | 3 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 4 | 5 | /** 6 | * SQLite数据库的数据库属性 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdDatabaseContentBySqlite extends SdAbstractDatabaseContent { 12 | 13 | public SdDatabaseContentBySqlite(String databaseName) { 14 | super(databaseName); 15 | } 16 | 17 | @Override 18 | public String createSQL() { 19 | return ""; 20 | } 21 | 22 | @Override 23 | public String updateSQL() throws UnsupportedOperationException { 24 | return ""; 25 | } 26 | 27 | @Override 28 | public String deleteSQL() { 29 | return ""; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlite/SdForeignKeyContentBySqlite.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlite; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicForeignKeyContent; 4 | 5 | /** 6 | * 外键属性的SQLite版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdForeignKeyContentBySqlite extends SdBasicForeignKeyContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlite/SdIndexKeyContentBySqlite.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlite; 2 | 3 | import org.mirrentools.sd.common.SdUtil; 4 | import org.mirrentools.sd.models.db.update.SdBasicIndexKeyContent; 5 | 6 | /** 7 | * 索引属性SQLite版实现 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class SdIndexKeyContentBySqlite extends SdBasicIndexKeyContent { 13 | 14 | @Override 15 | public String createSQL() { 16 | StringBuilder result = new StringBuilder(); 17 | result.append(" CREATE "); 18 | if (isUnique()) { 19 | result.append(" UNIQUE "); 20 | } 21 | result.append(" INDEX "); 22 | result.append(" IF NOT EXISTS "); 23 | result.append(getName()); 24 | result.append(" ON "); 25 | result.append(getTable()); 26 | result.append(" ( "); 27 | result.append(SdUtil.join(getColumns(), ",")); 28 | result.append(" ); "); 29 | return result.toString(); 30 | } 31 | 32 | @Override 33 | public String deleteSQL() { 34 | return " DROP INDEX " + getRemoveIndexName(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlite/SdPrimaryKeyContentBySqlite.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlite; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicPrimaryKeyContent; 4 | 5 | /** 6 | * 主键属性的SQLite版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdPrimaryKeyContentBySqlite extends SdBasicPrimaryKeyContent { 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlserver/SdColumnContentBySqlServer.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlserver; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicColumnContent; 4 | 5 | /** 6 | * 数据列属性的SQL Server实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdColumnContentBySqlServer extends SdBasicColumnContent { 12 | @Override 13 | public String createSQL() { 14 | StringBuilder sb = new StringBuilder(); 15 | sb.append(getName()); 16 | sb.append(" " + getType()); 17 | if (getLength() != null) { 18 | sb.append("(" + getLength() + ")"); 19 | } 20 | if (isIdentity()) { 21 | sb.append(String.format(" IDENTITY(%d,%d)", (getIdentitySeed() == null ? 1 : getIdentitySeed()), (getIdentityIncrement() == null ? 1 : getIdentityIncrement()))); 22 | } 23 | if (isNotNull()) { 24 | sb.append(" NOT NULL"); 25 | } 26 | if (getDefault() != null) { 27 | if (getDefault() instanceof Number) { 28 | sb.append(" DEFAULT " + getDefault()); 29 | } else { 30 | sb.append(" DEFAULT '" + getDefault() + "'"); 31 | } 32 | } 33 | if (converterExtensions() != null) { 34 | sb.append(" " + converterExtensions()); 35 | } 36 | return sb.toString(); 37 | } 38 | 39 | @Override 40 | public String updateSQL() { 41 | return " ADD " + createSQL(); 42 | } 43 | 44 | @Override 45 | public String deleteSQL() { 46 | return " DROP COLUMN " + getName(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlserver/SdConstraintContentBySqlServer.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlserver; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicConstraintContent; 4 | 5 | /** 6 | * 外键属性的SQL Server版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdConstraintContentBySqlServer extends SdBasicConstraintContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlserver/SdForeignKeyContentBySqlServer.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlserver; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicForeignKeyContent; 4 | 5 | /** 6 | * 外键属性的SQL Server版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdForeignKeyContentBySqlServer extends SdBasicForeignKeyContent { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlserver/SdIndexKeyContentBySqlServer.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlserver; 2 | 3 | import org.mirrentools.sd.common.SdUtil; 4 | import org.mirrentools.sd.models.db.update.SdBasicIndexKeyContent; 5 | 6 | /** 7 | * 索引属性SQL Server版实现 8 | * 9 | * @author Mirren 10 | * 11 | */ 12 | public class SdIndexKeyContentBySqlServer extends SdBasicIndexKeyContent { 13 | 14 | @Override 15 | public String createSQL() { 16 | StringBuilder result = new StringBuilder(); 17 | result.append(" CREATE "); 18 | if (isUnique()) { 19 | result.append(" UNIQUE "); 20 | } 21 | if (getType() != null) { 22 | result.append(getType()); 23 | } 24 | result.append(" INDEX "); 25 | result.append(getName()); 26 | result.append(" ON "); 27 | result.append(getTable()); 28 | result.append(" ( "); 29 | result.append(SdUtil.join(getColumns(), ",")); 30 | result.append(" );"); 31 | return result.toString(); 32 | } 33 | 34 | @Override 35 | public String deleteSQL() { 36 | return " DROP INDEX " + getRemoveIndexName(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlserver/SdPrimaryKeyContentBySqlServer.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlserver; 2 | 3 | import org.mirrentools.sd.models.db.update.SdBasicPrimaryKeyContent; 4 | 5 | /** 6 | * 主键属性的SQL Server版实现 7 | * 8 | * @author Mirren 9 | * 10 | */ 11 | public class SdPrimaryKeyContentBySqlServer extends SdBasicPrimaryKeyContent { 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/models/db/update/impl/sqlserver/SdTableContentBySqlServer.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.models.db.update.impl.sqlserver; 2 | 3 | import java.util.List; 4 | 5 | import org.mirrentools.sd.common.SdUtil; 6 | import org.mirrentools.sd.models.db.update.SdAbstractColumnContent; 7 | import org.mirrentools.sd.models.db.update.SdBasicTableContent; 8 | 9 | /** 10 | * 数据库表属性创建或者修改SQL语句的SQL Server实现 11 | * 12 | * @author Mirren 13 | */ 14 | public class SdTableContentBySqlServer extends SdBasicTableContent { 15 | 16 | @Override 17 | public List createSQL() { 18 | List result = super.createSQL(); 19 | // 添加表说明 20 | if (!SdUtil.isNullOrEmpty(getRemark())) { 21 | result.add(getTableRemarks()); 22 | } 23 | // 添加列说明 24 | for (int i = 0; i < getColums().size(); i++) { 25 | SdAbstractColumnContent col = getColums().get(i); 26 | if (!SdUtil.isNullOrEmpty(col.getRemark())) { 27 | result.add(getColomnRemarks(col.getName(), col.getRemark())); 28 | } 29 | } 30 | return result; 31 | } 32 | 33 | @Override 34 | public String deleteSQL() { 35 | return " DROP TABLE " + getTableName() + ";"; 36 | } 37 | 38 | /** 39 | * 获取表的注释 40 | * 41 | * @return 42 | */ 43 | private String getTableRemarks() { 44 | StringBuilder result = new StringBuilder(); 45 | result.append(" EXEC sp_addextendedproperty "); 46 | result.append(String.format("@name = N'MS_Description', @value = '%s',", getRemark())); 47 | result.append(String.format("@level0type = N'Schema', @level0name = '%s',", (getSchema() == null ? "dbo" : getSchema()))); 48 | result.append(String.format("@level1type = N'Table', @level1name = '%s';", getTableName())); 49 | return result.toString(); 50 | } 51 | 52 | /** 53 | * 获取列注释 54 | * 55 | * @param colName 56 | * 列名 57 | * @param remark 58 | * 注释 59 | * @return 60 | */ 61 | private String getColomnRemarks(String colName, String remark) { 62 | StringBuilder result = new StringBuilder(); 63 | result.append(" EXEC sp_addextendedproperty "); 64 | result.append(String.format("@name = N'MS_Description', @value = '%s',", remark)); 65 | result.append(String.format("@level0type = N'Schema', @level0name = '%s',", (getSchema() == null ? "dbo" : getSchema()))); 66 | result.append(String.format("@level1type = N'Table', @level1name = '%s',", getTableName())); 67 | result.append(String.format("@level2type = N'Column', @level2name = '%s';", colName)); 68 | return result.toString(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/options/def/ScrewDriverDB2Options.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.options.def; 2 | 3 | import org.mirrentools.sd.converter.impl.SdTemplateContentConverterDefaultImpl; 4 | import org.mirrentools.sd.converter.impl.db2.SdClassConverterDB2Impl; 5 | import org.mirrentools.sd.converter.impl.db2.SdTableContentConverterDB2Impl; 6 | import org.mirrentools.sd.converter.impl.db2.SdTableToClassConverterDB2Impl; 7 | import org.mirrentools.sd.impl.ScrewDriverTemplateFreeMarkerImpl; 8 | import org.mirrentools.sd.impl.dbutil.SdDbUtilDB2Impl; 9 | import org.mirrentools.sd.options.ScrewDriverOptions; 10 | import org.mirrentools.sd.options.SdDatabaseOptions; 11 | 12 | /** 13 | * DB2版配置 14 | * 15 | * @author Mirren 16 | * 17 | */ 18 | public class ScrewDriverDB2Options extends ScrewDriverOptions { 19 | /** 20 | * 初始化一个DB2版的ScrewDriver配置,用于仅生成SQL 21 | * 22 | * @param databaseOptions 数据库连接信息 23 | */ 24 | public ScrewDriverDB2Options(SdDatabaseOptions databaseOptions) { 25 | init(databaseOptions); 26 | } 27 | 28 | /** 29 | * 初始化 30 | * 31 | * @param databaseOptions 数据库连接信息 32 | */ 33 | private void init(SdDatabaseOptions databaseOptions) { 34 | super.setDatabaseOptions(databaseOptions); 35 | super.setTemplateContentConverter(new SdTemplateContentConverterDefaultImpl()); 36 | super.setTemplateEngine(new ScrewDriverTemplateFreeMarkerImpl()); 37 | 38 | super.setBeanConverter(new SdClassConverterDB2Impl()); 39 | super.setClassConverter(new SdTableToClassConverterDB2Impl()); 40 | 41 | super.setTableConverter(new SdTableContentConverterDB2Impl()); 42 | super.setDbUtil(new SdDbUtilDB2Impl(databaseOptions)); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/options/def/ScrewDriverMySqlOptions.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.options.def; 2 | 3 | import org.mirrentools.sd.converter.impl.SdTemplateContentConverterDefaultImpl; 4 | import org.mirrentools.sd.converter.impl.mysql.SdClassConverterMySqlImpl; 5 | import org.mirrentools.sd.converter.impl.mysql.SdDatabaseConverterMySqlImpl; 6 | import org.mirrentools.sd.converter.impl.mysql.SdTableContentConverterMySqlImpl; 7 | import org.mirrentools.sd.converter.impl.mysql.SdTableToClassConverterMySqlImpl; 8 | import org.mirrentools.sd.impl.ScrewDriverTemplateFreeMarkerImpl; 9 | import org.mirrentools.sd.impl.dbutil.SdDbUtilMySqlImpl; 10 | import org.mirrentools.sd.options.ScrewDriverOptions; 11 | import org.mirrentools.sd.options.SdDatabaseOptions; 12 | 13 | /** 14 | * MySQL版配置 15 | * 16 | * @author Mirren 17 | * 18 | */ 19 | public class ScrewDriverMySqlOptions extends ScrewDriverOptions { 20 | /** 21 | * 初始化一个MySQL版的ScrewDriver配置,用于仅生成SQL 22 | * 23 | * @param databaseOptions 数据库连接信息 24 | */ 25 | public ScrewDriverMySqlOptions(SdDatabaseOptions databaseOptions) { 26 | init(databaseOptions); 27 | 28 | } 29 | 30 | /** 31 | * @param databaseOptions 数据库连接信息 32 | */ 33 | private void init(SdDatabaseOptions databaseOptions) { 34 | super.setDatabaseOptions(databaseOptions); 35 | super.setTemplateContentConverter(new SdTemplateContentConverterDefaultImpl()); 36 | super.setTemplateEngine(new ScrewDriverTemplateFreeMarkerImpl()); 37 | 38 | super.setBeanConverter(new SdClassConverterMySqlImpl()); 39 | 40 | super.setTableConverter(new SdTableContentConverterMySqlImpl()); 41 | super.setClassConverter(new SdTableToClassConverterMySqlImpl()); 42 | super.setDatabaseConverter(new SdDatabaseConverterMySqlImpl()); 43 | 44 | super.setDbUtil(new SdDbUtilMySqlImpl(databaseOptions)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/options/def/ScrewDriverOracleOptions.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.options.def; 2 | 3 | import org.mirrentools.sd.converter.impl.SdTemplateContentConverterDefaultImpl; 4 | import org.mirrentools.sd.converter.impl.oracle.SdClassConverterOracleImpl; 5 | import org.mirrentools.sd.converter.impl.oracle.SdTableContentConverterOracleImpl; 6 | import org.mirrentools.sd.converter.impl.oracle.SdTableToClassConverterOracleImpl; 7 | import org.mirrentools.sd.impl.ScrewDriverTemplateFreeMarkerImpl; 8 | import org.mirrentools.sd.impl.dbutil.SdDbUtilOracleImpl; 9 | import org.mirrentools.sd.options.ScrewDriverOptions; 10 | import org.mirrentools.sd.options.SdDatabaseOptions; 11 | 12 | /** 13 | * Oracle版配置 14 | * 15 | * @author Mirren 16 | * 17 | */ 18 | public class ScrewDriverOracleOptions extends ScrewDriverOptions { 19 | /** 20 | * 初始化一个Oracle版的ScrewDriver配置,用于仅生成SQL 21 | * 22 | * 23 | * @param databaseOptions 数据库连接信息 24 | */ 25 | public ScrewDriverOracleOptions(SdDatabaseOptions databaseOptions) { 26 | init(databaseOptions); 27 | } 28 | 29 | /** 30 | * 初始化 31 | * 32 | * @param databaseOptions 数据库连接信息 33 | */ 34 | private void init(SdDatabaseOptions databaseOptions) { 35 | super.setDatabaseOptions(databaseOptions); 36 | super.setTemplateContentConverter(new SdTemplateContentConverterDefaultImpl()); 37 | super.setTemplateEngine(new ScrewDriverTemplateFreeMarkerImpl()); 38 | 39 | super.setBeanConverter(new SdClassConverterOracleImpl()); 40 | super.setClassConverter(new SdTableToClassConverterOracleImpl()); 41 | super.setTableConverter(new SdTableContentConverterOracleImpl()); 42 | super.setDbUtil(new SdDbUtilOracleImpl(databaseOptions)); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/options/def/ScrewDriverPostgreSqlOptions.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.options.def; 2 | 3 | import org.mirrentools.sd.converter.impl.SdTemplateContentConverterDefaultImpl; 4 | import org.mirrentools.sd.converter.impl.postgresql.SdClassConverterPostgreSqlImpl; 5 | import org.mirrentools.sd.converter.impl.postgresql.SdDatabaseConverterPostgreSqlImpl; 6 | import org.mirrentools.sd.converter.impl.postgresql.SdTableContentConverterPostgreSqlImpl; 7 | import org.mirrentools.sd.converter.impl.postgresql.SdTableToClassConverterPostgreSqlImpl; 8 | import org.mirrentools.sd.impl.ScrewDriverTemplateFreeMarkerImpl; 9 | import org.mirrentools.sd.impl.dbutil.SdDbUtilPostgreSqlImpl; 10 | import org.mirrentools.sd.options.ScrewDriverOptions; 11 | import org.mirrentools.sd.options.SdDatabaseOptions; 12 | 13 | /** 14 | * PostgreSQL版配置 15 | * 16 | * @author Mirren 17 | * 18 | */ 19 | public class ScrewDriverPostgreSqlOptions extends ScrewDriverOptions { 20 | /** 21 | * 初始化一个PostgreSQL版的ScrewDriver配置,用于仅生成SQL 22 | * 23 | * @param databaseOptions 数据库连接信息 24 | */ 25 | public ScrewDriverPostgreSqlOptions(SdDatabaseOptions databaseOptions) { 26 | super(); 27 | init(databaseOptions); 28 | } 29 | 30 | /** 31 | * 初始化 32 | * 33 | * @param databaseOptions 数据库连接信息 34 | */ 35 | private void init(SdDatabaseOptions databaseOptions) { 36 | super.setDatabaseOptions(databaseOptions); 37 | super.setTemplateContentConverter(new SdTemplateContentConverterDefaultImpl()); 38 | super.setTemplateEngine(new ScrewDriverTemplateFreeMarkerImpl()); 39 | 40 | super.setBeanConverter(new SdClassConverterPostgreSqlImpl()); 41 | 42 | super.setTableConverter(new SdTableContentConverterPostgreSqlImpl()); 43 | super.setClassConverter(new SdTableToClassConverterPostgreSqlImpl()); 44 | super.setDatabaseConverter(new SdDatabaseConverterPostgreSqlImpl()); 45 | 46 | super.setDbUtil(new SdDbUtilPostgreSqlImpl(databaseOptions)); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/options/def/ScrewDriverSqlServerOptions.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.options.def; 2 | 3 | import org.mirrentools.sd.converter.impl.SdTemplateContentConverterDefaultImpl; 4 | import org.mirrentools.sd.converter.impl.sqlite.SdTableToClassConverterSqliteImpl; 5 | import org.mirrentools.sd.converter.impl.sqlserver.SdClassConverterSqlServerImpl; 6 | import org.mirrentools.sd.converter.impl.sqlserver.SdTableContentConverterSqlServerImpl; 7 | import org.mirrentools.sd.impl.ScrewDriverTemplateFreeMarkerImpl; 8 | import org.mirrentools.sd.impl.dbutil.SdDbUtilSqlServerImpl; 9 | import org.mirrentools.sd.options.ScrewDriverOptions; 10 | import org.mirrentools.sd.options.SdDatabaseOptions; 11 | 12 | /** 13 | * SqlServer版配置 14 | * 15 | * @author Mirren 16 | * 17 | */ 18 | public class ScrewDriverSqlServerOptions extends ScrewDriverOptions { 19 | /** 20 | * 初始化一个SqlServer版的ScrewDriver配置,用于仅生成SQL 21 | * 22 | * 23 | * @param databaseOptions 24 | * 数据库连接信息 25 | */ 26 | public ScrewDriverSqlServerOptions(SdDatabaseOptions databaseOptions) { 27 | init( databaseOptions); 28 | } 29 | 30 | /** 31 | * 初始化 32 | * 33 | * @param databaseOptions 34 | * 数据库连接信息 35 | */ 36 | private void init(SdDatabaseOptions databaseOptions) { 37 | super.setDatabaseOptions(databaseOptions); 38 | super.setTemplateContentConverter(new SdTemplateContentConverterDefaultImpl()); 39 | super.setTemplateEngine(new ScrewDriverTemplateFreeMarkerImpl()); 40 | 41 | super.setBeanConverter(new SdClassConverterSqlServerImpl()); 42 | 43 | super.setTableConverter(new SdTableContentConverterSqlServerImpl()); 44 | super.setClassConverter(new SdTableToClassConverterSqliteImpl()); 45 | super.setDbUtil(new SdDbUtilSqlServerImpl(databaseOptions)); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/mirrentools/sd/options/def/ScrewDriverSqliteOptions.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.options.def; 2 | 3 | import org.mirrentools.sd.converter.impl.SdTemplateContentConverterDefaultImpl; 4 | import org.mirrentools.sd.converter.impl.sqlite.SdClassConverterSqliteImpl; 5 | import org.mirrentools.sd.converter.impl.sqlite.SdTableContentConverterSqliteImpl; 6 | import org.mirrentools.sd.converter.impl.sqlite.SdTableToClassConverterSqliteImpl; 7 | import org.mirrentools.sd.impl.ScrewDriverTemplateFreeMarkerImpl; 8 | import org.mirrentools.sd.impl.dbutil.SdDbUtilSqliteImpl; 9 | import org.mirrentools.sd.options.ScrewDriverOptions; 10 | import org.mirrentools.sd.options.SdDatabaseOptions; 11 | 12 | /** 13 | * SQLite版配置 14 | * 15 | * @author Mirren 16 | * 17 | */ 18 | public class ScrewDriverSqliteOptions extends ScrewDriverOptions { 19 | /** 20 | * 初始化一个SQLite版的ScrewDriver配置,用于仅生成SQL 21 | * 22 | * 23 | * @param databaseOptions 数据库连接信息 24 | */ 25 | public ScrewDriverSqliteOptions(SdDatabaseOptions databaseOptions) { 26 | init(databaseOptions); 27 | } 28 | 29 | /** 30 | * 初始化 31 | * 32 | * @param templateMaps 模板集合 33 | * @param databaseOptions 数据库连接信息 34 | */ 35 | private void init(SdDatabaseOptions databaseOptions) { 36 | super.setDatabaseOptions(databaseOptions); 37 | super.setTemplateContentConverter(new SdTemplateContentConverterDefaultImpl()); 38 | super.setTemplateEngine(new ScrewDriverTemplateFreeMarkerImpl()); 39 | super.setBeanConverter(new SdClassConverterSqliteImpl()); 40 | super.setTableConverter(new SdTableContentConverterSqliteImpl()); 41 | super.setClassConverter(new SdTableToClassConverterSqliteImpl()); 42 | super.setDbUtil(new SdDbUtilSqliteImpl(databaseOptions)); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/Controller.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.controller.packageName}; 2 | 3 | public interface ${content.items.controller.className} { 4 | //该模板为示例模板,你可以自己编写模板或者参考帮助文档中【模板与匹配规则说明】设置现有模板的路径 5 | } -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/Dao.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.dao.packageName}; 2 | 3 | public interface ${content.items.dao.className} { 4 | //该模板为示例模板,你可以自己编写模板或者参考帮助文档中【模板与匹配规则说明】设置现有模板的路径 5 | } -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/JavaEntity.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.entity.packageName}; 2 | 3 | <#if content.content.imports??> 4 | <#list content.content.imports as impt> 5 | import ${impt}; 6 | 7 | 8 | 9 | /** 10 | * <#if content.content.remark??>${content.content.remark} 11 | * @author 12 | */ 13 | <#if content.content.annotations??> 14 | <#list content.content.annotations as anno> 15 | ${anno} 16 | 17 | 18 | public class ${content.items.entity.className} { 19 | <#list content.content.fields as item> 20 | <#if item.fieldRemark??>/** ${item.fieldRemark} */ 21 | <#if item.annotations??> 22 | <#list item.annotations as anno> 23 | ${anno} 24 | 25 | 26 | private ${item.fieldType} ${item.fieldName}; 27 | 28 | 29 | <#list content.content.fields as item> 30 | <#if item.fieldRemark??> 31 | /** 32 | * 获取${item.fieldRemark} 33 | * 34 | * @return 35 | */ 36 | 37 | public ${item.fieldType} <#if item.fieldType == "boolean">is<#else>get${item.fieldNamePascal}() { 38 | return ${item.fieldName}; 39 | } 40 | <#if item.fieldRemark??> 41 | /** 42 | * 设置${item.fieldRemark} 43 | * 44 | * @param ${item.fieldName} 45 | */ 46 | 47 | public void set${item.fieldNamePascal}(${item.fieldType} ${item.fieldName}) { 48 | this.${item.fieldName} = ${item.fieldName}; 49 | } 50 | 51 | 52 | @Override 53 | public String toString() { 54 | return "${content.items.entity.className} [<#list content.content.fields as item>${item.fieldName}=" + ${item.fieldName} + " <#if item?has_next>, ]"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/JavaFluentEntity.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.entity.packageName}; 2 | 3 | <#if content.content.imports??> 4 | <#list content.content.imports as impt> 5 | import ${impt}; 6 | 7 | 8 | 9 | /** 10 | * <#if content.content.remark??>${content.content.remark} 11 | * @author 12 | */ 13 | <#if content.content.annotations??> 14 | <#list content.content.annotations as anno> 15 | ${anno} 16 | 17 | 18 | <#assign assign_ClassName = content.items.entity.className> 19 | public class ${assign_ClassName} { 20 | <#list content.content.fields as item> 21 | <#if item.fieldRemark??>/** ${item.fieldRemark} */ 22 | <#if item.annotations??> 23 | <#list item.annotations as anno> 24 | ${anno} 25 | 26 | 27 | private ${item.fieldType} ${item.fieldName}; 28 | 29 | 30 | <#list content.content.fields as item> 31 | <#if item.fieldRemark??> 32 | /** 33 | * 获取${item.fieldRemark} 34 | * 35 | * @return 36 | */ 37 | 38 | public ${item.fieldType} <#if item.fieldType == "boolean">is<#else>get${item.fieldNamePascal}() { 39 | return ${item.fieldName}; 40 | } 41 | <#if item.fieldRemark??> 42 | /** 43 | * 设置${item.fieldRemark} 44 | * 45 | * @param ${item.fieldName} 46 | */ 47 | 48 | public ${assign_ClassName} set${item.fieldNamePascal}(${item.fieldType} ${item.fieldName}) { 49 | this.${item.fieldName} = ${item.fieldName}; 50 | return this; 51 | } 52 | 53 | 54 | @Override 55 | public String toString() { 56 | return "${content.items.entity.className} [<#list content.content.fields as item>${item.fieldName}=" + ${item.fieldName} + " <#if item?has_next>, ]"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/JavaLombokEntity.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.entity.packageName}; 2 | 3 | <#if content.content.imports??> 4 | <#list content.content.imports as impt> 5 | import ${impt}; 6 | 7 | 8 | import lombok.Data; 9 | 10 | /** 11 | * <#if content.content.remark??>${content.content.remark} 12 | * @author 13 | */ 14 | <#if content.content.annotations??> 15 | <#list content.content.annotations as anno> 16 | ${anno} 17 | 18 | 19 | @Data 20 | public class ${content.items.entity.className} { 21 | <#list content.content.fields as item> 22 | <#if item.fieldRemark??>/** ${item.fieldRemark} */ 23 | <#if item.annotations??> 24 | <#list item.annotations as anno> 25 | ${anno} 26 | 27 | 28 | private ${item.fieldType} ${item.fieldName}; 29 | 30 | } -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/Service.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.service.packageName}; 2 | 3 | public interface ${content.items.service.className} { 4 | //该模板为示例模板,你可以自己编写模板或者参考帮助文档中【模板与匹配规则说明】设置现有模板的路径 5 | } -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/jpa/Controller.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.controller.packageName}; 2 | <#assign assign_EntityName = content.items.entity.className> 3 | import java.util.Map; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import ${content.items.service.packageName}.${content.items.service.className}; 12 | import ${content.items.entity.packageName}.${assign_EntityName}; 13 | 14 | /** 15 | * ${assign_EntityName}的接口服务 16 | * 17 | * @author 18 | * 19 | */ 20 | @RestController 21 | @RequestMapping("/${content.items.entity.lowerName}") 22 | public class ${content.items.controller.className} { 23 | /***/ 24 | @Autowired 25 | private ${content.items.service.className} service; 26 | 27 | @GetMapping(path = "/find", produces = { "application/json;charset=UTF-8" }) 28 | public Map find() { 29 | return service.find(); 30 | } 31 | 32 | @GetMapping(path = "/limit", produces = { "application/json;charset=UTF-8" }) 33 | public Map limit(Integer page, Integer rowSize) { 34 | return service.limit(page, rowSize); 35 | } 36 | 37 | @PostMapping(path = "/save", produces = { "application/json;charset=UTF-8" }) 38 | public Map save(${assign_EntityName} data) { 39 | return service.save(data); 40 | } 41 | <#if content.content.primaryField??> 42 | <#assign assign_fieldType = content.content.primaryField[0].fieldType> 43 | <#assign assign_fieldName = content.content.primaryField[0].fieldName> 44 | @GetMapping(path = "/get", produces = { "application/json;charset=UTF-8" }) 45 | public Map get(${assign_fieldType} ${assign_fieldName}) { 46 | return service.findOne(${assign_fieldName}); 47 | } 48 | 49 | @PostMapping(path = "/delete", produces = { "application/json;charset=UTF-8" }) 50 | public Map delete(${assign_fieldType} ${assign_fieldName}) { 51 | return service.delete(${assign_fieldName}); 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/jpa/Dao.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.dao.packageName}; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import ${content.items.entity.packageName}.${content.items.entity.className}; 7 | /** 8 | * ${content.items.entity.className}数据库相关操作 9 | * @author 10 | */ 11 | @Repository 12 | <#if content.content.primaryField??><#assign assign_fieldType = content.content.primaryField[0].fieldType> 13 | public interface ${content.items.dao.className} extends JpaRepository<${content.items.entity.className}, ${assign_fieldType!'null'}> { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/jpa/EntityLombok.ftl: -------------------------------------------------------------------------------- 1 | <#assign assign_ClassName = content.items.entity.className> 2 | package ${content.items.entity.packageName}; 3 | 4 | import javax.persistence.Entity; 5 | import javax.persistence.Id; 6 | import javax.persistence.Table; 7 | import javax.persistence.Column; 8 | import lombok.Data; 9 | <#if content.content.imports??> 10 | <#list content.content.imports as impt> 11 | import ${impt}; 12 | 13 | 14 | 15 | /** 16 | * <#if content.content.remark??>${content.content.remark} 17 | * @author 18 | */ 19 | <#if content.content.annotations??> 20 | <#list content.content.annotations as anno> 21 | ${anno} 22 | 23 | 24 | @Data 25 | @Entity 26 | @Table<#if assign_ClassName != content.content.tableName>(name = "${content.content.tableName}") 27 | public class ${assign_ClassName} { 28 | <#list content.content.fields as item> 29 | <#if item.fieldRemark??>/** ${item.fieldRemark} */ 30 | <#if item.annotations??> 31 | <#list item.annotations as anno> 32 | ${anno} 33 | 34 | 35 | <#if item.primary == true>@Id 36 | <#if item.primary == true && (item.autoIncrement==true || item.identity==true)>@GeneratedValue(strategy=GenerationType.IDENTITY) 37 | <#if item.fieldName != item.name || item.nullable == false || item.length?? || item.unique==true > 38 | @Column(<#assign assign_flag=false ><#if item.fieldName != item.name>name = "${item.name}"<#assign assign_flag = true ><#if item.length??><#if assign_flag==true>, <#if item.precision??>precision = ${item.length}, scale = ${item.precision}<#else>length = ${item.length}<#assign assign_flag =true ><#if item.unique==true><#if assign_flag==true>, unique = true<#assign assign_flag =true ><#if item.nullable == false ><#if assign_flag==true>, nullable = false) 39 | 40 | private ${item.fieldType} ${item.fieldName}; 41 | 42 | <#list content.content.additionalField as item> 43 | <#if item.fieldRemark??>/** ${item.fieldRemark} */ 44 | <#if item.annotations??> 45 | <#list item.annotations as anno> 46 | ${anno} 47 | 48 | 49 | private ${item.fieldType} ${item.fieldName} <#if item.defaults??> = <#if item.fieldType == "char" || item.fieldType == "Character" >'<#if item.fieldType == "String">"${item.defaults}<#if item.fieldType == "String">"<#if item.fieldType == "char" || item.fieldType == "Character" >'<#if item.fieldType == "float">f<#if item.fieldType == "Float">F<#if item.fieldType == "long">l<#if item.fieldType == "Long">L; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/jpa/Service.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.service.packageName}; 2 | 3 | import ${content.items.entity.packageName}.${content.items.entity.className}; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * ${content.items.entity.className}数据服务接口 9 | * 10 | * @author 11 | * 12 | */ 13 | public interface ${content.items.service.className} { 14 | /** 15 | * 获取所有数据 16 | * 17 | * @return 18 | */ 19 | Map find(); 20 | 21 | /** 22 | * 获取分页 23 | * 24 | * @param page 第几页 25 | * @param rowSize 每页显示多少行 26 | * @return 27 | */ 28 | Map limit(Integer page, Integer rowSize); 29 | 30 | /** 31 | * 保存与更新 32 | * 33 | * @param data 34 | * @return 35 | */ 36 | Map save(${content.items.entity.className} data); 37 | <#if content.content.primaryField??> 38 | <#assign assign_fieldType = content.content.primaryField[0].fieldType> 39 | /** 40 | * 获取指定数据 41 | * 42 | * @param id 43 | * @return 44 | */ 45 | Map findOne(${assign_fieldType} id); 46 | 47 | /** 48 | * 删除 49 | * 50 | * @param id 51 | * @return 52 | */ 53 | Map delete(${assign_fieldType} id); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/mybatis-plus/Controller.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.controller.packageName}; 2 | <#assign assign_EntityName = content.items.entity.className> 3 | import java.util.Map; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import ${content.items.service.packageName}.${content.items.service.className}; 12 | import ${content.items.entity.packageName}.${assign_EntityName}; 13 | 14 | /** 15 | * ${assign_EntityName}的接口服务 16 | * 17 | * @author 18 | * 19 | */ 20 | @RestController 21 | @RequestMapping("/${content.items.entity.lowerName}") 22 | public class ${content.items.controller.className} { 23 | /***/ 24 | @Autowired 25 | private ${content.items.service.className} service; 26 | 27 | @GetMapping(path = "/find", produces = { "application/json;charset=UTF-8" }) 28 | public Map find() { 29 | return service.find(); 30 | } 31 | 32 | @GetMapping(path = "/limit", produces = { "application/json;charset=UTF-8" }) 33 | public Map limit(Integer page, Integer rowSize) { 34 | return service.limit(page, rowSize); 35 | } 36 | 37 | @PostMapping(path = "/save", produces = { "application/json;charset=UTF-8" }) 38 | public Map save(${assign_EntityName} data) { 39 | return service.save(data); 40 | } 41 | <#if content.content.primaryField??> 42 | <#assign assign_fieldType = content.content.primaryField[0].fieldType> 43 | <#assign assign_fieldName = content.content.primaryField[0].fieldName> 44 | @GetMapping(path = "/get", produces = { "application/json;charset=UTF-8" }) 45 | public Map get(${assign_fieldType} ${assign_fieldName}) { 46 | return service.findOne(${assign_fieldName}); 47 | } 48 | 49 | @PostMapping(path = "/update", produces = { "application/json;charset=UTF-8" }) 50 | public Map update(${assign_EntityName} data) { 51 | return service.update(data); 52 | } 53 | 54 | @PostMapping(path = "/delete", produces = { "application/json;charset=UTF-8" }) 55 | public Map delete(${assign_fieldType} ${assign_fieldName}) { 56 | return service.delete(${assign_fieldName}); 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/mybatis-plus/Dao.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.dao.packageName}; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | 5 | import ${content.items.entity.packageName}.${content.items.entity.className}; 6 | /** 7 | * ${content.items.entity.className}数据库相关操作 8 | * @author 9 | */ 10 | public interface ${content.items.dao.className} extends BaseMapper<${content.items.entity.className}> { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/mybatis-plus/EntityLombok.ftl: -------------------------------------------------------------------------------- 1 | <#assign assign_ClassName = content.items.entity.className> 2 | package ${content.items.entity.packageName}; 3 | 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import lombok.Data; 8 | <#if content.content.imports??> 9 | <#list content.content.imports as impt> 10 | import ${impt}; 11 | 12 | 13 | 14 | /** 15 | * <#if content.content.remark??>${content.content.remark} 16 | * @author 17 | */ 18 | <#if content.content.annotations??> 19 | <#list content.content.annotations as anno> 20 | ${anno} 21 | 22 | 23 | @Data 24 | <#if assign_ClassName != content.content.tableName>@TableName("${content.content.tableName}") 25 | public class ${assign_ClassName} { 26 | <#list content.content.fields as item> 27 | <#if item.fieldRemark??>/** ${item.fieldRemark} */ 28 | <#if item.annotations??> 29 | <#list item.annotations as anno> 30 | ${anno} 31 | 32 | 33 | <#if item.primary == true> 34 | <#if item.autoIncrement==true || item.identity==true > 35 | @TableId(value="${item.name}",type=IdType.AUTO) 36 | <#elseif item.fieldName != item.name > 37 | @TableId(value="${item.name}") 38 | <#else> 39 | @TableId 40 | 41 | <#else> 42 | <#if item.fieldName != item.name>@TableField("${item.name}") 43 | 44 | private ${item.fieldType} ${item.fieldName}; 45 | 46 | <#list content.content.additionalField as item> 47 | <#if item.fieldRemark??>/** ${item.fieldRemark} */ 48 | <#if item.annotations??> 49 | <#list item.annotations as anno> 50 | ${anno} 51 | 52 | 53 | private ${item.fieldType} ${item.fieldName}; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/mybatis-plus/Service.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.service.packageName}; 2 | 3 | import ${content.items.entity.packageName}.${content.items.entity.className}; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * ${content.items.entity.className}数据服务接口 9 | * 10 | * @author 11 | * 12 | */ 13 | public interface ${content.items.service.className} { 14 | /** 15 | * 获取所有数据 16 | * 17 | * @return 18 | */ 19 | Map find(); 20 | 21 | /** 22 | * 获取分页 23 | * 24 | * @param page 第几页 25 | * @param rowSize 每页显示多少行 26 | * @return 27 | */ 28 | Map limit(Integer page, Integer rowSize); 29 | 30 | /** 31 | * 保存 32 | * 33 | * @param data 34 | * @return 35 | */ 36 | Map save(${content.items.entity.className} data); 37 | <#if content.content.primaryField??> 38 | <#assign assign_fieldType = content.content.primaryField[0].fieldType> 39 | /** 40 | * 获取指定数据 41 | * 42 | * @param id 43 | * @return 44 | */ 45 | Map findOne(${assign_fieldType} id); 46 | 47 | /** 48 | * 保存 49 | * 50 | * @param data 51 | * @return 52 | */ 53 | Map update(${content.items.entity.className} data); 54 | 55 | /** 56 | * 删除 57 | * 58 | * @param id 59 | * @return 60 | */ 61 | Map delete(${assign_fieldType} id); 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/mybatis/Controller.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.controller.packageName}; 2 | <#assign assign_EntityName = content.items.entity.className> 3 | import java.util.Map; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import ${content.items.service.packageName}.${content.items.service.className}; 12 | import ${content.items.entity.packageName}.${assign_EntityName}; 13 | 14 | /** 15 | * ${assign_EntityName}的接口服务 16 | * 17 | * @author 18 | * 19 | */ 20 | @RestController 21 | @RequestMapping("/${content.items.entity.lowerName}") 22 | public class ${content.items.controller.className} { 23 | /**${assign_EntityName}的服务*/ 24 | @Autowired 25 | private ${content.items.service.className} service; 26 | 27 | @GetMapping(path = "/find", produces = { "application/json;charset=UTF-8" }) 28 | public Map find() { 29 | return service.find(); 30 | } 31 | 32 | @GetMapping(path = "/limit", produces = { "application/json;charset=UTF-8" }) 33 | public Map limit(Integer page, Integer rowSize) { 34 | return service.limit(page, rowSize); 35 | } 36 | 37 | @PostMapping(path = "/save", produces = { "application/json;charset=UTF-8" }) 38 | public Map save(${assign_EntityName} data) { 39 | return service.save(data); 40 | } 41 | <#if content.content.primaryField??> 42 | <#assign assign_fieldType = content.content.primaryField[0].fieldType> 43 | <#assign assign_fieldName = content.content.primaryField[0].fieldName> 44 | @GetMapping(path = "/get", produces = { "application/json;charset=UTF-8" }) 45 | public Map get(${assign_fieldType} ${assign_fieldName}) { 46 | return service.findOne(${assign_fieldName}); 47 | } 48 | 49 | @PostMapping(path = "/update", produces = { "application/json;charset=UTF-8" }) 50 | public Map update(${assign_EntityName} data) { 51 | return service.update(data); 52 | } 53 | 54 | @PostMapping(path = "/delete", produces = { "application/json;charset=UTF-8" }) 55 | public Map delete(${assign_fieldType} ${assign_fieldName}) { 56 | return service.delete(${assign_fieldName}); 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/mybatis/Entity.ftl: -------------------------------------------------------------------------------- 1 | <#assign assign_ClassName = content.items.entity.className> 2 | package ${content.items.entity.packageName}; 3 | 4 | <#if content.content.imports??> 5 | <#list content.content.imports as impt> 6 | import ${impt}; 7 | 8 | 9 | 10 | /** 11 | * <#if content.content.remark??>${content.content.remark} 12 | * @author 13 | */ 14 | <#if content.content.annotations??> 15 | <#list content.content.annotations as anno> 16 | ${anno} 17 | 18 | 19 | public class ${assign_ClassName} { 20 | <#list content.content.fields as item> 21 | <#if item.fieldRemark??>/** ${item.fieldRemark} */ 22 | <#if item.annotations??> 23 | <#list item.annotations as anno> 24 | ${anno} 25 | 26 | 27 | private ${item.fieldType} ${item.fieldName}; 28 | 29 | <#if content.content.additionalField??> 30 | <#list content.content.additionalField as item> 31 | <#if item.fieldRemark??>/** ${item.fieldRemark} */ 32 | <#if item.annotations??> 33 | <#list item.annotations as anno> 34 | ${anno} 35 | 36 | 37 | private ${item.fieldType} ${item.fieldName}; 38 | 39 | 40 | <#list content.content.fields as item> 41 | <#if item.fieldRemark??> 42 | /** 43 | * 获取${item.fieldRemark} 44 | * 45 | * @return 46 | */ 47 | 48 | public ${item.fieldType} <#if item.fieldType == "boolean">is<#else>get${item.fieldNamePascal}() { 49 | return ${item.fieldName}; 50 | } 51 | <#if item.fieldRemark??> 52 | /** 53 | * 设置${item.fieldRemark} 54 | * 55 | * @param ${item.fieldName} 56 | */ 57 | 58 | public void set${item.fieldNamePascal}(${item.fieldType} ${item.fieldName}) { 59 | this.${item.fieldName} = ${item.fieldName}; 60 | } 61 | 62 | <#if content.content.additionalField??> 63 | <#list content.content.additionalField as item> 64 | <#if item.fieldRemark??> 65 | /** 66 | * 获取${item.fieldRemark} 67 | * 68 | * @return 69 | */ 70 | 71 | public ${item.fieldType} <#if item.fieldType == "boolean">is<#else>get${item.fieldNamePascal}() { 72 | return ${item.fieldName}; 73 | } 74 | <#if item.fieldRemark??> 75 | /** 76 | * 设置${item.fieldRemark} 77 | * 78 | * @param ${item.fieldName} 79 | */ 80 | 81 | public void set${item.fieldNamePascal}(${item.fieldType} ${item.fieldName}) { 82 | this.${item.fieldName} = ${item.fieldName}; 83 | } 84 | 85 | 86 | 87 | @Override 88 | public String toString() { 89 | return "${content.items.entity.className} [<#list content.content.fields as item>${item.fieldName}=" + ${item.fieldName} + " <#if item?has_next>, <#if content.content.additionalField??><#list content.content.additionalField as item>, ${item.fieldName}=" + ${item.fieldName} + " <#if item?has_next>, ]"; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/mybatis/EntityLombok.ftl: -------------------------------------------------------------------------------- 1 | <#assign assign_ClassName = content.items.entity.className> 2 | package ${content.items.entity.packageName}; 3 | 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import lombok.Data; 8 | <#if content.content.imports??> 9 | <#list content.content.imports as impt> 10 | import ${impt}; 11 | 12 | 13 | 14 | /** 15 | * <#if content.content.remark??>${content.content.remark} 16 | * @author 17 | */ 18 | <#if content.content.annotations??> 19 | <#list content.content.annotations as anno> 20 | ${anno} 21 | 22 | 23 | @Data 24 | public class ${assign_ClassName} { 25 | <#list content.content.fields as item> 26 | <#if item.fieldRemark??>/** ${item.fieldRemark} */ 27 | <#if item.annotations??> 28 | <#list item.annotations as anno> 29 | ${anno} 30 | 31 | 32 | private ${item.fieldType} ${item.fieldName}; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/mybatis/Service.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.service.packageName}; 2 | 3 | import ${content.items.entity.packageName}.${content.items.entity.className}; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * ${content.items.entity.className}数据服务接口 9 | * 10 | * @author 11 | * 12 | */ 13 | public interface ${content.items.service.className} { 14 | /** 15 | * 获取所有数据 16 | * 17 | * @return 18 | */ 19 | Map find(); 20 | 21 | /** 22 | * 获取分页 23 | * 24 | * @param page 第几页 25 | * @param rowSize 每页显示多少行 26 | * @return 27 | */ 28 | Map limit(Integer page, Integer rowSize); 29 | 30 | /** 31 | * 保存 32 | * 33 | * @param data 34 | * @return 35 | */ 36 | Map save(${content.items.entity.className} data); 37 | <#if content.content.primaryField??> 38 | <#assign assign_fieldType = content.content.primaryField[0].fieldType> 39 | /** 40 | * 获取指定数据 41 | * 42 | * @param id 43 | * @return 44 | */ 45 | Map findOne(${assign_fieldType} id); 46 | 47 | /** 48 | * 保存 49 | * 50 | * @param data 51 | * @return 52 | */ 53 | Map update(${content.items.entity.className} data); 54 | 55 | /** 56 | * 删除 57 | * 58 | * @param id 59 | * @return 60 | */ 61 | Map delete(${assign_fieldType} id); 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/vertx/RouterEmpty.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.router.packageName}; 2 | <#assign assign_ClassName = content.items.router.className> 3 | <#assign assign_ServiceName = content.items.service.className> 4 | import ${content.items.service.packageName}.${content.items.service.className}; 5 | 6 | import io.vertx.core.MultiMap; 7 | import io.vertx.core.http.HttpHeaders; 8 | import io.vertx.core.impl.logging.Logger; 9 | import io.vertx.core.impl.logging.LoggerFactory; 10 | import io.vertx.jdbcclient.JDBCPool; 11 | import io.vertx.ext.sql.assist.SQLExecute; 12 | import io.vertx.ext.web.Router; 13 | import io.vertx.ext.web.RoutingContext; 14 | 15 | /** 16 | * ${content.items.entity.className}的接口服务 17 | * 18 | * @author 19 | * 20 | */ 21 | public class ${assign_ClassName} { 22 | /** 日志工具 */ 23 | private final Logger LOG = LoggerFactory.getLogger(this.getClass()); 24 | /** 数据服务接口 */ 25 | private ${assign_ServiceName} service; 26 | 27 | private ${assign_ClassName}(SQLExecute execute) { 28 | super(); 29 | this.service = ${assign_ServiceName}.create(execute); 30 | } 31 | 32 | /** 33 | * 启动服务 34 | * 35 | * @param router 36 | * Router 37 | * @param execute 38 | * 数据执行器 39 | */ 40 | public static void startService(Router router, SQLExecute execute) { 41 | ${assign_ClassName} instance = new ${assign_ClassName}(execute); 42 | // 获取所有数据 43 | router.get("").handler(instance::empty); 44 | 45 | } 46 | 47 | private void empty(RoutingContext rct) { 48 | MultiMap params = rct.request().params(); 49 | if (LOG.isDebugEnabled()) { 50 | LOG.debug("执行获取数据[${assign_ServiceName}.find]-->请求参数:\n" + params); 51 | } 52 | //service.empty(params, res -> { 53 | // rct.response().putHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=utf-8").end(res.result().toBuffer()); 54 | //}); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/vertx/SQL.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.sql.packageName}; 2 | 3 | import ${content.items.entity.packageName}.${content.items.entity.className}; 4 | 5 | import io.vertx.jdbcclient.JDBCPool; 6 | import io.vertx.ext.sql.assist.CommonSQL; 7 | import io.vertx.ext.sql.assist.SQLExecute; 8 | 9 | /** 10 | * ${content.items.entity.className}数据库相关操作 11 | * @author 12 | */ 13 | public class ${content.items.sql.className} extends CommonSQL<${content.items.entity.className},JDBCPool> { 14 | public ${content.items.sql.className}(SQLExecute execute) { 15 | super(execute); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/vertx/Service.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.service.packageName}; 2 | 3 | import ${content.items.serviceImpl.packageName}.${content.items.serviceImpl.className}; 4 | 5 | import io.vertx.core.AsyncResult; 6 | import io.vertx.core.Handler; 7 | import io.vertx.core.MultiMap; 8 | import io.vertx.core.json.JsonObject; 9 | import io.vertx.jdbcclient.JDBCPool; 10 | import io.vertx.ext.sql.assist.SQLExecute; 11 | 12 | /** 13 | * ${content.items.entity.className}数据服务接口 14 | * 15 | * @author 16 | * 17 | */ 18 | public interface ${content.items.service.className} { 19 | /** 20 | * 创建一个实例 21 | * 22 | * @param execute 23 | * @return 24 | */ 25 | static ${content.items.service.className} create(SQLExecute execute) { 26 | return new ${content.items.serviceImpl.className}(execute); 27 | } 28 | 29 | /** 30 | * 获取所有数据 31 | * 32 | * @param params 请求参数 33 | * @param handler 响应结果 34 | */ 35 | void find(MultiMap params, Handler> handler); 36 | 37 | /** 38 | * 获取分页 39 | * 40 | * @param params 请求参数 41 | * @param handler 响应结果 42 | */ 43 | void limit(MultiMap params, Handler> handler); 44 | 45 | /** 46 | * 保存 47 | * 48 | * @param params 请求参数 49 | * @param handler 响应结果 50 | */ 51 | void save(MultiMap params, Handler> handler); 52 | <#if content.content.primaryField??> 53 | 54 | /** 55 | * 获取指定的数据 56 | * 57 | * @param params 请求参数 58 | * @param handler 响应结果 59 | */ 60 | void get(MultiMap params, Handler> handler); 61 | 62 | /** 63 | * 更新 64 | * 65 | * @param params 请求参数 66 | * @param handler 响应结果 67 | */ 68 | void update(MultiMap params, Handler> handler); 69 | 70 | /** 71 | * 删除 72 | * 73 | * @param params 请求参数 74 | * @param handler 响应结果 75 | */ 76 | void delete(MultiMap params, Handler> handler); 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/vertx/ServiceEmpty.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.service.packageName}; 2 | 3 | import ${content.items.serviceImpl.packageName}.${content.items.serviceImpl.className}; 4 | 5 | import io.vertx.core.AsyncResult; 6 | import io.vertx.core.Handler; 7 | import io.vertx.core.MultiMap; 8 | import io.vertx.core.json.JsonObject; 9 | import io.vertx.jdbcclient.JDBCPool; 10 | import io.vertx.ext.sql.assist.SQLExecute; 11 | 12 | /** 13 | * ${content.items.entity.className}数据服务接口 14 | * 15 | * @author 16 | * 17 | */ 18 | public interface ${content.items.service.className} { 19 | /** 20 | * 创建一个实例 21 | * 22 | * @param execute 23 | * @return 24 | */ 25 | static ${content.items.service.className} create(SQLExecute execute) { 26 | return new ${content.items.serviceImpl.className}(execute); 27 | } 28 | 29 | /** 30 | * 获取所有数据 31 | * 32 | * @param params 请求参数 33 | * @param handler 响应结果 34 | */ 35 | //void empty(MultiMap params, Handler> handler); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/vertx/ServiceImplEmpty.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.serviceImpl.packageName}; 2 | <#assign assign_ClassName = content.items.serviceImpl.className> 3 | <#assign assign_EntityName = content.items.entity.className> 4 | <#assign assign_SqlName = content.items.sql.camelName> 5 | 6 | 7 | import ${content.items.service.packageName}.${content.items.service.className}; 8 | import ${content.items.sql.packageName}.${content.items.sql.className}; 9 | 10 | import io.vertx.core.impl.logging.Logger; 11 | import io.vertx.core.impl.logging.LoggerFactory; 12 | import io.vertx.jdbcclient.JDBCPool; 13 | import io.vertx.ext.sql.assist.SQLExecute; 14 | 15 | /** 16 | * ${content.items.entity.className}数据服务接口的默认实现 17 | * 18 | * @author 19 | * 20 | */ 21 | public class ${assign_ClassName} implements ${content.items.service.className} { 22 | /** 日志工具 */ 23 | private final Logger LOG = LoggerFactory.getLogger(this.getClass()); 24 | /** SQL操作语句 */ 25 | private ${content.items.sql.className} ${assign_SqlName}; 26 | 27 | /** 28 | * 初始化 29 | * 30 | * @param execute SQL执行器 31 | */ 32 | public ${assign_ClassName}(SQLExecute execute) { 33 | super(); 34 | this.${assign_SqlName}= new ${content.items.sql.className}(execute); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/vertx3/RouterEmpty.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.router.packageName}; 2 | <#assign assign_ClassName = content.items.router.className> 3 | <#assign assign_ServiceName = content.items.service.className> 4 | import ${content.items.service.packageName}.${content.items.service.className}; 5 | 6 | import io.vertx.core.MultiMap; 7 | import io.vertx.core.http.HttpHeaders; 8 | import io.vertx.core.logging.Logger; 9 | import io.vertx.core.logging.LoggerFactory; 10 | import io.vertx.ext.jdbc.JDBCClient; 11 | import io.vertx.ext.sql.assist.SQLExecute; 12 | import io.vertx.ext.web.Router; 13 | import io.vertx.ext.web.RoutingContext; 14 | 15 | /** 16 | * ${content.items.entity.className}的接口服务 17 | * 18 | * @author 19 | * 20 | */ 21 | public class ${assign_ClassName} { 22 | /** 日志工具 */ 23 | private final Logger LOG = LoggerFactory.getLogger(this.getClass()); 24 | /** 数据服务接口 */ 25 | private ${assign_ServiceName} service; 26 | 27 | private ${assign_ClassName}(${assign_ServiceName} service) { 28 | super(); 29 | this.service = service; 30 | } 31 | 32 | /** 33 | * 启动服务 34 | * 35 | * @param router 36 | * Router 37 | * @param execute 38 | * 数据执行器 39 | */ 40 | public static void startService(Router router, SQLExecute execute) { 41 | ${assign_ClassName} instance = new ${assign_ClassName}(${assign_ServiceName}.create(execute)); 42 | // 获取所有数据 43 | router.get("").handler(instance::empty); 44 | 45 | } 46 | 47 | private void empty(RoutingContext rct) { 48 | MultiMap params = rct.request().params(); 49 | if (LOG.isDebugEnabled()) { 50 | LOG.debug("执行获取数据[${assign_ServiceName}.find]-->请求参数:\n" + params); 51 | } 52 | //service.empty(params, res -> { 53 | // rct.response().putHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=utf-8").end(res.result().toBuffer()); 54 | //}); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/vertx3/SQL.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.sql.packageName}; 2 | 3 | import ${content.items.entity.packageName}.${content.items.entity.className}; 4 | 5 | import io.vertx.ext.jdbc.JDBCClient; 6 | import io.vertx.ext.sql.assist.CommonSQL; 7 | import io.vertx.ext.sql.assist.SQLExecute; 8 | 9 | /** 10 | * ${content.items.entity.className}数据库相关操作 11 | * @author 12 | */ 13 | public class ${content.items.sql.className} extends CommonSQL<${content.items.entity.className},JDBCClient> { 14 | public ${content.items.sql.className}(SQLExecute execute) { 15 | super(execute); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/vertx3/Service.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.service.packageName}; 2 | 3 | import ${content.items.serviceImpl.packageName}.${content.items.serviceImpl.className}; 4 | 5 | import io.vertx.core.AsyncResult; 6 | import io.vertx.core.Handler; 7 | import io.vertx.core.MultiMap; 8 | import io.vertx.core.json.JsonObject; 9 | import io.vertx.ext.jdbc.JDBCClient; 10 | import io.vertx.ext.sql.assist.SQLExecute; 11 | 12 | /** 13 | * ${content.items.entity.className}数据服务接口 14 | * 15 | * @author 16 | * 17 | */ 18 | public interface ${content.items.service.className} { 19 | /** 20 | * 创建一个实例 21 | * 22 | * @param execute 23 | * @return 24 | */ 25 | static ${content.items.service.className} create(SQLExecute execute) { 26 | return new ${content.items.serviceImpl.className}(execute); 27 | } 28 | 29 | /** 30 | * 获取所有数据 31 | * 32 | * @param params 33 | * @param handler 34 | */ 35 | void find(MultiMap params, Handler> handler); 36 | 37 | /** 38 | * 获取分页 39 | * 40 | * @param params 41 | * @param handler 42 | */ 43 | void limit(MultiMap params, Handler> handler); 44 | 45 | /** 46 | * 保存 47 | * 48 | * @param params 49 | * @param handler 50 | */ 51 | void save(MultiMap params, Handler> handler); 52 | <#if content.content.primaryField??> 53 | 54 | /** 55 | * 获取指定的数据 56 | * 57 | * @param params 58 | * @param handler 59 | */ 60 | void get(MultiMap params, Handler> handler); 61 | 62 | /** 63 | * 更新 64 | * 65 | * @param params 66 | * @param handler 67 | */ 68 | void update(MultiMap params, Handler> handler); 69 | 70 | /** 71 | * 删除 72 | * 73 | * @param params 74 | * @param handler 75 | */ 76 | void delete(MultiMap params, Handler> handler); 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/vertx3/ServiceEmpty.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.service.packageName}; 2 | 3 | import ${content.items.serviceImpl.packageName}.${content.items.serviceImpl.className}; 4 | 5 | import io.vertx.core.AsyncResult; 6 | import io.vertx.core.Handler; 7 | import io.vertx.core.MultiMap; 8 | import io.vertx.core.json.JsonObject; 9 | import io.vertx.ext.jdbc.JDBCClient; 10 | import io.vertx.ext.sql.assist.SQLExecute; 11 | 12 | /** 13 | * ${content.items.entity.className}数据服务接口 14 | * 15 | * @author 16 | * 17 | */ 18 | public interface ${content.items.service.className} { 19 | /** 20 | * 创建一个实例 21 | * 22 | * @param execute 23 | * @return 24 | */ 25 | static ${content.items.service.className} create(SQLExecute execute) { 26 | return new ${content.items.serviceImpl.className}(execute); 27 | } 28 | 29 | /** 30 | * 获取所有数据 31 | * 32 | * @param params 33 | * @param handler 34 | */ 35 | //void empty(MultiMap params, Handler> handler); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/resources/SdTemplates/vertx3/ServiceImplEmpty.ftl: -------------------------------------------------------------------------------- 1 | package ${content.items.serviceImpl.packageName}; 2 | <#assign assign_ClassName = content.items.serviceImpl.className> 3 | <#assign assign_EntityName = content.items.entity.className> 4 | <#assign assign_SqlName = content.items.sql.camelName> 5 | 6 | 7 | import ${content.items.service.packageName}.${content.items.service.className}; 8 | import ${content.items.sql.packageName}.${content.items.sql.className}; 9 | 10 | import io.vertx.core.logging.Logger; 11 | import io.vertx.core.logging.LoggerFactory; 12 | import io.vertx.ext.jdbc.JDBCClient; 13 | import io.vertx.ext.sql.assist.SQLExecute; 14 | 15 | /** 16 | * ${content.items.entity.className}数据服务接口的默认实现 17 | * 18 | * @author 19 | * 20 | */ 21 | public class ${assign_ClassName} implements ${content.items.service.className} { 22 | /** 日志工具 */ 23 | private final Logger LOG = LoggerFactory.getLogger(this.getClass()); 24 | /** SQL操作语句 */ 25 | private ${content.items.sql.className} ${assign_SqlName}; 26 | 27 | /** 28 | * 初始化 29 | * 30 | * @param execute 31 | */ 32 | public ${assign_ClassName}(SQLExecute execute) { 33 | super(); 34 | this.${assign_SqlName}= new ${content.items.sql.className}(execute); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/.gitignore: -------------------------------------------------------------------------------- 1 | /Mytest.java 2 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/Db2Test.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.common.SdUtil; 7 | import org.mirrentools.sd.constant.SdConstant; 8 | import org.mirrentools.sd.constant.DB2; 9 | import org.mirrentools.sd.models.SdBean; 10 | import org.mirrentools.sd.models.SdColumn; 11 | import org.mirrentools.sd.models.SdTemplate; 12 | import org.mirrentools.sd.options.SdDatabaseOptions; 13 | import org.mirrentools.sd.options.def.ScrewDriverDB2Options; 14 | 15 | public class Db2Test { 16 | public static void main(String[] args) throws Exception { 17 | // 创建一个实体描述 18 | SdBean bean = new SdBean(); 19 | SdColumn column = new SdColumn().setName("id").setType(SdType.DECIMAL).setLength(10).setPrimary(true).setRemark("用户的id"); 20 | SdColumn column2 = new SdColumn().setName("name").setType(SdType.VARCHAR).setLength(60).setRemark("用户的名字"); 21 | SdColumn column3 = new SdColumn().setName("pwd").setType(SdType.VARCHAR).setLength(60).setRemark("用户的的密码"); 22 | bean.setName("user").setRemark("用户").setColumns(SdUtil.asList(column, column2, column3)); 23 | // 设置实体生成模板 24 | Map templates = new HashMap(); 25 | templates.put("entity", new SdTemplate().setPath("mybatis").setFile("JavaEntity.ftl").setSourceFolder(SdConstant.MAVEN_SRC).setPackageName("entity").setClassName("User")); 26 | // 初始化SQL执行生成工具 27 | SdDatabaseOptions databaseOptions = new SdDatabaseOptions(DB2.DB2_DERVER, "jdbc:db2://127.0.0.1:50000/sample"); 28 | databaseOptions.setUser("db2admin"); 29 | databaseOptions.setPassword("000000"); 30 | ScrewDriver screwDriver = ScrewDriver.instance(new ScrewDriverDB2Options(databaseOptions)); 31 | screwDriver.createTable(bean); 32 | screwDriver.createCode(bean,templates); 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/OracleTest2.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.common.SdUtil; 7 | import org.mirrentools.sd.constant.SdConstant; 8 | import org.mirrentools.sd.constant.Oracle; 9 | import org.mirrentools.sd.models.SdBean; 10 | import org.mirrentools.sd.models.SdColumn; 11 | import org.mirrentools.sd.models.SdTemplate; 12 | import org.mirrentools.sd.options.SdDatabaseOptions; 13 | import org.mirrentools.sd.options.def.ScrewDriverOracleOptions; 14 | 15 | public class OracleTest2 { 16 | public static void main(String[] args) throws Exception { 17 | // 创建一个实体描述 18 | SdBean bean = new SdBean(); 19 | SdColumn column = new SdColumn().setName("id").setType(SdType.NUMBER).setLength(10).setPrimary(true).setRemark("用户的id"); 20 | SdColumn column2 = new SdColumn().setName("name").setType(SdType.VARCHAR2).setLength(30).setRemark("用户的名字"); 21 | SdColumn column3 = new SdColumn().setName("pwd").setType(SdType.VARCHAR2).setLength(60).setRemark("用户的的密码"); 22 | bean.setName("tuser").setRemark("用户").setColumns(SdUtil.asList(column, column2, column3)); 23 | // 设置实体生成模板 24 | Map templates = new HashMap(); 25 | templates.put("entity", new SdTemplate().setPath("mybatis").setFile("JavaEntity.ftl").setSourceFolder(SdConstant.MAVEN_SRC).setPackageName("entity").setClassName("User")); 26 | // 初始化SQL执行生成工具 27 | SdDatabaseOptions databaseOptions = new SdDatabaseOptions(Oracle.ORACLE_DERVER, "jdbc:oracle:thin:@127.0.0.1:1521:orcl"); 28 | databaseOptions.setUser("scott"); 29 | databaseOptions.setPassword("tiger"); 30 | ScrewDriver screwDriver = ScrewDriver.instance(new ScrewDriverOracleOptions(databaseOptions)); 31 | screwDriver.createTable(bean); 32 | //screwDriver.createCode(bean); 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/ScrewDriverCreateCodeOnlyExample.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.models.SdBean; 7 | import org.mirrentools.sd.models.SdColumn; 8 | import org.mirrentools.sd.models.SdTemplate; 9 | import org.mirrentools.sd.options.ScrewDriverOptions; 10 | 11 | public class ScrewDriverCreateCodeOnlyExample { 12 | 13 | public static void main(String[] args) throws Exception { 14 | // 创建一个实体描述 15 | SdBean bean = new SdBean(); 16 | bean.setName("user").setRemark("用户"); 17 | bean.addColumn(new SdColumn().setName("id").setType(SdType.LONG).setPrimary(true).setRemark("用户的id")); 18 | bean.addColumn(new SdColumn().setName("name").setType(SdType.STRING).setLength(30).setRemark("用户的名字")); 19 | bean.addColumn(new SdColumn().setName("pwd").setType(SdType.STRING).setLength(60).setRemark("用户的的密码")); 20 | 21 | // 设置实体生成模板 22 | Map templates = new HashMap(); 23 | templates.put("entity", new SdTemplate().setFile("JavaEntity.ftl").setPackageName("entity").setClassName("User")); 24 | 25 | // 初始化执行工具 26 | ScrewDriver screwDriver = ScrewDriver.instance(new ScrewDriverOptions()); 27 | // 创建代码 28 | screwDriver.createCode(bean,templates); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/ScrewDriverCreateExample.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.constant.MySQL; 7 | import org.mirrentools.sd.models.SdBean; 8 | import org.mirrentools.sd.models.SdColumn; 9 | import org.mirrentools.sd.models.SdTemplate; 10 | import org.mirrentools.sd.options.ScrewDriverOptions; 11 | import org.mirrentools.sd.options.SdDatabaseOptions; 12 | 13 | public class ScrewDriverCreateExample { 14 | 15 | public static void main(String[] args) throws Exception { 16 | // 创建一个实体描述 17 | SdBean bean = new SdBean(); 18 | bean.setName("user").setRemark("用户"); 19 | bean.addColumn(new SdColumn().setName("id").setType(SdType.LONG).setPrimary(true).setRemark("用户的id")); 20 | bean.addColumn(new SdColumn().setName("name").setType(SdType.STRING).setLength(30).setRemark("用户的名字")); 21 | bean.addColumn(new SdColumn().setName("pwd").setType(SdType.STRING).setLength(60).setRemark("用户的的密码")); 22 | 23 | // 设置实体生成模板 24 | Map templates = new HashMap(); 25 | templates.put("entity", new SdTemplate().setFile("JavaEntity.ftl").setPackageName("entity").setClassName("User")); 26 | 27 | // 初始化数据库连接信息 28 | SdDatabaseOptions databaseOptions = new SdDatabaseOptions(MySQL.MYSQL_8_DERVER, "jdbc:mysql://localhost:3306/root?useUnicode=true&useSSL=false&serverTimezone=UTC"); 29 | databaseOptions.setUser("root"); 30 | databaseOptions.setPassword("root"); 31 | // 初始化执行工具 32 | ScrewDriver screwDriver = ScrewDriver.instance(new ScrewDriverOptions( databaseOptions)); 33 | // 创建代码 34 | screwDriver.createCode(bean,templates); 35 | // 生成表 36 | screwDriver.createTable(bean); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/ScrewDriverReadExample.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.constant.MySQL; 7 | import org.mirrentools.sd.models.SdClassContent; 8 | import org.mirrentools.sd.models.SdTemplate; 9 | import org.mirrentools.sd.options.ScrewDriverOptions; 10 | import org.mirrentools.sd.options.SdDatabaseOptions; 11 | 12 | public class ScrewDriverReadExample { 13 | 14 | public static void main(String[] args) throws Exception { 15 | 16 | // 设置实体生成模板 17 | Map templates = new HashMap(); 18 | templates.put("entity", new SdTemplate().setFile("JavaEntity.ftl").setPackageName("entity").setClassName("User")); 19 | 20 | // 初始化数据库连接信息 21 | SdDatabaseOptions databaseOptions = new SdDatabaseOptions(MySQL.MYSQL_8_DERVER, "jdbc:mysql://localhost:3306/root?useUnicode=true&useSSL=false&serverTimezone=UTC"); 22 | databaseOptions.setUser("root"); 23 | databaseOptions.setPassword("root"); 24 | 25 | // 初始化执行工具 26 | ScrewDriver screwDriver = ScrewDriver.instance(new ScrewDriverOptions( databaseOptions)); 27 | // 读取表信息 28 | SdClassContent content = screwDriver.readTable("root"); 29 | // 创建代码 30 | screwDriver.createCode(content,templates); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/SdUtilTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.mirrentools.sd.common.SdUtil; 7 | 8 | public class SdUtilTest { 9 | public static void main(String[] args) throws IOException { 10 | String file = SdUtil.readFileToString(new File("D:/TempJect/input.txt")); 11 | System.out.println(file); 12 | 13 | System.exit(0); 14 | String str = "my_name_is_mirren-my-NameIsMirrenNAME id mirren出生年份BornIn1991"; 15 | System.out.println("原字符串: " + str); 16 | String camelCase = SdUtil.toCamelCase(str); 17 | System.out.println("camelCase: " + camelCase); 18 | String pascalCase = SdUtil.toPascalCase(str); 19 | System.out.println("pascalCase: " + pascalCase); 20 | String underScoreCase = SdUtil.toUnderScoreCase(str); 21 | System.out.println("underScoreCase: " + underScoreCase); 22 | String upperUnderScoreCase = SdUtil.toUnderScoreCaseUpper(str); 23 | System.out.println("upperUnderScoreCase: " + upperUnderScoreCase); 24 | String hyphenCase = SdUtil.toHyphenCase(str); 25 | System.out.println("hyphenCase: " + hyphenCase); 26 | String upperHyphenCase = SdUtil.toHyphenCaseUpper(str); 27 | System.out.println("upperHyphenCase: " + upperHyphenCase); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/constant/CommonConstant.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.constant; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.models.SdTemplate; 7 | import org.mirrentools.sd.models.SdTemplateAttribute; 8 | import org.mirrentools.sd.models.db.query.SdTable; 9 | import org.mirrentools.sd.models.db.query.SdTableAttribute; 10 | import org.mirrentools.sd.models.db.query.SdTableColumnAttribute; 11 | import org.mirrentools.sd.models.db.query.SdTableIndexKeyAttribute; 12 | import org.mirrentools.sd.models.db.query.SdTablePortedKeysAttribute; 13 | import org.mirrentools.sd.models.db.query.SdTablePrimaryKeyAttribute; 14 | 15 | /** 16 | * 一些测试中可能灰反复使用的类 17 | * 18 | * @author Mirren 19 | * 20 | */ 21 | public class CommonConstant { 22 | // 设置实体生成模板 23 | public static Map templates; 24 | // 数据库配置文件 25 | public static SdTable studentTable; 26 | 27 | static { 28 | initTemplates(); 29 | initTable(); 30 | } 31 | 32 | /** 33 | * 初始化模板工具 34 | */ 35 | private static void initTemplates() { 36 | templates = new HashMap(); 37 | SdTemplate entity = new SdTemplate().setFile("entity.ftl").setSourceFolder(SdConstant.MAVEN_TEST).setPackageName("com.entity").setClassName("User"); 38 | templates.put("entity", entity); 39 | SdTemplate dao = new SdTemplate().setFile("dao.ftl").setSourceFolder(SdConstant.MAVEN_TEST).setPackageName("com.dao").setClassName("UserDao"); 40 | dao.addAttribute(new SdTemplateAttribute("test", "{c}{p}", "测试驼峰与帕斯卡还有下划线{u},连字符{h}")); 41 | templates.put("dao", dao); 42 | } 43 | 44 | /** 45 | * 初始化表 46 | */ 47 | private static void initTable() { 48 | studentTable = new SdTable(); 49 | String tableName = "classes_student"; 50 | studentTable.setInfo(new SdTableAttribute().setTableName(tableName).setRemarks("学生表")); 51 | SdTableColumnAttribute c1 = new SdTableColumnAttribute().setColumnName("id").setTypeName(SQL.BIGINT).setAutoincrement("YES").setRemarks("学生的id"); 52 | SdTableColumnAttribute c2 = new SdTableColumnAttribute().setColumnName("name").setTypeName(SQL.VARCHAR).setColumnSize(30).setNullable(1).setRemarks("学生的id"); 53 | SdTableColumnAttribute c3 = new SdTableColumnAttribute().setColumnName("mobile_phone").setTypeName(SQL.VARCHAR).setColumnDef("0086").setColumnSize(30).setNullable(1).setRemarks("学生的手机号码"); 54 | SdTableColumnAttribute c4 = new SdTableColumnAttribute().setColumnName("classes_id").setTypeName(SQL.INT).setRemarks("班级的id"); 55 | studentTable.addColumn(c1).addColumn(c2).addColumn(c3).addColumn(c4); 56 | studentTable.setPrimaryKey(new SdTablePrimaryKeyAttribute().setColumnName("id").setPkName("Primary").setTableName(tableName)); 57 | studentTable.addIndexKey(new SdTableIndexKeyAttribute().setTableName(tableName).setColumnName("mobile_phone").setIndexName("idx_user_mobile_phone")); 58 | studentTable 59 | .addForeignKey(new SdTablePortedKeysAttribute().setFktableCat("root").setFktableName("classes").setFkName("classes_id").setFkName("FK_classes_student_id").setFkcolumnName("classes_id")); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/converter/SdTableToClassConverterTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.mirrentools.sd.constant.CommonConstant; 8 | import org.mirrentools.sd.converter.impl.mysql.SdTableToClassConverterMySqlImpl; 9 | import org.mirrentools.sd.models.SdClassContent; 10 | 11 | /** 12 | * 将表属性类转为类属性的测试 13 | * 14 | * @author Mirren 15 | * 16 | */ 17 | public class SdTableToClassConverterTest { 18 | /** 转换类 */ 19 | private SdTableToClassConverter converter; 20 | @Before 21 | public void setUp() { 22 | converter = new SdTableToClassConverterMySqlImpl(); 23 | } 24 | @Test 25 | public void testConverter() { 26 | SdClassContent content = converter.converter(CommonConstant.studentTable); 27 | assertEquals("classes_student", content.getTableName()); 28 | assertEquals("classes_student", content.getUnderScoreName()); 29 | assertEquals("classes-student", content.getHyphenName()); 30 | assertEquals("classesStudent", content.getCamelName()); 31 | assertEquals("ClassesStudent", content.getPascalName()); 32 | assertEquals(4, content.getFields().size()); 33 | 34 | assertEquals(1, content.getPrimaryField().size()); 35 | assertEquals(1, content.getForeignField().size()); 36 | assertEquals(1, content.getIndexField().size()); 37 | assertEquals(1, content.getOtherField().size()); 38 | assertEquals(2, content.getCantNullField().size()); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/converter/SdTemplateContentConverterTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.converter; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.util.Map; 7 | 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.mirrentools.sd.constant.CommonConstant; 11 | import org.mirrentools.sd.constant.MySqlConstant; 12 | import org.mirrentools.sd.converter.impl.SdTemplateContentConverterDefaultImpl; 13 | import org.mirrentools.sd.models.SdClassContent; 14 | import org.mirrentools.sd.models.SdTemplate; 15 | import org.mirrentools.sd.models.SdTemplateAttribute; 16 | import org.mirrentools.sd.models.SdTemplateContent; 17 | import org.mirrentools.sd.options.SdDatabaseOptions; 18 | 19 | /** 20 | * 模板转换工具的测试 21 | * 22 | * @author Mirren 23 | * 24 | */ 25 | public class SdTemplateContentConverterTest { 26 | /** 模板转换器 */ 27 | private SdTemplateContentConverter converter; 28 | /** 模板属性 */ 29 | private Map templates; 30 | /** 用于班级的内容 */ 31 | private SdClassContent studentContent; 32 | /** 数据库配置文件 */ 33 | private SdDatabaseOptions databaseOptions; 34 | 35 | @Before 36 | public void setUp() { 37 | converter = new SdTemplateContentConverterDefaultImpl(); 38 | templates = CommonConstant.templates; 39 | studentContent = MySqlConstant.studentBeanContent; 40 | databaseOptions = MySqlConstant.databaseOptions; 41 | } 42 | 43 | @Test 44 | public void testConverter() { 45 | Map content = converter.converter(studentContent, databaseOptions, templates); 46 | assertEquals(2, content.size()); 47 | SdTemplateContent dao = content.get("dao"); 48 | assertNotNull(dao); 49 | assertEquals("dao.ftl", dao.getFile()); 50 | assertEquals("com.dao", dao.getPackageName()); 51 | assertEquals("UserDao", dao.getClassName()); 52 | assertEquals(".java", dao.getSuffix()); 53 | assertEquals(1, dao.getAttrs().size()); 54 | SdTemplateAttribute attribute = dao.getAttrs().get("test"); 55 | assertEquals("userDaoUserDao", attribute.getValue()); 56 | assertEquals("测试驼峰与帕斯卡还有下划线user_dao,连字符user-dao", attribute.getDescribe()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/dbutil/mysql/SdDbUtilMySqlExecuteTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.dbutil.mysql; 2 | 3 | import static org.junit.Assert.assertNotNull; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import java.sql.Connection; 7 | 8 | import org.mirrentools.sd.ScrewDriverDbUtil; 9 | import org.mirrentools.sd.constant.MySQL; 10 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 11 | import org.mirrentools.sd.models.db.update.impl.mysql.SdDatabaseContentByMySQL; 12 | import org.mirrentools.sd.options.SdDatabaseOptions; 13 | 14 | /** 15 | * 操作工具的测试类 16 | * 17 | * @author Mirren 18 | * 19 | */ 20 | public class SdDbUtilMySqlExecuteTest { 21 | /** 操作工具 */ 22 | private ScrewDriverDbUtil sdDbUtil; 23 | 24 | public static void main(String[] args) throws Exception { 25 | SdDbUtilMySqlExecuteTest test = new SdDbUtilMySqlExecuteTest(); 26 | test.setUp(); 27 | test.testGetConnection(); 28 | test.testGetConnectionDatabaseConfig(); 29 | test.testCreateDatabase(); 30 | test.testUpdateDatabase(); 31 | } 32 | 33 | public void setUp() throws Exception { 34 | SdDatabaseOptions config = new SdDatabaseOptions(MySQL.MYSQL_DERVER, "jdbc:mysql://localhost:3306/root?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=UTC"); 35 | config.setUser("root"); 36 | config.setPassword("root"); 37 | sdDbUtil = ScrewDriverDbUtil.instance(config); 38 | } 39 | 40 | public void testGetConnection() throws Exception { 41 | Connection connection = sdDbUtil.getConnection(); 42 | assertNotNull(connection); 43 | } 44 | 45 | public void testGetConnectionDatabaseConfig() throws Exception { 46 | SdDatabaseOptions config = new SdDatabaseOptions(MySQL.MYSQL_DERVER, "jdbc:mysql://localhost:3306/root?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=UTC"); 47 | config.setUser("root"); 48 | config.setPassword("root"); 49 | Connection connection = sdDbUtil.getConnection(config); 50 | assertNotNull(connection); 51 | } 52 | 53 | public void testCreateDatabase() throws Exception { 54 | SdAbstractDatabaseContent content = new SdDatabaseContentByMySQL("item"); 55 | boolean result = sdDbUtil.createDatabase(content); 56 | assertTrue(result); 57 | } 58 | 59 | public void testUpdateDatabase() throws Exception { 60 | SdAbstractDatabaseContent content = new SdDatabaseContentByMySQL("item"); 61 | boolean result = sdDbUtil.updateDatabase(content); 62 | assertTrue(result); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/dbutil/postgresql/SdDbUtilPostgreSqlExecuteTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.dbutil.postgresql; 2 | 3 | import static org.junit.Assert.assertNotNull; 4 | import static org.junit.Assert.assertTrue; 5 | import static org.junit.Assert.fail; 6 | 7 | import java.sql.Connection; 8 | 9 | import org.mirrentools.sd.ScrewDriverDbUtil; 10 | import org.mirrentools.sd.constant.PostgreSQL; 11 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 12 | import org.mirrentools.sd.models.db.update.impl.mysql.SdDatabaseContentByMySQL; 13 | import org.mirrentools.sd.options.SdDatabaseOptions; 14 | 15 | /** 16 | * 操作工具的测试类 17 | * 18 | * @author Mirren 19 | * 20 | */ 21 | public class SdDbUtilPostgreSqlExecuteTest { 22 | /** 操作工具 */ 23 | private ScrewDriverDbUtil sdDbUtil; 24 | 25 | public static void main(String[] args) throws Exception { 26 | SdDbUtilPostgreSqlExecuteTest test = new SdDbUtilPostgreSqlExecuteTest(); 27 | test.setUp(); 28 | test.testGetConnection(); 29 | test.testGetConnectionDatabaseConfig(); 30 | test.testCreateDatabase(); 31 | test.testUpdateDatabase(); 32 | } 33 | 34 | public void setUp() throws Exception { 35 | SdDatabaseOptions config = new SdDatabaseOptions(PostgreSQL.POSTGRE_SQL_DERVER, "jdbc:postgresql://localhost:5432/root"); 36 | config.setUser("postgres"); 37 | config.setPassword("root"); 38 | sdDbUtil = ScrewDriverDbUtil.instance(config); 39 | } 40 | 41 | public void testGetConnection() { 42 | try { 43 | Connection connection = sdDbUtil.getConnection(); 44 | assertNotNull(connection); 45 | } catch (Exception e) { 46 | e.printStackTrace(); 47 | fail(); 48 | } 49 | } 50 | 51 | public void testGetConnectionDatabaseConfig() { 52 | SdDatabaseOptions config = new SdDatabaseOptions(PostgreSQL.POSTGRE_SQL_DERVER, "jdbc:postgresql://localhost:5432/root"); 53 | config.setUser("postgres"); 54 | config.setPassword("root"); 55 | try { 56 | Connection connection = sdDbUtil.getConnection(config); 57 | assertNotNull(connection); 58 | } catch (Exception e) { 59 | e.printStackTrace(); 60 | fail(e.getMessage()); 61 | } 62 | } 63 | 64 | public void testCreateDatabase() { 65 | SdAbstractDatabaseContent content = new SdDatabaseContentByMySQL("item"); 66 | try { 67 | boolean result = sdDbUtil.createDatabase(content); 68 | assertTrue(result); 69 | } catch (Exception e) { 70 | e.printStackTrace(); 71 | fail(e.getMessage()); 72 | } 73 | } 74 | 75 | public void testUpdateDatabase() { 76 | SdAbstractDatabaseContent content = new SdDatabaseContentByMySQL("item"); 77 | try { 78 | boolean result = sdDbUtil.updateDatabase(content); 79 | assertTrue(result); 80 | } catch (UnsupportedOperationException e) { 81 | e.printStackTrace(); 82 | } catch (Exception e) { 83 | e.printStackTrace(); 84 | fail(e.getMessage()); 85 | } 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/dbutil/sqlite/SdDbUtilSqliteExecuteTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.dbutil.sqlite; 2 | 3 | import static org.junit.Assert.assertNotNull; 4 | import static org.junit.Assert.assertTrue; 5 | import static org.junit.Assert.fail; 6 | 7 | import java.sql.Connection; 8 | 9 | import org.mirrentools.sd.ScrewDriverDbUtil; 10 | import org.mirrentools.sd.constant.SQLite; 11 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 12 | import org.mirrentools.sd.models.db.update.impl.mysql.SdDatabaseContentByMySQL; 13 | import org.mirrentools.sd.models.db.update.impl.sqlite.SdDatabaseContentBySqlite; 14 | import org.mirrentools.sd.options.SdDatabaseOptions; 15 | 16 | /** 17 | * 操作工具的测试类 18 | * 19 | * @author Mirren 20 | * 21 | */ 22 | public class SdDbUtilSqliteExecuteTest { 23 | /** 操作工具 */ 24 | private ScrewDriverDbUtil sdDbUtil; 25 | 26 | public static void main(String[] args) throws Exception { 27 | SdDbUtilSqliteExecuteTest test = new SdDbUtilSqliteExecuteTest(); 28 | test.setUp(); 29 | test.testGetConnection(); 30 | test.testCreateDatabase(); 31 | test.testUpdateDatabase(); 32 | } 33 | 34 | public void setUp() throws Exception { 35 | SdDatabaseOptions config = new SdDatabaseOptions(SQLite.SQLITE_DERVER, "jdbc:sqlite:D:/tempProject/test.db"); 36 | sdDbUtil = ScrewDriverDbUtil.instance(config); 37 | } 38 | 39 | public void testGetConnection() { 40 | try { 41 | Connection connection = sdDbUtil.getConnection(); 42 | assertNotNull(connection); 43 | } catch (Exception e) { 44 | e.printStackTrace(); 45 | fail(); 46 | } 47 | } 48 | public void testCreateDatabase() { 49 | try { 50 | boolean result = sdDbUtil.createDatabase(new SdDatabaseContentBySqlite("idd")); 51 | assertTrue(result); 52 | } catch (Exception e) { 53 | e.printStackTrace(); 54 | fail(e.getMessage()); 55 | } 56 | } 57 | 58 | public void testUpdateDatabase() { 59 | SdAbstractDatabaseContent content = new SdDatabaseContentByMySQL("item"); 60 | try { 61 | boolean result = sdDbUtil.updateDatabase(content); 62 | assertTrue(result); 63 | } catch (UnsupportedOperationException e) { 64 | e.printStackTrace(); 65 | } catch (Exception e) { 66 | e.printStackTrace(); 67 | fail(e.getMessage()); 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/dbutil/sqlserver/SdDbUtilSqlServerExecuteTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.dbutil.sqlserver; 2 | 3 | import static org.junit.Assert.assertNotNull; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import java.sql.Connection; 7 | 8 | import org.mirrentools.sd.ScrewDriverDbUtil; 9 | import org.mirrentools.sd.constant.SqlServer; 10 | import org.mirrentools.sd.models.SdDatabase; 11 | import org.mirrentools.sd.models.db.update.SdAbstractDatabaseContent; 12 | import org.mirrentools.sd.models.db.update.impl.sqlserver.SdDatabaseContentBySqlServer; 13 | import org.mirrentools.sd.options.SdDatabaseOptions; 14 | 15 | /** 16 | * 操作工具的测试类 17 | * 18 | * @author Mirren 19 | * 20 | */ 21 | public class SdDbUtilSqlServerExecuteTest { 22 | /** 操作工具 */ 23 | private ScrewDriverDbUtil sdDbUtil; 24 | 25 | public static void main(String[] args) throws Exception { 26 | SdDbUtilSqlServerExecuteTest test = new SdDbUtilSqlServerExecuteTest(); 27 | test.setUp(); 28 | test.testGetConnection(); 29 | test.testGetConnectionDatabaseConfig(); 30 | test.testCreateDatabase(); 31 | // test.testUpdateDatabase(); 32 | } 33 | 34 | public void setUp() throws Exception { 35 | SdDatabaseOptions config = new SdDatabaseOptions(SqlServer.SQL_SERVER_DERVER, "jdbc:sqlserver://localhost:1433;DatabaseName=item"); 36 | config.setUser("sa"); 37 | config.setPassword("root"); 38 | sdDbUtil = ScrewDriverDbUtil.instance(config); 39 | } 40 | 41 | public void testGetConnection() throws Exception { 42 | Connection connection = sdDbUtil.getConnection(); 43 | assertNotNull(connection); 44 | } 45 | 46 | public void testGetConnectionDatabaseConfig() throws Exception { 47 | SdDatabaseOptions config = new SdDatabaseOptions(SqlServer.SQL_SERVER_DERVER, "jdbc:sqlserver://localhost:1433;DatabaseName=item"); 48 | config.setUser("sa"); 49 | config.setPassword("root"); 50 | Connection connection = sdDbUtil.getConnection(config); 51 | assertNotNull(connection); 52 | } 53 | 54 | public void testCreateDatabase() throws Exception { 55 | SdDatabase database = new SdDatabase(); 56 | database.setDatabase("test"); 57 | database.setDbName("test").setDbFilename("E:/sqlserver/test/test.mdf"); 58 | database.setLogName("test_log").setLogFilename("E:/sqlserver/test/test_log.ldf"); 59 | SdAbstractDatabaseContent content = new SdDatabaseContentBySqlServer(database); 60 | boolean result = sdDbUtil.createDatabase(content); 61 | assertTrue(result); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/templateutil/Constant.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.templateutil; 2 | 3 | import org.mirrentools.sd.SdType; 4 | import org.mirrentools.sd.constant.MySQL; 5 | import org.mirrentools.sd.models.SdBean; 6 | import org.mirrentools.sd.models.SdColumn; 7 | import org.mirrentools.sd.options.SdDatabaseOptions; 8 | 9 | /** 10 | * 模板测试类的常量 11 | * 12 | * @author Mirren 13 | * 14 | */ 15 | public class Constant { 16 | /** bean常量 */ 17 | public final static SdBean BEAN; 18 | /** 数据库配置信息常量 */ 19 | public final static SdDatabaseOptions DATABASEOPTIONS; 20 | static { 21 | // 创建一个实体描述 22 | BEAN = new SdBean(); 23 | BEAN.setName("user").setRemark("用户"); 24 | BEAN.addColumn(new SdColumn().setName("id").setType(SdType.LONG).setPrimary(true).setRemark("用户的id")); 25 | BEAN.addColumn(new SdColumn().setName("name").setType(SdType.STRING).setLength(30).setRemark("用户的名字")); 26 | BEAN.addColumn(new SdColumn().setName("pwd").setType(SdType.STRING).setLength(60).setRemark("用户的的密码")); 27 | 28 | // 初始化数据库连接信息 29 | DATABASEOPTIONS = new SdDatabaseOptions(MySQL.MYSQL_8_DERVER, 30 | "jdbc:mysql://localhost:3306/root?useUnicode=true&useSSL=false&serverTimezone=UTC"); 31 | DATABASEOPTIONS.setUser("root"); 32 | DATABASEOPTIONS.setPassword("root"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/templateutil/FreeMarkerTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.templateutil; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.ScrewDriver; 7 | import org.mirrentools.sd.SdType; 8 | import org.mirrentools.sd.models.SdBean; 9 | import org.mirrentools.sd.models.SdColumn; 10 | import org.mirrentools.sd.models.SdTemplate; 11 | import org.mirrentools.sd.options.ScrewDriverOptions; 12 | 13 | public class FreeMarkerTest { 14 | public static void main(String[] args) { 15 | String entityName="Users"; 16 | Map templates = new HashMap(); 17 | templates.put("entity", new SdTemplate() 18 | .setPath("/SdTemplates/vertx/") 19 | .setFile("Entity.ftl") 20 | .setPackageName("entity") 21 | .setClassName(entityName)); 22 | templates.put("sql", new SdTemplate() 23 | .setPath("/SdTemplates/vertx/") 24 | .setFile("SQL.ftl") 25 | .setPackageName("sql") 26 | .setClassName(entityName+"SQL")); 27 | templates.put("service", new SdTemplate() 28 | .setPath("/SdTemplates/vertx/") 29 | .setFile("Service.ftl") 30 | .setPackageName("service") 31 | .setClassName(entityName+"Service")); 32 | templates.put("serviceImpl", new SdTemplate() 33 | .setPath("/SdTemplates/vertx/") 34 | .setFile("ServiceImpl.ftl") 35 | .setPackageName("service.impl") 36 | .setClassName(entityName+"ServiceImpl")); 37 | templates.put("router", new SdTemplate() 38 | .setPath("/SdTemplates/vertx/") 39 | .setFile("Router.ftl") 40 | .setPackageName("router") 41 | .setClassName(entityName+"Router")); 42 | templates.put("test", new SdTemplate() 43 | .setPath("/SdTemplates/vertx/") 44 | .setFile("Test.ftl") 45 | .setSourceFolder(org.mirrentools.sd.constant.SdConstant.MAVEN_TEST) 46 | .setPackageName("test") 47 | .setClassName(entityName+"RouterTest")); 48 | 49 | // 初始化执行工具 50 | ScrewDriverOptions options = new ScrewDriverOptions( Constant.DATABASEOPTIONS); 51 | options.setOutputPath("D:/TempJect/freemarker"); 52 | ScrewDriver screwDriver = ScrewDriver.instance(options); 53 | SdBean bean = Constant.BEAN; 54 | bean.addColumn(new SdColumn().setType(SdType.FLOAT).setNullable(false).setName("float_test")); 55 | bean.addColumn(new SdColumn().setType(SdType.DOUBLE).setNullable(false).setName("double_test")); 56 | bean.addColumn(new SdColumn().setType(SdType.LONG).setNullable(false).setName("long_test")); 57 | bean.addAdditionalColumn(new SdColumn().setType(SdType.FLOAT).setNullable(false).setName("lala_test")); 58 | screwDriver.createCode(bean,templates); 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/templateutil/FreeMarkerTestJpa.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.templateutil; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.ScrewDriver; 7 | import org.mirrentools.sd.SdType; 8 | import org.mirrentools.sd.models.SdBean; 9 | import org.mirrentools.sd.models.SdColumn; 10 | import org.mirrentools.sd.models.SdTemplate; 11 | import org.mirrentools.sd.options.ScrewDriverOptions; 12 | 13 | public class FreeMarkerTestJpa { 14 | public static void main(String[] args) { 15 | String packageName="com.example.demo."; 16 | String entityName="Users"; 17 | Map templates = new HashMap(); 18 | templates.put("entity", new SdTemplate() 19 | .setPath("/SdTemplates/jpa/") 20 | .setFile("Entity.ftl") 21 | .setPackageName(packageName + "entity") 22 | .setClassName(entityName)); 23 | templates.put("dao", new SdTemplate() 24 | .setPath("/SdTemplates/jpa/") 25 | .setFile("Dao.ftl") 26 | .setPackageName(packageName + "repository") 27 | .setClassName(entityName + "Repository")); 28 | templates.put("service", new SdTemplate() 29 | .setPath("/SdTemplates/jpa/") 30 | .setFile("Service.ftl") 31 | .setPackageName(packageName + "service") 32 | .setClassName(entityName + "Service")); 33 | templates.put("serviceImpl", new SdTemplate() 34 | .setPath("/SdTemplates/jpa/") 35 | .setFile("ServiceImpl.ftl") 36 | .setPackageName(packageName + "service.impl") 37 | .setClassName(entityName + "ServiceImpl")); 38 | templates.put("controller", new SdTemplate() 39 | .setPath("/SdTemplates/jpa/") 40 | .setFile("Controller.ftl") 41 | .setPackageName(packageName + "controller") 42 | .setClassName(entityName + "Controller")); 43 | templates.put("test", new SdTemplate() 44 | .setPath("/SdTemplates/jpa/") 45 | .setFile("Test.ftl") 46 | .setSourceFolder(org.mirrentools.sd.constant.SdConstant.MAVEN_TEST) 47 | .setPackageName(packageName + "test") 48 | .setClassName(entityName + "ControllerTest") 49 | ); 50 | 51 | // 初始化执行工具 52 | ScrewDriverOptions options = new ScrewDriverOptions( Constant.DATABASEOPTIONS); 53 | options.setOutputPath("D:/TempJect/freemarker"); 54 | ScrewDriver screwDriver = ScrewDriver.instance(options); 55 | SdBean bean = Constant.BEAN; 56 | bean.addColumn(new SdColumn().setType(SdType.FLOAT).setNullable(false).setName("float_test")); 57 | bean.addColumn(new SdColumn().setType(SdType.DOUBLE).setLength(10, 2).setNullable(false).setName("double_test")); 58 | bean.addColumn(new SdColumn().setType(SdType.LONG).setNullable(false).setName("long_test")); 59 | screwDriver.createCode(bean,templates); 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/templateutil/FreeMarkerTestMP.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.templateutil; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.mirrentools.sd.ScrewDriver; 7 | import org.mirrentools.sd.SdType; 8 | import org.mirrentools.sd.models.SdBean; 9 | import org.mirrentools.sd.models.SdColumn; 10 | import org.mirrentools.sd.models.SdTemplate; 11 | import org.mirrentools.sd.options.ScrewDriverOptions; 12 | 13 | public class FreeMarkerTestMP { 14 | public static void main(String[] args) { 15 | String packageName="com.example.demo."; 16 | String entityName="Users"; 17 | Map templates = new HashMap(); 18 | templates.put("entity", new SdTemplate() 19 | .setPath("/SdTemplates/mybatis-plus/") 20 | .setFile("Entity.ftl") 21 | .setPackageName(packageName + "entity") 22 | .setClassName(entityName)); 23 | templates.put("dao", new SdTemplate() 24 | .setPath("/SdTemplates/mybatis-plus/") 25 | .setFile("Dao.ftl") 26 | .setPackageName(packageName + "mapper") 27 | .setClassName(entityName + "Mapper")); 28 | templates.put("service", new SdTemplate() 29 | .setPath("/SdTemplates/mybatis-plus/") 30 | .setFile("Service.ftl") 31 | .setPackageName(packageName + "service") 32 | .setClassName(entityName + "Service")); 33 | templates.put("serviceImpl", new SdTemplate() 34 | .setPath("/SdTemplates/mybatis-plus/") 35 | .setFile("ServiceImpl.ftl") 36 | .setPackageName(packageName + "service.impl") 37 | .setClassName(entityName + "ServiceImpl")); 38 | templates.put("controller", new SdTemplate() 39 | .setPath("/SdTemplates/mybatis-plus/") 40 | .setFile("Controller.ftl") 41 | .setPackageName(packageName + "controller") 42 | .setClassName(entityName + "Controller")); 43 | templates.put("test", new SdTemplate() 44 | .setPath("/SdTemplates/mybatis-plus/") 45 | .setFile("Test.ftl") 46 | .setSourceFolder(org.mirrentools.sd.constant.SdConstant.MAVEN_TEST) 47 | .setPackageName(packageName + "test") 48 | .setClassName(entityName + "ControllerTest") 49 | ); 50 | 51 | // 初始化执行工具 52 | ScrewDriverOptions options = new ScrewDriverOptions( Constant.DATABASEOPTIONS); 53 | options.setOutputPath("D:/TempJect/freemarker"); 54 | ScrewDriver screwDriver = ScrewDriver.instance(options); 55 | SdBean bean = Constant.BEAN; 56 | bean.addColumn(new SdColumn().setType(SdType.FLOAT).setNullable(false).setName("float_test")); 57 | bean.addColumn(new SdColumn().setType(SdType.DOUBLE).setLength(10, 2).setNullable(false).setName("double_test")); 58 | bean.addColumn(new SdColumn().setType(SdType.LONG).setNullable(false).setName("long_test")); 59 | bean.addAdditionalColumn(new SdColumn().setType(SdType.FLOAT).setNullable(false).setName("lala_test")); 60 | screwDriver.createCode(bean,templates); 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/templateutil/MvelTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.templateutil; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.mirrentools.sd.ScrewDriver; 6 | import org.mirrentools.sd.impl.ScrewDriverTemplateMvelImpl; 7 | import org.mirrentools.sd.models.SdTemplate; 8 | import org.mirrentools.sd.options.ScrewDriverOptions; 9 | 10 | public class MvelTest { 11 | public static void main(String[] args) { 12 | HashMap templates = new HashMap(); 13 | templates.put("entity", new SdTemplate() 14 | .setPath("D:/TempJect/mvel") 15 | .setFile("input.txt") 16 | .setPackageName("entity") 17 | .setClassName("User")); 18 | 19 | // 初始化执行工具 20 | ScrewDriverOptions options = new ScrewDriverOptions( Constant.DATABASEOPTIONS); 21 | options.setOutputPath("D:/TempJect/mvel"); 22 | options.setTemplateEngine(new ScrewDriverTemplateMvelImpl()); 23 | ScrewDriver screwDriver = ScrewDriver.instance(options); 24 | screwDriver.createCode(Constant.BEAN,templates); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/util/CodeUtilByFreeMarkerTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.util; 2 | 3 | import java.util.Map; 4 | 5 | import org.mirrentools.sd.ScrewDriverCode; 6 | import org.mirrentools.sd.constant.CommonConstant; 7 | import org.mirrentools.sd.constant.MySqlConstant; 8 | import org.mirrentools.sd.impl.ScrewDriverCodeImpl; 9 | import org.mirrentools.sd.models.SdBean; 10 | import org.mirrentools.sd.models.SdTemplate; 11 | import org.mirrentools.sd.options.ScrewDriverOptions; 12 | 13 | /** 14 | * FreeMarker模板生成文件的测试 15 | * 16 | * @author Mirren 17 | * 18 | */ 19 | public class CodeUtilByFreeMarkerTest { 20 | public static void main(String[] args) { 21 | // 创建一个实体描述 22 | SdBean bean = MySqlConstant.studentBean; 23 | // 设置实体生成模板 24 | Map templates = CommonConstant.templates; 25 | 26 | // 初始化代码执行生成工具 27 | ScrewDriverCode codeUtil = new ScrewDriverCodeImpl(new ScrewDriverOptions( MySqlConstant.databaseOptions)); 28 | codeUtil.execute(bean,templates); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/util/ScrewDriverMySQLTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.util; 2 | 3 | import org.mirrentools.sd.ScrewDriver; 4 | import org.mirrentools.sd.SdType; 5 | import org.mirrentools.sd.constant.MySqlConstant; 6 | import org.mirrentools.sd.models.SdBean; 7 | import org.mirrentools.sd.models.SdColumn; 8 | import org.mirrentools.sd.options.ScrewDriverOptions; 9 | 10 | public class ScrewDriverMySQLTest { 11 | 12 | public static void main(String[] args) { 13 | ScrewDriverOptions options = new ScrewDriverOptions(MySqlConstant.databaseOptions); 14 | ScrewDriver driver = ScrewDriver.instance(options); 15 | boolean deleteTable = driver.deleteTable(MySqlConstant.classesBean); 16 | System.out.println("deleteTable: " + deleteTable); 17 | boolean createTable = driver.createTable(MySqlConstant.classesBean); 18 | System.out.println("createTable: " + createTable); 19 | SdBean bean = new SdBean().setName("classes"); 20 | bean.addColumn(new SdColumn().setName("alteradd").setType(SdType.INTEGER)); 21 | boolean updateTable = driver.updateTable(bean); 22 | System.out.println("updateTable: " + updateTable); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/util/ScrewDriverPostgreSQLTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.util; 2 | 3 | import org.mirrentools.sd.constant.PostgreSQL; 4 | import org.mirrentools.sd.constant.PostgreSqlConstant; 5 | import org.mirrentools.sd.impl.ScrewDriverSqlImpl; 6 | import org.mirrentools.sd.options.ScrewDriverOptions; 7 | import org.mirrentools.sd.options.SdDatabaseOptions; 8 | 9 | public class ScrewDriverPostgreSQLTest { 10 | /** 数据库配置文件 */ 11 | SdDatabaseOptions config; 12 | 13 | public static void main(String[] args) { 14 | ScrewDriverPostgreSQLTest test = new ScrewDriverPostgreSQLTest(); 15 | test.setUp(); 16 | test.testCreateClasses(); 17 | test.testCreateStudent(); 18 | } 19 | 20 | public void setUp() { 21 | config = new SdDatabaseOptions(PostgreSQL.POSTGRE_SQL_DERVER, "jdbc:postgresql://localhost:5432/item"); 22 | config.setUser("postgres"); 23 | config.setPassword("root"); 24 | } 25 | 26 | public void testCreateClasses() { 27 | boolean execute = new ScrewDriverSqlImpl(new ScrewDriverOptions(config)).createTable(PostgreSqlConstant.classesBean); 28 | System.out.println("SQL执行结果:" + execute); 29 | } 30 | 31 | public void testCreateStudent() { 32 | boolean execute = new ScrewDriverSqlImpl(new ScrewDriverOptions(config)).createTable(PostgreSqlConstant.studentBean); 33 | System.out.println("SQL执行结果:" + execute); 34 | } 35 | 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/util/ScrewDriverSqlServerTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.util; 2 | 3 | import org.mirrentools.sd.ScrewDriver; 4 | import org.mirrentools.sd.constant.SqlServerConstant; 5 | import org.mirrentools.sd.options.ScrewDriverOptions; 6 | 7 | public class ScrewDriverSqlServerTest { 8 | 9 | public static void main(String[] args) { 10 | ScrewDriverOptions options = new ScrewDriverOptions(SqlServerConstant.databaseOptions); 11 | ScrewDriver driver = ScrewDriver.instance(options); 12 | boolean deleteTable = driver.deleteTable(SqlServerConstant.classesBean); 13 | System.out.println("deleteTable: " + deleteTable); 14 | boolean createTable = driver.createTable(SqlServerConstant.classesBean); 15 | System.out.println("createTable: " + createTable); 16 | boolean createTable1 = driver.createTable(SqlServerConstant.studentBean); 17 | System.out.println("createTable: " + createTable1); 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/org/mirrentools/sd/util/ScrewDriverSqliteTest.java: -------------------------------------------------------------------------------- 1 | package org.mirrentools.sd.util; 2 | 3 | import org.mirrentools.sd.constant.SQLite; 4 | import org.mirrentools.sd.constant.SqliteConstant; 5 | import org.mirrentools.sd.impl.ScrewDriverSqlImpl; 6 | import org.mirrentools.sd.options.ScrewDriverOptions; 7 | import org.mirrentools.sd.options.SdDatabaseOptions; 8 | 9 | public class ScrewDriverSqliteTest { 10 | /** 数据库配置文件 */ 11 | SdDatabaseOptions config; 12 | 13 | public static void main(String[] args) { 14 | ScrewDriverSqliteTest test = new ScrewDriverSqliteTest(); 15 | test.setUp(); 16 | test.testCreateClasses(); 17 | test.testCreateStudent(); 18 | } 19 | 20 | public void setUp() { 21 | config = new SdDatabaseOptions(SQLite.SQLITE_DERVER, "jdbc:sqlite:D:/tempProject/item.db"); 22 | } 23 | 24 | public void testCreateClasses() { 25 | boolean execute = new ScrewDriverSqlImpl(new ScrewDriverOptions(config)).createTable(SqliteConstant.classesBean); 26 | System.out.println("SQL执行结果:" + execute); 27 | } 28 | 29 | public void testCreateStudent() { 30 | boolean execute = new ScrewDriverSqlImpl(new ScrewDriverOptions(config)).createTable(SqliteConstant.studentBean); 31 | System.out.println("SQL执行结果:" + execute); 32 | } 33 | 34 | } 35 | --------------------------------------------------------------------------------