Browse Source

调整可重载

青苗 9 years ago
parent
commit
33598f4e94

+ 30 - 30
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/AutoGenerator.java

@@ -44,7 +44,7 @@ import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
  */
  */
 public class AutoGenerator {
 public class AutoGenerator {
 
 
-	private ConfigGenerator config;
+	protected ConfigGenerator config;
 
 
 	public ConfigGenerator getConfig() {
 	public ConfigGenerator getConfig() {
 		return config;
 		return config;
@@ -62,16 +62,16 @@ public class AutoGenerator {
 		this.config = config;
 		this.config = config;
 	}
 	}
 
 
-	private static String PATH_ENTITY = null;
-	private static String PATH_MAPPER = null;
-	private static String PATH_XML = null;
-	private static String PATH_SERVICE = null;
-	private static String PATH_SERVICE_IMPL = null;
+	protected static String PATH_ENTITY = null;
+	protected static String PATH_MAPPER = null;
+	protected static String PATH_XML = null;
+	protected static String PATH_SERVICE = null;
+	protected static String PATH_SERVICE_IMPL = null;
 
 
-	private static boolean FILE_OVERRIDE = false;
+	protected static boolean FILE_OVERRIDE = false;
 
 
-	private static final String JAVA_SUFFIX = ".java";
-	private static final String XML_SUFFIX = ".xml";
+	protected static final String JAVA_SUFFIX = ".java";
+	protected static final String XML_SUFFIX = ".xml";
 
 
 	/**
 	/**
 	 * run 执行
 	 * run 执行
@@ -140,7 +140,7 @@ public class AutoGenerator {
 	 * @param packageName
 	 * @param packageName
 	 * @return
 	 * @return
 	 */
 	 */
-	private static String getPathFromPackageName(String packageName) {
+	protected static String getPathFromPackageName(String packageName) {
 		if (null == packageName || "".equals(packageName)) {
 		if (null == packageName || "".equals(packageName)) {
 			return "";
 			return "";
 		}
 		}
@@ -154,7 +154,7 @@ public class AutoGenerator {
 	 *            文件地址片段
 	 *            文件地址片段
 	 * @return
 	 * @return
 	 */
 	 */
-	private static String getFilePath(String savePath, String segment) {
+	protected static String getFilePath(String savePath, String segment) {
 		File folder = new File(savePath + File.separator + segment);
 		File folder = new File(savePath + File.separator + segment);
 		if (!folder.exists()) {
 		if (!folder.exists()) {
 			folder.mkdirs();
 			folder.mkdirs();
@@ -275,7 +275,7 @@ public class AutoGenerator {
 	 * @param suffix
 	 * @param suffix
 	 * @return
 	 * @return
 	 */
 	 */
-	private boolean valideFile(String dirPath, String beanName, String suffix) {
+	protected boolean valideFile(String dirPath, String beanName, String suffix) {
 		File file = new File(dirPath, beanName + suffix);
 		File file = new File(dirPath, beanName + suffix);
 		return !file.exists() || FILE_OVERRIDE;
 		return !file.exists() || FILE_OVERRIDE;
 	}
 	}
@@ -291,7 +291,7 @@ public class AutoGenerator {
 	 * @return
 	 * @return
 	 * @throws SQLException
 	 * @throws SQLException
 	 */
 	 */
-	private List<String> getTables(Connection conn) throws SQLException {
+	protected List<String> getTables(Connection conn) throws SQLException {
 		List<String> tables = new ArrayList<String>();
 		List<String> tables = new ArrayList<String>();
 		PreparedStatement pstate = conn.prepareStatement(config.getConfigDataSource().getTablesSql());
 		PreparedStatement pstate = conn.prepareStatement(config.getConfigDataSource().getTablesSql());
 		ResultSet results = pstate.executeQuery();
 		ResultSet results = pstate.executeQuery();
@@ -327,7 +327,7 @@ public class AutoGenerator {
 	 *            表名
 	 *            表名
 	 * @return beanName
 	 * @return beanName
 	 */
 	 */
-	private String getBeanName(String table, boolean includePrefix) {
+	protected String getBeanName(String table, boolean includePrefix) {
 		StringBuilder sb = new StringBuilder();
 		StringBuilder sb = new StringBuilder();
 		if (table.contains("_")) {
 		if (table.contains("_")) {
 			String[] tables = table.split("_");
 			String[] tables = table.split("_");
@@ -346,7 +346,7 @@ public class AutoGenerator {
 		return sb.toString();
 		return sb.toString();
 	}
 	}
 
 
-	private String processType(String type) {
+	protected String processType(String type) {
 		if (config.getConfigDataSource() == ConfigDataSource.ORACLE) {
 		if (config.getConfigDataSource() == ConfigDataSource.ORACLE) {
 			return oracleProcessType(type);
 			return oracleProcessType(type);
 		}
 		}
@@ -360,7 +360,7 @@ public class AutoGenerator {
 	 *            字段类型
 	 *            字段类型
 	 * @return
 	 * @return
 	 */
 	 */
-	private String mysqlProcessType(String type) {
+	protected String mysqlProcessType(String type) {
 		if (type.contains("char")) {
 		if (type.contains("char")) {
 			return "String";
 			return "String";
 		} else if (type.contains("bigint")) {
 		} else if (type.contains("bigint")) {
@@ -392,7 +392,7 @@ public class AutoGenerator {
 	 *            字段类型
 	 *            字段类型
 	 * @return
 	 * @return
 	 */
 	 */
-	private String oracleProcessType(String type) {
+	protected String oracleProcessType(String type) {
 		if (type.contains("CHAR")) {
 		if (type.contains("CHAR")) {
 			return "String";
 			return "String";
 		} else if (type.contains("DATE") || type.contains("TIMESTAMP")) {
 		} else if (type.contains("DATE") || type.contains("TIMESTAMP")) {
@@ -416,7 +416,7 @@ public class AutoGenerator {
 	 *            字段类型列表
 	 *            字段类型列表
 	 * @return
 	 * @return
 	 */
 	 */
-	private boolean isDate(List<String> types) {
+	protected boolean isDate(List<String> types) {
 		for (String type : types) {
 		for (String type : types) {
 			if (type.contains("date") || type.contains("timestamp")) {
 			if (type.contains("date") || type.contains("timestamp")) {
 				return true;
 				return true;
@@ -432,7 +432,7 @@ public class AutoGenerator {
 	 *            字段类型列表
 	 *            字段类型列表
 	 * @return
 	 * @return
 	 */
 	 */
-	private boolean isDecimal(List<String> types) {
+	protected boolean isDecimal(List<String> types) {
 		for (String type : types) {
 		for (String type : types) {
 			if (type.contains("decimal")) {
 			if (type.contains("decimal")) {
 				return true;
 				return true;
@@ -441,7 +441,7 @@ public class AutoGenerator {
 		return false;
 		return false;
 	}
 	}
 
 
-	private String processField(String field) {
+	protected String processField(String field) {
 		/*
 		/*
 		 * 驼峰命名直接返回
 		 * 驼峰命名直接返回
 		 */
 		 */
@@ -471,7 +471,7 @@ public class AutoGenerator {
 	 * @return
 	 * @return
 	 * @throws IOException
 	 * @throws IOException
 	 */
 	 */
-	private BufferedWriter buildClassComment(BufferedWriter bw, String text) throws IOException {
+	protected BufferedWriter buildClassComment(BufferedWriter bw, String text) throws IOException {
 		bw.newLine();
 		bw.newLine();
 		bw.write("/**");
 		bw.write("/**");
 		bw.newLine();
 		bw.newLine();
@@ -493,7 +493,7 @@ public class AutoGenerator {
 	 * @param comments
 	 * @param comments
 	 * @throws IOException
 	 * @throws IOException
 	 */
 	 */
-	private void buildEntityBean(List<String> columns, List<String> types, List<String> comments, String tableComment,
+	protected void buildEntityBean(List<String> columns, List<String> types, List<String> comments, String tableComment,
 			Map<String, IdInfo> idMap, String table, String beanName) throws IOException {
 			Map<String, IdInfo> idMap, String table, String beanName) throws IOException {
 		File beanFile = new File(PATH_ENTITY, beanName + ".java");
 		File beanFile = new File(PATH_ENTITY, beanName + ".java");
 		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(beanFile)));
 		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(beanFile)));
@@ -533,7 +533,7 @@ public class AutoGenerator {
 		bw.newLine();
 		bw.newLine();
 		bw.write("\t@TableField(exist = false)");
 		bw.write("\t@TableField(exist = false)");
 		bw.newLine();
 		bw.newLine();
-		bw.write("\tprivate static final long serialVersionUID = 1L;");
+		bw.write("\tprotected static final long serialVersionUID = 1L;");
 		bw.newLine();
 		bw.newLine();
 		int size = columns.size();
 		int size = columns.size();
 		for (int i = 0; i < size; i++) {
 		for (int i = 0; i < size; i++) {
@@ -578,7 +578,7 @@ public class AutoGenerator {
 				bw.write("\t@TableField(value = \"" + column + "\")");
 				bw.write("\t@TableField(value = \"" + column + "\")");
 				bw.newLine();
 				bw.newLine();
 			}
 			}
-			bw.write("\tprivate " + processType(types.get(i)) + " " + field + ";");
+			bw.write("\tprotected " + processType(types.get(i)) + " " + field + ";");
 			bw.newLine();
 			bw.newLine();
 		}
 		}
 
 
@@ -630,7 +630,7 @@ public class AutoGenerator {
 	 * @param mapperName
 	 * @param mapperName
 	 * @throws IOException
 	 * @throws IOException
 	 */
 	 */
-	private void buildMapper(String beanName, String mapperName) throws IOException {
+	protected void buildMapper(String beanName, String mapperName) throws IOException {
 		File mapperFile = new File(PATH_MAPPER, mapperName + ".java");
 		File mapperFile = new File(PATH_MAPPER, mapperName + ".java");
 		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapperFile), "utf-8"));
 		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapperFile), "utf-8"));
 		bw.write("package " + config.getMapperPackage() + ";");
 		bw.write("package " + config.getMapperPackage() + ";");
@@ -670,7 +670,7 @@ public class AutoGenerator {
 	 * @param comments
 	 * @param comments
 	 * @throws IOException
 	 * @throws IOException
 	 */
 	 */
-	private void buildMapperXml(List<String> columns, List<String> types, List<String> comments,
+	protected void buildMapperXml(List<String> columns, List<String> types, List<String> comments,
 			Map<String, IdInfo> idMap, String mapperName) throws IOException {
 			Map<String, IdInfo> idMap, String mapperName) throws IOException {
 		File mapperXmlFile = new File(PATH_XML, mapperName + ".xml");
 		File mapperXmlFile = new File(PATH_XML, mapperName + ".xml");
 		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapperXmlFile)));
 		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapperXmlFile)));
@@ -700,7 +700,7 @@ public class AutoGenerator {
 	 * @param serviceName
 	 * @param serviceName
 	 * @throws IOException
 	 * @throws IOException
 	 */
 	 */
-	private void buildService(String beanName, String serviceName) throws IOException {
+	protected void buildService(String beanName, String serviceName) throws IOException {
 		File serviceFile = new File(PATH_SERVICE, serviceName + ".java");
 		File serviceFile = new File(PATH_SERVICE, serviceName + ".java");
 		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(serviceFile), "utf-8"));
 		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(serviceFile), "utf-8"));
 		bw.write("package " + config.getServicePackage() + ";");
 		bw.write("package " + config.getServicePackage() + ";");
@@ -740,7 +740,7 @@ public class AutoGenerator {
 	 * @param mapperName
 	 * @param mapperName
 	 * @throws IOException
 	 * @throws IOException
 	 */
 	 */
-	private void buildServiceImpl(String beanName, String serviceImplName, String serviceName, String mapperName)
+	protected void buildServiceImpl(String beanName, String serviceImplName, String serviceName, String mapperName)
 			throws IOException {
 			throws IOException {
 		File serviceFile = new File(PATH_SERVICE_IMPL, serviceImplName + ".java");
 		File serviceFile = new File(PATH_SERVICE_IMPL, serviceImplName + ".java");
 		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(serviceFile), "utf-8"));
 		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(serviceFile), "utf-8"));
@@ -786,7 +786,7 @@ public class AutoGenerator {
 	 * @param columns
 	 * @param columns
 	 * @throws IOException
 	 * @throws IOException
 	 */
 	 */
-	private void buildSQL(BufferedWriter bw, Map<String, IdInfo> idMap, List<String> columns) throws IOException {
+	protected void buildSQL(BufferedWriter bw, Map<String, IdInfo> idMap, List<String> columns) throws IOException {
 		int size = columns.size();
 		int size = columns.size();
 		bw.write("\t<!-- 通用查询结果列-->");
 		bw.write("\t<!-- 通用查询结果列-->");
 		bw.newLine();
 		bw.newLine();
@@ -823,7 +823,7 @@ public class AutoGenerator {
 	 * @return
 	 * @return
 	 * @throws SQLException
 	 * @throws SQLException
 	 */
 	 */
-	private Map<String, String> getTableComment(Connection conn) throws SQLException {
+	protected Map<String, String> getTableComment(Connection conn) throws SQLException {
 		Map<String, String> maps = new HashMap<String, String>();
 		Map<String, String> maps = new HashMap<String, String>();
 		PreparedStatement pstate = conn.prepareStatement(config.getConfigDataSource().getTableCommentsSql());
 		PreparedStatement pstate = conn.prepareStatement(config.getConfigDataSource().getTableCommentsSql());
 		ResultSet results = pstate.executeQuery();
 		ResultSet results = pstate.executeQuery();

+ 7 - 28
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/ConfigDataSource.java

@@ -24,8 +24,7 @@ package com.baomidou.mybatisplus.generator;
  * @Date 2016-04-25
  * @Date 2016-04-25
  */
  */
 public enum ConfigDataSource {
 public enum ConfigDataSource {
-	MYSQL("mysql", "show tables", "show table status", "show full fields from %s", "NAME", "COMMENT"
-		,"FIELD","TYPE","COMMENT","KEY"), 
+	MYSQL("mysql", "show tables", "show table status", "show full fields from %s", "NAME", "COMMENT" ,"FIELD","TYPE","COMMENT","KEY"), 
 	ORACLE("oracle", "SELECT * FROM USER_TABLES", "SELECT * FROM USER_TAB_COMMENTS",
 	ORACLE("oracle", "SELECT * FROM USER_TABLES", "SELECT * FROM USER_TAB_COMMENTS",
 			"SELECT A.COLUMN_NAME, A.DATA_TYPE, B.COMMENTS  FROM USER_TAB_COLUMNS A, USER_COL_COMMENTS B WHERE A.TABLE_NAME=B.TABLE_NAME AND A.COLUMN_NAME = B.COLUMN_NAME AND A.TABLE_NAME='%s'",
 			"SELECT A.COLUMN_NAME, A.DATA_TYPE, B.COMMENTS  FROM USER_TAB_COLUMNS A, USER_COL_COMMENTS B WHERE A.TABLE_NAME=B.TABLE_NAME AND A.COLUMN_NAME = B.COLUMN_NAME AND A.TABLE_NAME='%s'",
 			"TABLE_NAME", "COMMENTS" ,"COLUMN_NAME","DATA_TYPE","COMMENTS","COLUMN_NAME");
 			"TABLE_NAME", "COMMENTS" ,"COLUMN_NAME","DATA_TYPE","COMMENTS","COLUMN_NAME");
@@ -41,18 +40,9 @@ public enum ConfigDataSource {
 	private final String fieldComment;
 	private final String fieldComment;
 	private final String fieldKey;
 	private final String fieldKey;
 
 
-
-	ConfigDataSource(
-			final String db,
-			final String tablesSql,
-			final String tableCommentsSql,
-			final String tableFieldsSql,
-			final String tableName,
-			final String tableComment,
-			final String fieldName,
-			final String fieldType,
-			final String fieldComment,
-			final String fieldKey ) {
+	ConfigDataSource(final String db, final String tablesSql, final String tableCommentsSql,
+			final String tableFieldsSql, final String tableName, final String tableComment, final String fieldName,
+			final String fieldType, final String fieldComment, final String fieldKey) {
 		this.db = db;
 		this.db = db;
 		this.tablesSql = tablesSql;
 		this.tablesSql = tablesSql;
 		this.tableCommentsSql = tableCommentsSql;
 		this.tableCommentsSql = tableCommentsSql;
@@ -65,7 +55,6 @@ public enum ConfigDataSource {
 		this.fieldKey = fieldKey;
 		this.fieldKey = fieldKey;
 	}
 	}
 
 
-
 	/**
 	/**
 	 * <p>
 	 * <p>
 	 * 获取数据库类型(默认 MySql)
 	 * 获取数据库类型(默认 MySql)
@@ -75,61 +64,51 @@ public enum ConfigDataSource {
 	 *            数据库类型字符串
 	 *            数据库类型字符串
 	 * @return
 	 * @return
 	 */
 	 */
-	public static ConfigDataSource getConfigDataSource( String dbType ) {
-		for ( ConfigDataSource dt : ConfigDataSource.values() ) {
-			if ( dt.getDb().equals(dbType) ) {
+	public static ConfigDataSource getConfigDataSource(String dbType) {
+		for (ConfigDataSource dt : ConfigDataSource.values()) {
+			if (dt.getDb().equals(dbType)) {
 				return dt;
 				return dt;
 			}
 			}
 		}
 		}
 		return MYSQL;
 		return MYSQL;
 	}
 	}
 
 
-
 	public String getDb() {
 	public String getDb() {
 		return db;
 		return db;
 	}
 	}
 
 
-
 	public String getTablesSql() {
 	public String getTablesSql() {
 		return tablesSql;
 		return tablesSql;
 	}
 	}
 
 
-
 	public String getTableCommentsSql() {
 	public String getTableCommentsSql() {
 		return tableCommentsSql;
 		return tableCommentsSql;
 	}
 	}
 
 
-
 	public String getTableFieldsSql() {
 	public String getTableFieldsSql() {
 		return tableFieldsSql;
 		return tableFieldsSql;
 	}
 	}
 
 
-
 	public String getTableName() {
 	public String getTableName() {
 		return tableName;
 		return tableName;
 	}
 	}
 
 
-
 	public String getTableComment() {
 	public String getTableComment() {
 		return tableComment;
 		return tableComment;
 	}
 	}
 
 
-
 	public String getFieldName() {
 	public String getFieldName() {
 		return fieldName;
 		return fieldName;
 	}
 	}
 
 
-
 	public String getFieldType() {
 	public String getFieldType() {
 		return fieldType;
 		return fieldType;
 	}
 	}
 
 
-
 	public String getFieldComment() {
 	public String getFieldComment() {
 		return fieldComment;
 		return fieldComment;
 	}
 	}
 
 
-
 	public String getFieldKey() {
 	public String getFieldKey() {
 		return fieldKey;
 		return fieldKey;
 	}
 	}

+ 21 - 21
mybatis-plus/src/main/java/com/baomidou/mybatisplus/generator/ConfigGenerator.java

@@ -46,60 +46,60 @@ import com.baomidou.mybatisplus.annotations.IdType;
  */
  */
 public class ConfigGenerator {
 public class ConfigGenerator {
 
 
-	private String saveDir;
+	protected String saveDir;
 
 
-	private String entityPackage;
+	protected String entityPackage;
 
 
-	private String mapperPackage;
+	protected String mapperPackage;
 
 
-	private String xmlPackage;
+	protected String xmlPackage;
 
 
-	private String servicePackage;
+	protected String servicePackage;
 
 
-	private String serviceImplPackage;
+	protected String serviceImplPackage;
 
 
-	private String superServiceImpl;
+	protected String superServiceImpl;
 
 
 	/*
 	/*
 	 * 自定义 mapperName serviceName serviceImplName
 	 * 自定义 mapperName serviceName serviceImplName
 	 */
 	 */
-	private String mapperName = "%sMapper";
+	protected String mapperName = "%sMapper";
 
 
-	private String serviceName = "I%sService";
+	protected String serviceName = "I%sService";
 
 
-	private String serviceImplName = "%sServiceImpl";
+	protected String serviceImplName = "%sServiceImpl";
 
 
 	/*
 	/*
 	 * 指定生成表名
 	 * 指定生成表名
 	 */
 	 */
-	private String[] tableNames = null;
+	protected String[] tableNames = null;
 
 
 	/*
 	/*
 	 * 是否覆盖当前路径下已有文件(默认 true)
 	 * 是否覆盖当前路径下已有文件(默认 true)
 	 */
 	 */
-	private boolean fileOverride = true;
+	protected boolean fileOverride = true;
 
 
 	/* db_config */
 	/* db_config */
-	private boolean dbPrefix = false;
+	protected boolean dbPrefix = false;
 
 
 	/*
 	/*
 	 * 数据库字段使用下划线命名(默认 false)
 	 * 数据库字段使用下划线命名(默认 false)
 	 */
 	 */
-	private boolean dbColumnUnderline = false;
+	protected boolean dbColumnUnderline = false;
 
 
-	private String dbDriverName;
+	protected String dbDriverName;
 
 
-	private String dbUser;
+	protected String dbUser;
 
 
-	private String dbPassword;
+	protected String dbPassword;
 
 
-	private String dbUrl;
+	protected String dbUrl;
 
 
-	private IdType idType = null;
+	protected IdType idType = null;
 
 
-	private ConfigDataSource configDataSource = ConfigDataSource.MYSQL;
+	protected ConfigDataSource configDataSource = ConfigDataSource.MYSQL;
 
 
-	private ConfigIdType configIdType = ConfigIdType.LONG;
+	protected ConfigIdType configIdType = ConfigIdType.LONG;
 
 
 	public String getSaveDir() {
 	public String getSaveDir() {
 		return saveDir;
 		return saveDir;