Initial commit
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package com.assess.business.handler;
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2025 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import com.assess.business.domain.IndicatorConfig;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.ibatis.type.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@Component
|
||||
@MappedTypes(IndicatorConfig.class)
|
||||
@MappedJdbcTypes({
|
||||
JdbcType.VARCHAR,
|
||||
JdbcType.BLOB
|
||||
})
|
||||
public class IndicatorConfigTypeHandler extends BaseTypeHandler<IndicatorConfig>
|
||||
implements TypeHandler<IndicatorConfig> {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, IndicatorConfig parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
ps.setString(i, serialize(parameter));
|
||||
}
|
||||
|
||||
public String serialize(IndicatorConfig indicatorConfig) {
|
||||
if (null != indicatorConfig){
|
||||
try {
|
||||
return objectMapper.writeValueAsString(indicatorConfig);
|
||||
} catch (Exception e){
|
||||
logger.error("Can not serialize", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IndicatorConfig deserialize(String config) throws SQLException {
|
||||
if (StringUtils.hasText(config)){
|
||||
try {
|
||||
return objectMapper.readValue(config, IndicatorConfig.class);
|
||||
} catch (Exception e){
|
||||
logger.error("Can not deserialize", e);
|
||||
}
|
||||
}
|
||||
return new IndicatorConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndicatorConfig getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String jsonValue = rs.getString(columnName);
|
||||
return deserialize(jsonValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndicatorConfig getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String jsonValue = rs.getString(columnIndex);
|
||||
return deserialize(jsonValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndicatorConfig getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String jsonValue = cs.getString(columnIndex);
|
||||
return deserialize(jsonValue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.solution.algo.domain;
|
||||
/*
|
||||
* This file is part of the kernelstudio package.
|
||||
*
|
||||
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
* that was distributed with this source code.
|
||||
*/
|
||||
|
||||
public class AlgorithmConfig {
|
||||
}
|
||||
Reference in New Issue
Block a user