Caratacus vor 8 Jahren
Ursprung
Commit
4a7b95b912

+ 6 - 5
mybatis-plus/src/main/java/com/baomidou/framework/service/impl/ServiceImpl.java

@@ -28,13 +28,14 @@ import com.baomidou.mybatisplus.toolkit.StringUtils;
 import com.baomidou.mybatisplus.toolkit.TableInfo;
 import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
 import org.apache.ibatis.jdbc.SQL;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 import org.apache.ibatis.session.SqlSession;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
-import java.util.logging.Logger;
 
 /**
  * <p>
@@ -46,7 +47,7 @@ import java.util.logging.Logger;
  */
 public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
 
-	protected static final Logger logger = Logger.getLogger("ServiceImpl");
+	private static final Log logger = LogFactory.getLog(ServiceImpl.class);
 
 	@Autowired
 	protected M baseMapper;
@@ -163,7 +164,7 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
 			}
 			batchSqlSession.flushStatements();
 		} catch (Exception e) {
-			logger.warning("Error: Cannot execute insertBatch Method. Cause:" + e);
+			logger.warn("Error: Cannot execute insertBatch Method. Cause:" + e);
 			return false;
 		}
 		return true;
@@ -209,7 +210,7 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
 			}
 			batchSqlSession.flushStatements();
 		} catch (Exception e) {
-			logger.warning("Error: Cannot execute insertBatch Method. Cause:" + e);
+			logger.warn("Error: Cannot execute insertBatch Method. Cause:" + e);
 			return false;
 		}
 		return true;
@@ -232,7 +233,7 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
 		if (CollectionUtil.isNotEmpty(list)) {
 			int size = list.size();
 			if (size > 1) {
-				logger.warning(String.format("Warn: selectOne Method There are  %s results.", size));
+				logger.warn(String.format("Warn: selectOne Method There are  %s results.", size));
 			}
 			return list.get(0);
 		}

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

@@ -21,13 +21,14 @@ 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.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.session.Configuration;
 import org.apache.ibatis.session.SqlSession;
 
 import java.util.Set;
 import java.util.concurrent.ConcurrentSkipListSet;
