DataJdbcSource优化

This commit is contained in:
redkale
2023-12-03 22:52:19 +08:00
parent ed8719c27b
commit 7522e79f7d
3 changed files with 25 additions and 42 deletions

View File

@@ -22,4 +22,5 @@ import static java.lang.annotation.RetentionPolicy.*;
@Retention(SOURCE)
public @interface AsmDepends {
Class[] value() default {};
}

View File

@@ -1082,7 +1082,6 @@ public class DataJdbcSource extends AbstractDataSqlSource {
private <T> int updateEntityDBStatement(List<Statement> stmtsRef, final SourceConnection conn, final EntityInfo<T> info, T... entitys) throws SQLException {
final long s = System.currentTimeMillis();
String presql = null;
String caseSql = null;
PreparedStatement prestmt = null;
List<PreparedStatement> prestmts = null;
Map<String, PrepareInfo<T>> prepareInfos = null;
@@ -1090,25 +1089,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
final Attribute<T, Serializable>[] attrs = info.updateAttributes;
try {
if (info.getTableStrategy() == null) {
caseSql = info.getUpdateQuestionPrepareCaseSQL(entitys);
if (caseSql == null) {
presql = info.getUpdateQuestionPrepareSQL(entitys[0]);
prestmt = prepareUpdateEntityStatement(conn, presql, info, entitys);
} else {
presql = caseSql;
prestmt = conn.prepareUpdateStatement(presql);
int len = entitys.length;
final Attribute<T, Serializable> primary = info.getPrimary();
Attribute<T, Serializable> otherAttr = attrs[0];
//UPDATE twointrecord SET randomNumber = ( CASE WHEN id = ? THEN ? WHEN id = ? THEN ? WHEN id = ? THEN ? END ) WHERE id IN (?,?,?)
for (int i = 0; i < entitys.length; i++) {
Serializable pk = primary.get(entitys[i]);
prestmt.setObject(i * 2 + 1, pk); //1 3 5
prestmt.setObject(i * 2 + 2, getEntityAttrValue(info, otherAttr, entitys[i])); //2 4 6
prestmt.setObject(len * 2 + i + 1, pk); //7 8 9
}
prestmt.addBatch();
}
presql = info.getUpdateQuestionPrepareSQL(entitys[0]);
prestmt = prepareUpdateEntityStatement(conn, presql, info, entitys);
int c1 = 0;
int[] pc = prestmt.executeBatch();
for (int p : pc) {
@@ -1189,7 +1171,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
}
}
if (info.isLoggable(logger, Level.FINEST) && caseSql == null) { //打印调试信息
if (info.isLoggable(logger, Level.FINEST)) { //打印调试信息
Attribute<T, Serializable> primary = info.getPrimary();
if (info.getTableStrategy() == null) {
char[] sqlchars = presql.toCharArray();

View File

@@ -3394,67 +3394,67 @@ public final class Utility {
*
* @return 对象
*/
@AsmDepends
@AsmDepends(Copier.class)
public static <T> T convertValue(Type type, Object value) {
if (type == null || value == null) {
return (T) value;
}
final Class clazz = TypeToken.typeToClass(type);
final Class vclzz = value.getClass();
if (clazz == vclzz || clazz.isAssignableFrom(vclzz)) {
final Class typeClazz = TypeToken.typeToClass(type);
final Class valClazz = value.getClass();
if (typeClazz == valClazz || typeClazz.isAssignableFrom(valClazz)) {
return (T) value;
} else if (clazz == String.class) {
} else if (typeClazz == String.class) {
return (T) value.toString();
} else if (clazz == double.class || clazz == Double.class) {
} else if (typeClazz == double.class || typeClazz == Double.class) {
if (value instanceof Number) {
return (T) (Number) ((Number) value).doubleValue();
} else if (vclzz == String.class) {
} else if (valClazz == String.class) {
return (T) (Number) Double.parseDouble(value.toString());
}
} else if (clazz == float.class || clazz == Float.class) {
} else if (typeClazz == float.class || typeClazz == Float.class) {
if (value instanceof Number) {
return (T) (Number) ((Number) value).floatValue();
} else if (vclzz == String.class) {
} else if (valClazz == String.class) {
return (T) (Number) Float.parseFloat(value.toString());
}
} else if (clazz == long.class || clazz == Long.class) {
} else if (typeClazz == long.class || typeClazz == Long.class) {
if (value instanceof Number) {
return (T) (Number) ((Number) value).longValue();
} else if (vclzz == String.class) {
} else if (valClazz == String.class) {
return (T) (Number) Long.parseLong(value.toString());
}
} else if (clazz == int.class || clazz == Integer.class) {
} else if (typeClazz == int.class || typeClazz == Integer.class) {
if (value instanceof Number) {
return (T) (Number) ((Number) value).intValue();
} else if (vclzz == String.class) {
} else if (valClazz == String.class) {
return (T) (Number) Integer.parseInt(value.toString());
}
} else if (clazz == short.class || clazz == Short.class) {
} else if (typeClazz == short.class || typeClazz == Short.class) {
if (value instanceof Number) {
return (T) (Number) ((Number) value).shortValue();
} else if (vclzz == String.class) {
} else if (valClazz == String.class) {
return (T) (Number) Short.parseShort(value.toString());
}
} else if (clazz == char.class || clazz == Character.class) {
} else if (typeClazz == char.class || typeClazz == Character.class) {
if (value instanceof Number) {
char ch = (char) ((Number) value).intValue();
return (T) (Object) ch;
}
} else if (clazz == byte.class || clazz == Byte.class) {
} else if (typeClazz == byte.class || typeClazz == Byte.class) {
if (value instanceof Number) {
return (T) (Number) ((Number) value).byteValue();
}
} else if (clazz == boolean.class || clazz == Boolean.class) {
} else if (typeClazz == boolean.class || typeClazz == Boolean.class) {
if (value instanceof Number) {
return (T) (Object) (((Number) value).intValue() > 0);
}
} else if (clazz == BigInteger.class && vclzz == String.class) {
} else if (typeClazz == BigInteger.class && valClazz == String.class) {
return (T) new BigInteger(value.toString());
} else if (clazz == BigDecimal.class && vclzz == String.class) {
} else if (typeClazz == BigDecimal.class && valClazz == String.class) {
return (T) new BigDecimal(value.toString());
}
JsonConvert convert = JsonConvert.root();
if (CharSequence.class.isAssignableFrom(vclzz)) {
if (CharSequence.class.isAssignableFrom(valClazz)) {
return convert.convertFrom(type, value.toString());
} else {
return convert.convertFrom(type, convert.convertToBytes(value));