package foundation.value;
|
|
import java.sql.Clob;
|
|
import javax.sql.rowset.serial.SerialClob;
|
|
import com.alibaba.druid.proxy.jdbc.ClobProxy;
|
import com.alibaba.druid.proxy.jdbc.NClobProxyImpl;
|
|
import foundation.server.config.DBaseType;
|
import foundation.util.Util;
|
|
public class ClobTranslator extends ITranslator {
|
@Override
|
public Clob load(Object value){
|
if (value == null || value == ValueType.Null) {
|
return null;
|
}
|
|
if (value instanceof NClobProxyImpl) {
|
ClobProxy clobProxy = (ClobProxy)value;
|
return clobProxy.getRawClob();
|
}
|
|
return null;
|
}
|
|
@Override
|
public Clob load(String value) throws Exception {
|
if (Util.isEmpty(value)) {
|
return null;
|
}
|
|
return new SerialClob(value.toCharArray());
|
}
|
|
@Override
|
public String toString(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return null;
|
}
|
Clob clob = (Clob)value;
|
return clob.getSubString((long)1, (int)clob.length());
|
}
|
|
|
@Override
|
public String toSqlString(DBaseType dbaseType, Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return "null";
|
}
|
|
Clob clob = (Clob)value;
|
|
if (clob.length() == 0 ) {
|
return "''";
|
}
|
|
return "'" + clob.getSubString((long)1, (int)clob.length()) + "'";
|
|
}
|
|
@Override
|
public String toJSONString(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return "null";
|
}
|
|
//1. 如果数据本身就是 Date, 按着Date转换
|
if (value instanceof Clob) {
|
Clob clob = (Clob)value;
|
return "\"" + clob.getSubString((long)1, (int)clob.length()) + "\"";
|
}
|
|
//2. 如果数据是 String, 按着String转
|
if (value instanceof String) {
|
return "\"" + (String)value + "\"";
|
}
|
|
return "\"" + value.toString() + "\"";
|
}
|
|
@Override
|
public String toSchemaString(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return "null";
|
}
|
|
//1. 如果数据本身就是 Clob, 按着Clob转换
|
if (value instanceof Clob) {
|
Clob clob = (Clob)value;
|
return "\"" + clob.getSubString((long)1, (int)clob.length()) + "\"";
|
}
|
|
//2. 如果数据是 String, 按着String转
|
if (value instanceof String) {
|
return "\"" + (String)value + "\"";
|
}
|
|
return "\"" + value.toString() + "\"";
|
}
|
|
|
private Clob toClob(Object value){
|
if (value == null || value == ValueType.Null) {
|
return null;
|
}
|
|
if (value instanceof NClobProxyImpl) {
|
ClobProxy clobProxy = (ClobProxy)value;
|
return clobProxy.getRawClob();
|
}
|
|
return null;
|
}
|
|
@Override
|
public Object toTranslatorTypeValue(Object value) throws Exception {
|
return null;
|
}
|
|
@Override
|
public String checkType(Object object) {
|
return null;
|
}
|
|
/*
|
@Override
|
public Integer toInteger(Object value) throws Exception {
|
return null;
|
}
|
|
@Override
|
public Double toDouble(Object value) throws Exception {
|
return null;
|
}
|
|
@Override
|
public BigDecimal toBigDecimal(Object value) throws Exception {
|
return null;
|
}
|
|
@Override
|
public Boolean toBoolean(Object object) throws Exception {
|
return null;
|
}
|
|
@Override
|
public Date toDate(Object value) throws Exception {
|
return null;
|
}
|
*/
|
|
@Override
|
public Class<?> getDataClass() {
|
return Clob.class;
|
}
|
}
|