瀏覽代碼

部分代码优化

Caratacus 8 年之前
父節點
當前提交
bdeef3abed

+ 5 - 8
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisConfiguration.java

@@ -15,19 +15,16 @@
  */
 package com.baomidou.mybatisplus;
 
-import java.util.Set;
-import java.util.concurrent.ConcurrentSkipListSet;
-import java.util.logging.Logger;
-
+import com.baomidou.mybatisplus.mapper.AutoSqlInjector;
+import com.baomidou.mybatisplus.mapper.DBType;
+import com.baomidou.mybatisplus.mapper.IMetaObjectHandler;
+import com.baomidou.mybatisplus.mapper.ISqlInjector;
 import org.apache.ibatis.binding.MapperRegistry;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.session.Configuration;
 import org.apache.ibatis.session.SqlSession;
 
-import com.baomidou.mybatisplus.mapper.AutoSqlInjector;
-import com.baomidou.mybatisplus.mapper.DBType;
-import com.baomidou.mybatisplus.mapper.IMetaObjectHandler;
-import com.baomidou.mybatisplus.mapper.ISqlInjector;
+import java.util.logging.Logger;
 
 /**
  * <p>

+ 4 - 8
mybatis-plus/src/main/java/com/baomidou/mybatisplus/MybatisPulsMapperRegistry.java

@@ -15,20 +15,16 @@
  */
 package com.baomidou.mybatisplus;
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.ibatis.binding.BindingException;
 import org.apache.ibatis.binding.MapperProxyFactory;
 import org.apache.ibatis.binding.MapperRegistry;
-import org.apache.ibatis.io.ResolverUtil;
 import org.apache.ibatis.session.Configuration;
 import org.apache.ibatis.session.SqlSession;
 
-import com.baomidou.mybatisplus.MybatisPlusMapperBuilder;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * 继承至MapperRegistry

+ 11 - 13
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/AutoSqlInjector.java

@@ -15,13 +15,12 @@
  */
 package com.baomidou.mybatisplus.mapper;
 
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Logger;
-
+import com.baomidou.mybatisplus.MybatisConfiguration;
+import com.baomidou.mybatisplus.annotations.FieldStrategy;
+import com.baomidou.mybatisplus.annotations.IdType;
+import com.baomidou.mybatisplus.toolkit.TableFieldInfo;
+import com.baomidou.mybatisplus.toolkit.TableInfo;
+import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
 import org.apache.ibatis.builder.MapperBuilderAssistant;
 import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
 import org.apache.ibatis.executor.keygen.KeyGenerator;
@@ -34,12 +33,11 @@ import org.apache.ibatis.scripting.LanguageDriver;
 import org.apache.ibatis.scripting.defaults.RawSqlSource;
 import org.apache.ibatis.session.Configuration;
 
-import com.baomidou.mybatisplus.MybatisConfiguration;
-import com.baomidou.mybatisplus.annotations.FieldStrategy;
-import com.baomidou.mybatisplus.annotations.IdType;
-import com.baomidou.mybatisplus.toolkit.TableFieldInfo;
-import com.baomidou.mybatisplus.toolkit.TableInfo;
-import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
 
 /**
  * <p>

+ 1 - 1
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/IMetaObjectHandler.java

@@ -32,7 +32,7 @@ public interface IMetaObjectHandler {
 	 * 插入元对象字段填充
 	 * </p>
 	 * 
-	 * @param Object
+	 * @param metaObject
 	 *            元对象
 	 * @return
 	 */

+ 16 - 19
mybatis-plus/src/main/java/com/baomidou/mybatisplus/spring/MybatisSqlSessionFactoryBean.java

@@ -15,18 +15,12 @@
  */
 package com.baomidou.mybatisplus.spring;
 
-import static org.springframework.util.Assert.notNull;
-import static org.springframework.util.Assert.state;
-import static org.springframework.util.ObjectUtils.isEmpty;
-import static org.springframework.util.StringUtils.hasLength;
-import static org.springframework.util.StringUtils.tokenizeToStringArray;
-
-import java.io.IOException;
-import java.sql.SQLException;
-import java.util.Properties;
-
-import javax.sql.DataSource;
-
+import com.baomidou.mybatisplus.MybatisConfiguration;
+import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
+import com.baomidou.mybatisplus.mapper.DBType;
+import com.baomidou.mybatisplus.mapper.IMetaObjectHandler;
+import com.baomidou.mybatisplus.mapper.ISqlInjector;
+import com.baomidou.mybatisplus.toolkit.PackageHelper;
 import org.apache.ibatis.builder.xml.XMLConfigBuilder;
 import org.apache.ibatis.builder.xml.XMLMapperBuilder;
 import org.apache.ibatis.cache.Cache;
@@ -55,13 +49,16 @@ import org.springframework.core.NestedIOException;
 import org.springframework.core.io.Resource;
 import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
 
