From 7f5d914898c9d05942705ce7d80c0d14a8174df8 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期二, 19 十二月 2023 15:57:14 +0800 Subject: [PATCH] 1、common模块优化代码; 2、通信中间件优化代码,队列遍历由递归调用改为while循环,原因是队列数据量大时递归调易产生栈溢出,HashTable多线程应用时仍有线程安全问题,改为HashMap+同步锁; 3、RTU模拟器和模拟器控制服务增加report命令 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java | 30 +++++++++++++++++------------- 1 files changed, 17 insertions(+), 13 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java index 1729ef2..eca91c8 100644 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java @@ -27,29 +27,33 @@ static int MAPPED_STATEMENT_INDEX = 0; static int PARAMETER_INDEX = 1; - static int ROWBOUNDS_INDEX = 2; - static int RESULT_HANDLER_INDEX = 3; static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME = "setId"; - static String BASE_FIELD_SET_CREATE_TIME_FUNTION_NAME = "setCreateDt"; - static String BASE_FIELD_SET_UPDATE_TIME_FUNTION_NAME = "setUpdateDt"; - static String BASE_FIELD_SET_DELETE_FUNTION_NAME = "setDelete"; - public AutoGenerateIdInterceptor() { - //System.out.println("auto generate primaryKey mybatis plugin start!!!"); - } - - @SuppressWarnings("static-access") + /** + * 鎷︽埅閫昏緫瀹炵幇 + * @param invocation 浠g悊 + * @return Object + * @throws Throwable 寮傚父 + */ public Object intercept(Invocation invocation) throws Throwable { MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[MAPPED_STATEMENT_INDEX]; SqlCommandType commandType = mappedStatement.getSqlCommandType(); - if (commandType.INSERT.equals(SqlCommandType.INSERT)) { + if (commandType.equals(SqlCommandType.INSERT)) { Object entity = invocation.getArgs()[PARAMETER_INDEX]; if (entity instanceof BaseEntity) { - Class<? extends Object> entityClass = entity.getClass(); - Method setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ; + //Class<? extends Object> entityClass = entity.getClass(); + Class<?> entityClass = entity.getClass(); + Method setMt = null ; + try{ + //鏈変竴浜涘疄浣撴病鏈塱d锛屼緥濡備腑闂磋〃 + setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ; + }catch (Exception e){ + //褰揺ntityClass娌℃湁setId鏂规硶鏃讹紝浼氭姏鍑哄紓甯� + } if(setMt != null){ setMt.invoke(entity, new IDLongGenerator().generate()); } + invocation.getArgs()[PARAMETER_INDEX] = entity; } } -- Gitblit v1.8.0