-import java.util.logging.Logger;
 
 /**
  * <p>
@@ -42,7 +43,7 @@ import java.util.logging.Logger;
  */
 public class MybatisConfiguration extends Configuration {
 
-	protected final Logger logger = Logger.getLogger("MybatisConfiguration");
+	private static final Log logger = LogFactory.getLog(MybatisConfiguration.class);
 
 	/*
 	 * 数据库类型(默认 MySql)
@@ -103,7 +104,7 @@ public class MybatisConfiguration extends Configuration {
 	 */
 	@Override
 	public void addMappedStatement(MappedStatement ms) {
-		logger.fine(" addMappedStatement: " + ms.getId());
+		logger.debug(" addMappedStatement: " + ms.getId());
 		if (IS_REFRESH) {
 			/*
 			 * 支持是否自动刷新 XML 变更内容,开发环境使用【 注:生产环境勿用!】
@@ -114,7 +115,7 @@ public class MybatisConfiguration extends Configuration {
 				/*
 				 * 说明已加载了xml中的节点; 忽略mapper中的SqlProvider数据
 				 */
-				logger.severe("mapper[" + ms.getId() + "] is ignored, because it's exists, maybe from xml file");
+				logger.error("mapper[" + ms.getId() + "] is ignored, because it's exists, maybe from xml file");
 				return;
 			}
 		}

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

@@ -15,17 +15,19 @@
  */
 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.SqlReservedWords;
+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;
 import org.apache.ibatis.executor.keygen.NoKeyGenerator;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.mapping.SqlCommandType;
 import org.apache.ibatis.mapping.SqlSource;
@@ -34,14 +36,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.SqlReservedWords;
-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.Set;
 
 /**
  * <p>
@@ -52,7 +51,8 @@ import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
  * @Date 2016-09-09
  */
 public class AutoSqlInjector implements ISqlInjector {
-	protected static final Logger logger = Logger.getLogger("AutoSqlInjector");
+
+	private static final Log logger = LogFactory.getLog(AutoSqlInjector.class);
 
 	protected Configuration configuration;
 
@@ -126,7 +126,7 @@ public class AutoSqlInjector implements ISqlInjector {
 			/**
 			 * 警告
 			 */
-			logger.warning(String.format("%s ,Not found @TableId annotation, cannot use mybatis-plus curd method.",
+			logger.warn(String.format("%s ,Not found @TableId annotation, cannot use mybatis-plus curd method.",
 					modelClass.toString()));
 		}
 	}
@@ -135,7 +135,7 @@ public class AutoSqlInjector implements ISqlInjector {
 	 * 自定义方法,注入点(子类需重写该方法)
 	 */
 	public void inject(Configuration configuration, MapperBuilderAssistant builderAssistant, Class<?> mapperClass,
-					   Class<?> modelClass, TableInfo table) {
+			Class<?> modelClass, TableInfo table) {
 		// to do nothing
 	}
 
@@ -612,7 +612,7 @@ public class AutoSqlInjector implements ISqlInjector {
 	 * 查询
 	 */
 	public MappedStatement addSelectMappedStatement(Class<?> mapperClass, String id, SqlSource sqlSource, Class<?> resultType,
-													TableInfo table) {
+			TableInfo table) {
 		if (null != table) {
 			String resultMap = table.getResultMap();
 			if (null != resultMap) {
@@ -631,7 +631,7 @@ public class AutoSqlInjector implements ISqlInjector {
 	 * 插入
 	 */
 	public MappedStatement addInsertMappedStatement(Class<?> mapperClass, Class<?> modelClass, String id, SqlSource sqlSource,
-													KeyGenerator keyGenerator, String keyProperty, String keyColumn) {
+			KeyGenerator keyGenerator, String keyProperty, String keyColumn) {
 		return this.addMappedStatement(mapperClass, id, sqlSource, SqlCommandType.INSERT, modelClass, null, Integer.class,
 				keyGenerator, keyProperty, keyColumn);
 	}
@@ -653,8 +653,8 @@ public class AutoSqlInjector implements ISqlInjector {
 	}
 
 	public MappedStatement addMappedStatement(Class<?> mapperClass, String id, SqlSource sqlSource,
-											  SqlCommandType sqlCommandType, Class<?> parameterClass, String resultMap, Class<?> resultType,
-											  KeyGenerator keyGenerator, String keyProperty, String keyColumn) {
+			SqlCommandType sqlCommandType, Class<?> parameterClass, String resultMap, Class<?> resultType,
+			KeyGenerator keyGenerator, String keyProperty, String keyColumn) {
 		String statementName = mapperClass.getName() + "." + id;
 		if (configuration.hasStatement(statementName)) {
 			System.err.println("{" + statementName

+ 5 - 3
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/SqlExplainInterceptor.java

@@ -19,6 +19,8 @@ import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
 import com.baomidou.mybatisplus.toolkit.IOUtils;
 import org.apache.ibatis.builder.StaticSqlSource;
 import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 import org.apache.ibatis.mapping.BoundSql;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.mapping.SqlCommandType;
@@ -34,7 +36,6 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.util.Properties;
-import java.util.logging.Logger;
 
 /**
  * <p>
@@ -46,7 +47,8 @@ import java.util.logging.Logger;
  */
 @Intercepts({ @Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class }) })
 public class SqlExplainInterceptor implements Interceptor {
-	protected final Logger logger = Logger.getLogger("SqlExplainInterceptor");
+
+	private static final Log logger = LogFactory.getLog(SqlExplainInterceptor.class);
 
 	/**
 	 * 发现执行全表 delete update 语句是否停止执行
@@ -110,7 +112,7 @@ public class SqlExplainInterceptor implements Interceptor {
 					if (this.isStopProceed()) {
 						throw new MybatisPlusException(tip);
 					}
-					logger.severe(tip);
+					logger.error(tip);
 					break;
 				}
 			}

+ 7 - 6
mybatis-plus/src/main/java/com/baomidou/mybatisplus/spring/MybatisMapperRefresh.java

@@ -23,6 +23,8 @@ import org.apache.ibatis.builder.xml.XMLMapperEntityResolver;
 import org.apache.ibatis.executor.ErrorContext;
 import org.apache.ibatis.executor.keygen.SelectKeyGenerator;
 import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 import org.apache.ibatis.parsing.XNode;
 import org.apache.ibatis.parsing.XPathParser;
 import org.apache.ibatis.session.Configuration;
@@ -42,7 +44,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.logging.Logger;
 
 /**
  * <p>
@@ -55,7 +56,7 @@ import java.util.logging.Logger;
  * @Date 2016-08-25
  */
 public class MybatisMapperRefresh implements Runnable {
-	protected final Logger logger = Logger.getLogger("MybatisMapperRefresh");
+	private static final Log logger = LogFactory.getLog(MybatisMapperRefresh.class);
 	private SqlSessionFactory sqlSessionFactory;
 	private Resource[] mapperLocations;
 	private Long beforeTime = 0L;
@@ -118,7 +119,8 @@ public class MybatisMapperRefresh implements Runnable {
 						for (Resource mapperLocation : mapperLocations) {
 							try {
 								if (ResourceUtils.isJarURL(mapperLocation.getURL())) {
-									String key = new UrlResource(ResourceUtils.extractJarFileURL(mapperLocation.getURL())).getFile().getPath();
+									String key = new UrlResource(ResourceUtils.extractJarFileURL(mapperLocation.getURL()))
+											.getFile().getPath();
 									fileSet.add(key);
 									if (jarMapper.get(key) != null) {
 										jarMapper.get(key).add(mapperLocation);
@@ -185,8 +187,7 @@ public class MybatisMapperRefresh implements Runnable {
 		this.configuration = sqlSessionFactory.getConfiguration();
 		boolean isSupper = configuration.getClass().getSuperclass() == Configuration.class;
 		try {
-			Field loadedResourcesField = isSupper
-					? configuration.getClass().getSuperclass().getDeclaredField("loadedResources")
+			Field loadedResourcesField = isSupper ? configuration.getClass().getSuperclass().getDeclaredField("loadedResources")
 					: configuration.getClass().getDeclaredField("loadedResources");
 			loadedResourcesField.setAccessible(true);
 			Set loadedResourcesSet = ((Set) loadedResourcesField.get(configuration));
@@ -208,7 +209,7 @@ public class MybatisMapperRefresh implements Runnable {
 					sqlSessionFactory.getConfiguration(), // 注入的sql先不进行处理了
 					resource.toString(), sqlSessionFactory.getConfiguration().getSqlFragments());
 			xmlMapperBuilder.parse();
-			logger.fine("refresh:" + resource + ",success!");
+			logger.debug("refresh:" + resource + ",success!");
 		} catch (Exception e) {
 			throw new NestedIOException("Failed to parse mapping resource: '" + resource + "'", e);
 		} finally {

+ 10 - 11
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/ReflectionKit.java

@@ -16,13 +16,14 @@
 package com.baomidou.mybatisplus.toolkit;
 
 import com.baomidou.mybatisplus.annotations.FieldStrategy;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.List;
-import java.util.logging.Logger;
 
 /**
  * <p>
@@ -33,8 +34,7 @@ import java.util.logging.Logger;
  * @Date 2016-09-22
  */
 public class ReflectionKit {
-
-	protected static final Logger logger = Logger.getLogger("ReflectionKit");
+	private static final Log logger = LogFactory.getLog(ReflectionKit.class);
 
 	/**
 	 * <p>
@@ -65,11 +65,11 @@ public class ReflectionKit {
 			Method method = cls.getMethod(getMethodCapitalize(str));
 			obj = method.invoke(entity);
 		} catch (NoSuchMethodException e) {
-			logger.warning(String.format("Warn: No such method. in %s.  Cause:", cls.getSimpleName()) + e);
+			logger.warn(String.format("Warn: No such method. in %s.  Cause:", cls.getSimpleName()) + e);
 		} catch (IllegalAccessException e) {
-			logger.warning(String.format("Warn: Cannot execute a private method. in %s.  Cause:", cls.getSimpleName()) + e);
+			logger.warn(String.format("Warn: Cannot execute a private method. in %s.  Cause:", cls.getSimpleName()) + e);
 		} catch (InvocationTargetException e) {
-			logger.warning("Warn: Unexpected exception on getMethodValue.  Cause:" + e);
+			logger.warn("Warn: Unexpected exception on getMethodValue.  Cause:" + e);
 		}
 		return obj;
 	}
@@ -104,7 +104,7 @@ public class ReflectionKit {
 		Class<?> cls = bean.getClass();
 		TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
 		if (null == tableInfo) {
-			logger.warning("Warn: Could not find @TableId.");
+			logger.warn("Warn: Could not find @TableId.");
 			return false;
 		}
 		boolean result = false;
@@ -143,20 +143,19 @@ public class ReflectionKit {
 		Type genType = clazz.getGenericSuperclass();
 
 		if (!(genType instanceof ParameterizedType)) {
-			logger.warning(String.format("Warn: %s's superclass not ParameterizedType", clazz.getSimpleName()));
+			logger.warn(String.format("Warn: %s's superclass not ParameterizedType", clazz.getSimpleName()));
 			return Object.class;
 		}
 
 		Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
 
 		if (index >= params.length || index < 0) {
-			logger.warning(String.format("Warn: Index: %s, Size of %s's Parameterized Type: %s .", index, clazz.getSimpleName(),
+			logger.warn(String.format("Warn: Index: %s, Size of %s's Parameterized Type: %s .", index, clazz.getSimpleName(),
 					params.length));
 			return Object.class;
 		}
 		if (!(params[index] instanceof Class)) {
-			logger.warning(String.format("Warn: %s not set the actual class on superclass generic parameter",
-					clazz.getSimpleName()));
+			logger.warn(String.format("Warn: %s not set the actual class on superclass generic parameter", clazz.getSimpleName()));
 			return Object.class;
 		}
 

+ 11 - 11
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/Sequence.java

@@ -16,11 +16,13 @@
 package com.baomidou.mybatisplus.toolkit;
 
 import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
+import com.baomidou.mybatisplus.plugins.SqlExplainInterceptor;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 
 import java.lang.management.ManagementFactory;
 import java.net.InetAddress;
 import java.net.NetworkInterface;
-import java.util.logging.Logger;
 
 /**
  * <p>
@@ -32,7 +34,7 @@ import java.util.logging.Logger;
  * @date 2016-08-18
  */
 public class Sequence {
-	protected final static Logger logger = Logger.getLogger("Sequence");
+	private static final Log logger = LogFactory.getLog(SqlExplainInterceptor.class);
 
 	/* 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动) */
 	private final long twepoch = 1288834974657L;
@@ -67,8 +69,7 @@ public class Sequence {
 	 */
 	public Sequence(long workerId, long datacenterId) {
 		if (workerId > maxWorkerId || workerId < 0) {
-			throw new MybatisPlusException(
-					String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
+			throw new MybatisPlusException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
 		}
 		if (datacenterId > maxDatacenterId || datacenterId < 0) {
 			throw new MybatisPlusException(
@@ -86,8 +87,8 @@ public class Sequence {
 	public synchronized long nextId() {
 		long timestamp = timeGen();
 		if (timestamp < lastTimestamp) {
-			throw new MybatisPlusException(String.format(
-					"Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
+			throw new MybatisPlusException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds",
+					lastTimestamp - timestamp));
 		}
 		if (lastTimestamp == timestamp) {
 			sequence = (sequence + 1) & sequenceMask;
@@ -100,8 +101,8 @@ public class Sequence {
 
 		lastTimestamp = timestamp;
 
-		return ((timestamp - twepoch) << timestampLeftShift) | (datacenterId << datacenterIdShift)
-				| (workerId << workerIdShift) | sequence;
+		return ((timestamp - twepoch) << timestampLeftShift) | (datacenterId << datacenterIdShift) | (workerId << workerIdShift)
+				| sequence;
 	}
 
 	protected long tilNextMillis(long lastTimestamp) {
@@ -151,12 +152,11 @@ public class Sequence {
 				id = 1L;
 			} else {
 				byte[] mac = network.getHardwareAddress();
-				id = ((0x000000FF & (long) mac[mac.length - 1])
-						| (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
+				id = ((0x000000FF & (long) mac[mac.length - 1]) | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
 				id = id % (maxDatacenterId + 1);
 			}
 		} catch (Exception e) {
-			logger.fine(" getDatacenterId: " + e.getMessage());
+			logger.warn(" getDatacenterId: " + e.getMessage());
 		}
 		return id;
 	}

+ 5 - 3
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/TableInfoHelper.java

@@ -24,6 +24,8 @@ import com.baomidou.mybatisplus.annotations.TableId;
 import com.baomidou.mybatisplus.annotations.TableName;
 import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
 import org.apache.ibatis.builder.MapperBuilderAssistant;
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
 import org.apache.ibatis.session.SqlSessionFactory;
 
 import java.lang.reflect.Field;
@@ -33,7 +35,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Logger;
 
 /**
  * <p>
@@ -44,7 +45,8 @@ import java.util.logging.Logger;
  * @Date 2016-09-09
  */
 public class TableInfoHelper {
-	protected static final Logger logger = Logger.getLogger("TableInfoHelper");
+
+	private static final Log logger = LogFactory.getLog(TableInfoHelper.class);
 
 	/**
 	 * 缓存反射类表信息
@@ -145,7 +147,7 @@ public class TableInfoHelper {
 		 * 未发现主键注解,跳过注入
 		 */
 		if (null == tableInfo.getKeyColumn()) {
-			logger.warning(String.format("Warn: Could not find @TableId in Class: %s, initTableInfo Method Fail.",
+			logger.warn(String.format("Warn: Could not find @TableId in Class: %s, initTableInfo Method Fail.",
 					clazz.getName()));
 			return null;
 		}