mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-08-29 08:54:00 +00:00
近期问题修复
This commit is contained in:
@@ -29,6 +29,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@Slf4j
|
||||
public class ClickhouseMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
|
||||
@@ -283,30 +284,9 @@ public class ClickhouseMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
}
|
||||
break;
|
||||
case ColumnMetaData.TYPE_STRING:
|
||||
if (isPk) {
|
||||
retval += "String";
|
||||
} else {
|
||||
if (length > 0) {
|
||||
if (length == 1) {
|
||||
retval += "Nullable(FixedString(1))";
|
||||
} else if (length < 4096) {
|
||||
retval += "Nullable(FixedString(" + length + "))";
|
||||
} else {
|
||||
retval += "Nullable(String)";
|
||||
}
|
||||
} else {
|
||||
retval += "Nullable(String)";
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case ColumnMetaData.TYPE_BINARY:
|
||||
default:
|
||||
if (isPk) {
|
||||
retval += "String";
|
||||
} else {
|
||||
retval += "Nullable(String)";
|
||||
}
|
||||
retval += isPk ? "String" : "Nullable(String)";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -24,5 +24,10 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
@@ -0,0 +1,110 @@
|
||||
// Copyright tang. All rights reserved.
|
||||
// https://gitee.com/inrgihc/dbswitch
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
//
|
||||
// Author: tang (inrgihc@126.com)
|
||||
// Date : 2020/1/2
|
||||
// Location: beijing , china
|
||||
/////////////////////////////////////////////////////////////
|
||||
package org.dromara.dbswitch.product.mongodb;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
import java.io.IOException;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
public class MongodbJacksonUtils {
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
static {
|
||||
objectMapper.disable(MapperFeature.IGNORE_DUPLICATE_MODULE_REGISTRATIONS);
|
||||
objectMapper.registerModule(createSimpleModule());
|
||||
}
|
||||
|
||||
private static SimpleModule createSimpleModule() {
|
||||
SimpleModule module = new SimpleModule();
|
||||
|
||||
module.addSerializer(Date.class, new StdSerializer<Date>(Date.class) {
|
||||
|
||||
@Override
|
||||
public void serialize(Date value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
|
||||
throws IOException {
|
||||
if (value != null) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DatePattern.NORM_DATE_PATTERN);
|
||||
jsonGenerator.writeString(sdf.format(value));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.addSerializer(LocalDate.class, new StdSerializer<LocalDate>(LocalDate.class) {
|
||||
|
||||
@Override
|
||||
public void serialize(LocalDate value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
|
||||
throws IOException {
|
||||
if (value != null) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DatePattern.NORM_DATE_PATTERN);
|
||||
jsonGenerator.writeString(sdf.format(value));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.addSerializer(Time.class, new StdSerializer<Time>(Time.class) {
|
||||
|
||||
@Override
|
||||
public void serialize(Time value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
|
||||
throws IOException {
|
||||
if (value != null) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DatePattern.NORM_TIME_PATTERN);
|
||||
jsonGenerator.writeString(sdf.format(value));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.addSerializer(Timestamp.class, new StdSerializer<Timestamp>(Timestamp.class) {
|
||||
|
||||
@Override
|
||||
public void serialize(Timestamp value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
|
||||
throws IOException {
|
||||
if (value != null) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DatePattern.NORM_DATETIME_PATTERN);
|
||||
jsonGenerator.writeString(sdf.format(value));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.addSerializer(LocalDateTime.class, new StdSerializer<LocalDateTime>(LocalDateTime.class) {
|
||||
|
||||
@Override
|
||||
public void serialize(LocalDateTime value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
|
||||
throws IOException {
|
||||
if (value != null) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DatePattern.NORM_DATETIME_PATTERN);
|
||||
jsonGenerator.writeString(sdf.format(value));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
public static String toJsonStr(Object obj) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,9 +9,6 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
package org.dromara.dbswitch.product.mongodb;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.dromara.dbswitch.core.provider.ProductFactoryProvider;
|
||||
import org.dromara.dbswitch.core.provider.write.DefaultTableDataWriteProvider;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
@@ -23,6 +20,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dromara.dbswitch.core.provider.ProductFactoryProvider;
|
||||
import org.dromara.dbswitch.core.provider.write.DefaultTableDataWriteProvider;
|
||||
|
||||
@Slf4j
|
||||
public class MongodbTableDataWriteProvider extends DefaultTableDataWriteProvider {
|
||||
@@ -77,7 +76,7 @@ public class MongodbTableDataWriteProvider extends DefaultTableDataWriteProvider
|
||||
}
|
||||
rows.add(columns);
|
||||
}
|
||||
return JSONUtil.toJsonStr(rows);
|
||||
return MongodbJacksonUtils.toJsonStr(rows);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -9,14 +9,6 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
package org.dromara.dbswitch.product.mysql;
|
||||
|
||||
import org.dromara.dbswitch.common.consts.Constants;
|
||||
import org.dromara.dbswitch.core.provider.ProductFactoryProvider;
|
||||
import org.dromara.dbswitch.core.provider.meta.AbstractMetadataProvider;
|
||||
import org.dromara.dbswitch.core.schema.ColumnDescription;
|
||||
import org.dromara.dbswitch.core.schema.ColumnMetaData;
|
||||
import org.dromara.dbswitch.core.schema.IndexDescription;
|
||||
import org.dromara.dbswitch.core.schema.TableDescription;
|
||||
import org.dromara.dbswitch.core.schema.SourceProperties;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -29,6 +21,14 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.dbswitch.common.consts.Constants;
|
||||
import org.dromara.dbswitch.core.provider.ProductFactoryProvider;
|
||||
import org.dromara.dbswitch.core.provider.meta.AbstractMetadataProvider;
|
||||
import org.dromara.dbswitch.core.schema.ColumnDescription;
|
||||
import org.dromara.dbswitch.core.schema.ColumnMetaData;
|
||||
import org.dromara.dbswitch.core.schema.IndexDescription;
|
||||
import org.dromara.dbswitch.core.schema.SourceProperties;
|
||||
import org.dromara.dbswitch.core.schema.TableDescription;
|
||||
|
||||
@Slf4j
|
||||
public class MysqlMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
@@ -253,6 +253,11 @@ public class MysqlMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
switch (type) {
|
||||
case ColumnMetaData.TYPE_TIMESTAMP:
|
||||
retval += "DATETIME";
|
||||
if (3 == length) {
|
||||
retval += "(3)";
|
||||
} else if (6 == length) {
|
||||
retval += "(6)";
|
||||
}
|
||||
break;
|
||||
case ColumnMetaData.TYPE_TIME:
|
||||
retval += "TIME";
|
||||
|
Reference in New Issue
Block a user