Skip to content

Commit

Permalink
add checkBaseField
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Sep 20, 2024
1 parent 8315de5 commit 66b0d55
Showing 1 changed file with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
package org.apache.bigtop.manager.dao.sql;

import org.apache.bigtop.manager.common.utils.ClassUtils;
import org.apache.bigtop.manager.dao.annotations.CreateBy;
import org.apache.bigtop.manager.dao.annotations.CreateTime;
import org.apache.bigtop.manager.dao.annotations.QueryCondition;
import org.apache.bigtop.manager.dao.annotations.UpdateBy;
import org.apache.bigtop.manager.dao.annotations.UpdateTime;
import org.apache.bigtop.manager.dao.enums.DBType;

import org.apache.ibatis.jdbc.SQL;
Expand Down Expand Up @@ -297,7 +301,10 @@ public static <Entity> String updateList(
if (ps == null || ps.getReadMethod() == null) {
continue;
}

Field field = ReflectionUtils.findField(entityClass, entry.getKey());
if (field == null || checkBaseField(field)) {
continue;
}
Object value = ReflectionUtils.invokeMethod(ps.getReadMethod(), entity);
PropertyDescriptor pkPs =
BeanUtils.getPropertyDescriptor(entityClass, tableMetaData.getPkProperty());
Expand All @@ -316,12 +323,9 @@ public static <Entity> String updateList(
.append(escapeSingleQuote(value.toString()))
.append("' ");
} else if (!partial) {
Field field = ReflectionUtils.findField(entityClass, entry.getKey());
if (field != null) {
Column column = field.getAnnotation(Column.class);
if (column != null && !column.nullable() && value == null) {
continue;
}
Column column = field.getAnnotation(Column.class);
if (column != null && !column.nullable() && value == null) {
continue;
}
caseClause
.append("WHEN ")
Expand Down Expand Up @@ -368,7 +372,10 @@ public static <Entity> String updateList(
primaryKey = keywordsFormat(entry.getValue(), DBType.POSTGRESQL);
continue;
}

Field field = ReflectionUtils.findField(entityClass, entry.getKey());
if (field == null || checkBaseField(field)) {
continue;
}
StringBuilder caseClause = new StringBuilder();
caseClause
.append(keywordsFormat(entry.getValue(), DBType.POSTGRESQL))
Expand Down Expand Up @@ -397,12 +404,9 @@ public static <Entity> String updateList(
.append(escapeSingleQuote(value.toString()))
.append("' ");
} else if (!partial) {
Field field = ReflectionUtils.findField(entityClass, entry.getKey());
if (field != null) {
Column column = field.getAnnotation(Column.class);
if (column != null && !column.nullable() && value == null) {
continue;
}
Column column = field.getAnnotation(Column.class);
if (column != null && !column.nullable() && value == null) {
continue;
}
caseClause
.append("WHEN ")
Expand Down Expand Up @@ -637,6 +641,13 @@ private static String escapeSingleQuote(String input) {
return null;
}

private static boolean checkBaseField(Field field) {
return field.isAnnotationPresent(CreateBy.class)
|| field.isAnnotationPresent(CreateTime.class)
|| field.isAnnotationPresent(UpdateBy.class)
|| field.isAnnotationPresent(UpdateTime.class);
}

private static <Condition> SQL mysqlCondition(Condition condition, TableMetaData tableMetaData)
throws IllegalAccessException {

Expand Down

0 comments on commit 66b0d55

Please sign in to comment.