Commit 48a9eb4c by s_guodong

优化dbUpdate方法

parent 3d420a82
...@@ -72,7 +72,7 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession ...@@ -72,7 +72,7 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
//定义mapper文件中的sql语句id //定义mapper文件中的sql语句id
private static final String SQLID_INSERT = "insert"; private static final String SQLID_INSERT = "insert";
private static final String SQLID_UPDATE = "updateByPrimaryKey"; private static final String SQLID_UPDATE = "updateByPrimaryKeySelective";
private static final String SQLID_DELETE = "deleteByPrimaryKey"; private static final String SQLID_DELETE = "deleteByPrimaryKey";
private static final String SQLID_DELBYIDS = "deleteByIds"; private static final String SQLID_DELBYIDS = "deleteByIds";
private static final String SQLID_DYNCREAD = "dyncRead"; private static final String SQLID_DYNCREAD = "dyncRead";
...@@ -125,6 +125,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession ...@@ -125,6 +125,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override @Override
public <T extends IModule> int dbUpdate(T module) { public <T extends IModule> int dbUpdate(T module) {
boolean b = checkAllPropertiesNull(module);
if (b) {
return 0;
}
if (isMultiDb) { if (isMultiDb) {
String moduleDB = MdaUtils.getModuleDB(module); String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB); DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
...@@ -644,4 +648,34 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession ...@@ -644,4 +648,34 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
private void setNoMoreRow() { private void setNoMoreRow() {
MdaEnv.getContext().setErrorCode(Constants.NO_MORE_ROW); MdaEnv.getContext().setErrorCode(Constants.NO_MORE_ROW);
} }
/**
* 校验是否所有的属性都为null
*
* @return
*/
private boolean checkAllPropertiesNull(Object obj) {
if (obj == null) {
return true;
}
Class<?> aClass = obj.getClass();
Field[] declaredFields = aClass.getDeclaredFields();
for (Field field : declaredFields) {
String name = field.getName();
if (field.isAnnotationPresent(Ignore.class) || "inr".equals(name)) {
continue;
}
field.setAccessible(true);
Object o = null;
try {
o = field.get(obj);
} catch (IllegalAccessException e) {
}
if (o != null) {
return false;
}
}
return true;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment