mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 10:43:06 +08:00
fix(chat2db-mysql): optimize valueProcessor
This commit is contained in:
@ -6,6 +6,8 @@ import ai.chat2db.spi.jdbc.DefaultValueProcessor;
|
||||
import ai.chat2db.spi.model.JDBCDataValue;
|
||||
import ai.chat2db.spi.model.SQLDataValue;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@ -19,6 +21,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class MysqlValueProcessor extends DefaultValueProcessor {
|
||||
public static final Set<String> FUNCTION_SET = Set.of("now()", "default");
|
||||
private static final Logger log = LoggerFactory.getLogger(MysqlValueProcessor.class);
|
||||
|
||||
|
||||
@Override
|
||||
@ -65,18 +68,47 @@ public class MysqlValueProcessor extends DefaultValueProcessor {
|
||||
if (FUNCTION_SET.contains(dataValue.getValue().toLowerCase())) {
|
||||
return dataValue.getValue();
|
||||
}
|
||||
return MysqlValueProcessorFactory.getValueProcessor(dataValue.getDateTypeName()).convertSQLValueByType(dataValue);
|
||||
try {
|
||||
DefaultValueProcessor valueProcessor = MysqlValueProcessorFactory.getValueProcessor(dataValue.getDateTypeName());
|
||||
if (Objects.nonNull(valueProcessor)) {
|
||||
return valueProcessor.convertSQLValueByType(dataValue);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("convertSQLValueByType error", e);
|
||||
return super.convertSQLValueByType(dataValue);
|
||||
}
|
||||
return super.convertSQLValueByType(dataValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueByType(JDBCDataValue dataValue) {
|
||||
String type = dataValue.getType();
|
||||
return MysqlValueProcessorFactory.getValueProcessor(type).convertJDBCValueByType(dataValue);
|
||||
try {
|
||||
DefaultValueProcessor valueProcessor = MysqlValueProcessorFactory.getValueProcessor(type);
|
||||
if (Objects.nonNull(valueProcessor)) {
|
||||
return valueProcessor.convertJDBCValueByType(dataValue);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("convertJDBCValueByType error", e);
|
||||
return super.convertJDBCValueByType(dataValue);
|
||||
}
|
||||
return super.convertJDBCValueByType(dataValue);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertJDBCValueStrByType(JDBCDataValue dataValue) {
|
||||
String type = dataValue.getType();
|
||||
return MysqlValueProcessorFactory.getValueProcessor(type).convertJDBCValueStrByType(dataValue);
|
||||
DefaultValueProcessor valueProcessor;
|
||||
try {
|
||||
valueProcessor = MysqlValueProcessorFactory.getValueProcessor(type);
|
||||
if (Objects.nonNull(valueProcessor)) {
|
||||
return valueProcessor.convertJDBCValueStrByType(dataValue);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("convertJDBCValueStrByType error", e);
|
||||
return super.convertJDBCValueStrByType(dataValue);
|
||||
}
|
||||
return super.convertJDBCValueStrByType(dataValue);
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,6 @@ public class MysqlValueProcessorFactory {
|
||||
}
|
||||
|
||||
public static DefaultValueProcessor getValueProcessor(String type) {
|
||||
DefaultValueProcessor processor = PROCESSOR_MAP.get(type);
|
||||
return processor == null ? new DefaultValueProcessor() : processor;
|
||||
return PROCESSOR_MAP.get(type);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user