-import com.baomidou.mybatisplus.MybatisConfiguration;
-import com.baomidou.mybatisplus.MybatisXMLConfigBuilder;
-import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
-import com.baomidou.mybatisplus.mapper.DBType;
-import com.baomidou.mybatisplus.mapper.IMetaObjectHandler;
-import com.baomidou.mybatisplus.mapper.ISqlInjector;
-import com.baomidou.mybatisplus.toolkit.PackageHelper;
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import static org.springframework.util.Assert.notNull;
+import static org.springframework.util.Assert.state;
+import static org.springframework.util.ObjectUtils.isEmpty;
+import static org.springframework.util.StringUtils.hasLength;
+import static org.springframework.util.StringUtils.tokenizeToStringArray;
 
 /**
  * <p>

+ 77 - 71
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/ReflectionKit.java

@@ -32,83 +32,89 @@ import java.util.List;
  */
 public class ReflectionKit {
 
-    private static Logger logger = LoggerFactory.getLogger(ReflectionKit.class);
+	private static Logger logger = LoggerFactory.getLogger(ReflectionKit.class);
 
-    /**
-     * <p>
-     * 反射 method 方法名,例如 getId
-     * </p>
-     *
-     * @param str 属性字符串内容
-     * @return
-     */
-    public static String getMethodCapitalize(final String str) {
-        return StringUtils.concatCapitalize("get", str);
-    }
+	/**
+	 * <p>
+	 * 反射 method 方法名,例如 getId
+	 * </p>
+	 *
+	 * @param str
+	 *            属性字符串内容
+	 * @return
+	 */
+	public static String getMethodCapitalize(final String str) {
+		return StringUtils.concatCapitalize("get", str);
+	}
 
-    /**
-     * 获取 public get方法的值
-     *
-     * @param cls
-     * @param entity 实体
-     * @param str    属性字符串内容
-     * @return Object
-     */
-    public static Object getMethodValue(Class<?> cls, Object entity, String str) {
-        Object obj = null;
-        try {
-            Method method = cls.getMethod(getMethodCapitalize(str));
-            obj = method.invoke(entity);
-        } catch (NoSuchMethodException e) {
-            logger.warn("Warn: No such method. in " + cls);
-        } catch (IllegalAccessException e) {
-            logger.warn("Warn: Cannot execute a private method. in " + cls);
-        } catch (InvocationTargetException e) {
-            logger.warn("Warn: Unexpected exception on getMethodValue.  Cause:" + e);
-        }
-        return obj;
-    }
+	/**
+	 * 获取 public get方法的值
+	 *
+	 * @param cls
+	 * @param entity
+	 *            实体
+	 * @param str
+	 *            属性字符串内容
+	 * @return Object
+	 */
+	public static Object getMethodValue(Class<?> cls, Object entity, String str) {
+		Object obj = null;
+		try {
+			Method method = cls.getMethod(getMethodCapitalize(str));
+			obj = method.invoke(entity);
+		} catch (NoSuchMethodException e) {
+			logger.warn("Warn: No such method. in " + cls + ".  Cause:" + e);
+		} catch (IllegalAccessException e) {
+			logger.warn("Warn: Cannot execute a private method. in " + cls + ".  Cause:" + e);
+		} catch (InvocationTargetException e) {
+			logger.warn("Warn: Unexpected exception on getMethodValue.  Cause:" + e);
+		}
+		return obj;
+	}
 
-    /**
-     * 获取 public get方法的值
-     *
-     * @param entity 实体
-     * @param str    属性字符串内容
-     * @return Object
-     */
-    public static Object getMethodValue(Object entity, String str) {
+	/**
+	 * 获取 public get方法的值
+	 *
+	 * @param entity
+	 *            实体
+	 * @param str
+	 *            属性字符串内容
+	 * @return Object
+	 */
+	public static Object getMethodValue(Object entity, String str) {
 		if (null == entity) {
 			return null;
 		}
-        return getMethodValue(entity.getClass(), entity, str);
-    }
+		return getMethodValue(entity.getClass(), entity, str);
+	}
 
-    /**
-     * 调用对象的get方法检查对象所有属性是否为null
-     *
-     * @param bean 检查对象
-     * @return boolean true对象所有属性不为null,false对象所有属性为null
-     */
-    public static boolean checkFieldValueNotNull(Object bean) {
-        if (null == bean) {
-            return false;
-        }
-        Class<?> cls = bean.getClass();
-        TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
-        if (null == tableInfo) {
-            logger.warn("Warn: Could not find @TableId.");
-            return false;
-        }
-        boolean result = false;
-        List<TableFieldInfo> fieldList = tableInfo.getFieldList();
-        for (TableFieldInfo tableFieldInfo : fieldList) {
-            Object val = getMethodValue(cls, bean, tableFieldInfo.getProperty());
-            if (null != val) {
-                result = true;
-                break;
-            }
-        }
-        return result;
-    }
+	/**
+	 * 调用对象的get方法检查对象所有属性是否为null
+	 *
+	 * @param bean
+	 *            检查对象
+	 * @return boolean true对象所有属性不为null,false对象所有属性为null
+	 */
+	public static boolean checkFieldValueNotNull(Object bean) {
+		if (null == bean) {
+			return false;
+		}
+		Class<?> cls = bean.getClass();
+		TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
+		if (null == tableInfo) {
+			logger.warn("Warn: Could not find @TableId.");
+			return false;
+		}
+		boolean result = false;
+		List<TableFieldInfo> fieldList = tableInfo.getFieldList();
+		for (TableFieldInfo tableFieldInfo : fieldList) {
+			Object val = getMethodValue(cls, bean, tableFieldInfo.getProperty());
+			if (null != val) {
+				result = true;
+				break;
+			}
+		}
+		return result;
+	}
 
 }

+ 1 - 1
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/StringUtils.java

@@ -61,7 +61,7 @@ public class StringUtils {
 	 * @return 判断结果
 	 */
 	public static boolean isNotEmpty(String str) {
-		return (str != null) && !EMPTY_STRING.equals(str.trim());
+		return !isEmpty(str);
 	}
 
 	/**