[Core] Unify the data types returned by each plug-in (close #479)

This commit is contained in:
qianmoQ 2023-11-13 01:10:41 +08:00
parent 7187bd4bcd
commit 3a26eb94a1
6 changed files with 80 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package io.edurt.datacap.spi.adapter;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.edurt.datacap.spi.FormatType;
import io.edurt.datacap.spi.column.Column;
import io.edurt.datacap.spi.column.JdbcColumn;
import io.edurt.datacap.spi.connection.JdbcConfigure;
import io.edurt.datacap.spi.connection.JdbcConnection;
@ -52,17 +53,17 @@ public class JdbcAdapter
List<String> types = new ArrayList<>();
List<Object> columns = new ArrayList<>();
try (ResultSet resultSet = statement.executeQuery(content)) {
JdbcColumn jdbcColumn = new JdbcColumn(resultSet);
Column jdbcColumn = new JdbcColumn(resultSet);
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
headers.add(metaData.getColumnName(i));
types.add(metaData.getColumnTypeName(i));
types.add(jdbcColumn.mappingColumnType(metaData.getColumnTypeName(i)));
}
while (resultSet.next()) {
List<Object> _columns = new ArrayList<>();
for (int i = 1; i <= columnCount; i++) {
_columns.add(jdbcColumn.convert(metaData.getColumnTypeName(i), i));
_columns.add(jdbcColumn.mappingColumnData(metaData.getColumnTypeName(i), i));
}
columns.add(handlerFormatter(configure.getFormat(), headers, _columns));
}

View File

@ -0,0 +1,20 @@
package io.edurt.datacap.spi.column;
import java.sql.ResultSet;
import java.sql.SQLException;
public abstract class Column
{
protected final ResultSet resultSet;
public Column(ResultSet resultSet)
{
this.resultSet = resultSet;
}
public abstract Object mappingColumnData(String columnType, Integer columnIndex)
throws SQLException;
public abstract String mappingColumnType(String columnName)
throws SQLException;
}

View File

@ -1,18 +1,22 @@
package io.edurt.datacap.spi.column;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
public class JdbcColumn
extends Column
{
private final ResultSet resultSet;
public JdbcColumn(ResultSet resultSet)
{
this.resultSet = resultSet;
super(resultSet);
}
public Object convert(String columnType, Integer columnIndex)
@Override
public Object mappingColumnData(String columnType, Integer columnIndex)
throws SQLException
{
// Obtain the value of the corresponding type based on the data returned in the query result
@ -61,4 +65,49 @@ public class JdbcColumn
return resultSet.getObject(columnIndex);
}
}
@Override
public String mappingColumnType(String columnName)
throws SQLException
{
// Obtain the value of the corresponding type based on the data returned in the query result
if (columnName.equalsIgnoreCase(JdbcColumnType.INTEGER.name())
|| columnName.equalsIgnoreCase(JdbcColumnType.INT.name())) {
return Integer.class.getSimpleName();
}
else if (columnName.equalsIgnoreCase(JdbcColumnType.TINYINT.name())
|| columnName.equalsIgnoreCase(JdbcColumnType.BLOB.name())) {
return Byte.class.getSimpleName();
}
else if (columnName.equalsIgnoreCase(JdbcColumnType.DOUBLE.name())) {
return Double.class.getSimpleName();
}
else if (columnName.equalsIgnoreCase(JdbcColumnType.REAL.name())) {
return Float.class.getSimpleName();
}
else if (columnName.equalsIgnoreCase(JdbcColumnType.BIGINT.name())) {
return Long.class.getSimpleName();
}
else if (columnName.equalsIgnoreCase(JdbcColumnType.SMALLINT.name())) {
return Short.class.getSimpleName();
}
else if (columnName.equalsIgnoreCase(JdbcColumnType.DECIMAL.name())) {
return BigDecimal.class.getSimpleName();
}
else if (columnName.equalsIgnoreCase(JdbcColumnType.BIT.name())) {
return Boolean.class.getSimpleName();
}
else if (columnName.equalsIgnoreCase(JdbcColumnType.DATE.name())) {
return Date.class.getSimpleName();
}
else if (columnName.equalsIgnoreCase(JdbcColumnType.TIME.name())) {
return Time.class.getSimpleName();
}
else if (columnName.equalsIgnoreCase(JdbcColumnType.TIMESTAMP.name())) {
return Timestamp.class.getSimpleName();
}
else {
return String.class.getSimpleName();
}
}
}

View File

@ -293,6 +293,7 @@ export default defineComponent({
.then(response => {
if (response.status) {
this.$Message.success(response.message);
this.handlerInitialize();
}
else {
this.$Message.error(response.message);

View File

@ -75,7 +75,7 @@ public class KyuubiAdapter
headers.add(metaData.getColumnName(i));
types.add(metaData.getColumnTypeName(i));
}
_columns.add(jdbcColumn.convert(metaData.getColumnTypeName(i), i));
_columns.add(jdbcColumn.mappingColumnData(metaData.getColumnTypeName(i), i));
}
isPresent = false;
columns.add(handlerFormatter(configure.getFormat(), headers, _columns));

View File

@ -54,7 +54,7 @@ public class RedisAdapter
headers.add(metaData.getColumnName(i));
types.add(metaData.getColumnTypeName(i));
}
_columns.add(jdbcColumn.convert(metaData.getColumnTypeName(i), i));
_columns.add(jdbcColumn.mappingColumnData(metaData.getColumnTypeName(i), i));
}
isPresent = false;
columns.add(handlerFormatter(configure.getFormat(), headers, _columns));