Skip to content

Commit

Permalink
feat:support Serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
Chat2DB-Pro committed Mar 15, 2024
1 parent 3ae6f88 commit 0fe586d
Show file tree
Hide file tree
Showing 33 changed files with 207 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ export const dataSourceFormConfigs: IConnectionConfig[] = [
{
"key": "zeroDateTimeBehavior",
"value": "convertToNull"
},
{
"key": "useInformationSchema",
"value": "true"
}
],
type: DatabaseTypeCode.MYSQL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.apache.commons.lang3.StringUtils;


public class ClickHouseSqlBuilder extends DefaultSqlBuilder implements SqlBuilder {
public class ClickHouseSqlBuilder extends DefaultSqlBuilder {
@Override
public String buildCreateTableSql(Table table) {
StringBuilder script = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ai.chat2db.spi.model.Schema;
import org.apache.commons.lang3.StringUtils;

public class H2SqlBuilder extends DefaultSqlBuilder implements SqlBuilder {
public class H2SqlBuilder extends DefaultSqlBuilder {

@Override
public String buildCreateSchemaSql(Schema schema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.stream.Collectors;


public class KingBaseSqlBuilder extends DefaultSqlBuilder implements SqlBuilder {
public class KingBaseSqlBuilder extends DefaultSqlBuilder {
@Override
public String buildCreateTableSql(Table table) {
StringBuilder script = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ai.chat2db.plugin.mongodb;

import ai.chat2db.spi.model.Command;
import ai.chat2db.spi.model.ExecuteResult;
import ai.chat2db.spi.sql.SQLExecutor;

import java.util.List;

public class MongodbCommandExecutor extends SQLExecutor {

@Override
public List<ExecuteResult> executeSelectTable(Command command) {
String sql = "db." + command.getTableName() + ".find()";
command.setScript(sql);
return execute(command);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ai.chat2db.plugin.mongodb;

import ai.chat2db.spi.CommandExecutor;
import ai.chat2db.spi.MetaData;
import ai.chat2db.spi.jdbc.DefaultMetaService;
import ai.chat2db.spi.model.Database;
import ai.chat2db.spi.sql.SQLExecutor;
import com.google.common.collect.Lists;

import java.sql.Connection;
Expand All @@ -17,4 +17,9 @@ public class MongodbMetaData extends DefaultMetaService implements MetaData {
public List<Database> databases(Connection connection) {
return Lists.newArrayList();
}

@Override
public CommandExecutor getCommandExecutor() {
return new MongodbCommandExecutor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.*;


public class MysqlSqlBuilder extends DefaultSqlBuilder implements SqlBuilder {
public class MysqlSqlBuilder extends DefaultSqlBuilder {
@Override
public String buildCreateTableSql(Table table) {
StringBuilder script = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import ai.chat2db.plugin.oracle.type.OracleColumnTypeEnum;
import ai.chat2db.plugin.oracle.type.OracleIndexTypeEnum;
import ai.chat2db.spi.SqlBuilder;
import ai.chat2db.spi.jdbc.DefaultSqlBuilder;
import ai.chat2db.spi.model.Table;
import ai.chat2db.spi.model.TableColumn;
import ai.chat2db.spi.model.TableIndex;
import org.apache.commons.lang3.StringUtils;

public class OracleSqlBuilder extends DefaultSqlBuilder implements SqlBuilder {
public class OracleSqlBuilder extends DefaultSqlBuilder {
@Override
public String buildCreateTableSql(Table table) {
StringBuilder script = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import ai.chat2db.plugin.postgresql.type.PostgreSQLColumnTypeEnum;
import ai.chat2db.plugin.postgresql.type.PostgreSQLIndexTypeEnum;
import ai.chat2db.spi.SqlBuilder;
import ai.chat2db.spi.jdbc.DefaultSqlBuilder;
import ai.chat2db.spi.model.*;
import org.apache.commons.collections4.CollectionUtils;
Expand All @@ -14,7 +13,7 @@
import java.util.stream.Collectors;


public class PostgreSQLSqlBuilder extends DefaultSqlBuilder implements SqlBuilder {
public class PostgreSQLSqlBuilder extends DefaultSqlBuilder {
@Override
public String buildCreateTableSql(Table table) {
StringBuilder script = new StringBuilder();
Expand Down
34 changes: 0 additions & 34 deletions chat2db-server/chat2db-plugins/chat2db-redis/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.apache.commons.lang3.StringUtils;


public class SqliteBuilder extends DefaultSqlBuilder implements SqlBuilder {
public class SqliteBuilder extends DefaultSqlBuilder {
@Override
public String buildCreateTableSql(Table table) {
StringBuilder script = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ai.chat2db.spi.sql.Chat2DBContext;
import org.apache.commons.lang3.StringUtils;

public class SqlServerSqlBuilder extends DefaultSqlBuilder implements SqlBuilder {
public class SqlServerSqlBuilder extends DefaultSqlBuilder {
@Override
public String buildCreateTableSql(Table table) {
StringBuilder script = new StringBuilder();
Expand Down
1 change: 0 additions & 1 deletion chat2db-server/chat2db-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<module>chat2db-mongodb</module>
<module>chat2db-presto</module>
<module>chat2db-hive</module>
<module>chat2db-redis</module>
<module>chat2db-kingbase</module>
</modules>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class DlExecuteParam {
private String databaseName;


private String tableName;


/**
* schema name
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public interface DlTemplateService {
ListResult<ExecuteResult> execute(DlExecuteParam param);


/**
*
* @param param
* @return
*/
ListResult<ExecuteResult> executeSelectTable(DlExecuteParam param);


/**
* Data source execution update
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@
<artifactId>chat2db-presto</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>ai.chat2db</groupId>
<artifactId>chat2db-redis</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>ai.chat2db</groupId>
<artifactId>chat2db-sqlite</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import ai.chat2db.spi.model.*;
import ai.chat2db.spi.sql.Chat2DBContext;
import ai.chat2db.spi.sql.ConnectInfo;
import ai.chat2db.spi.sql.SQLExecutor;
import ai.chat2db.spi.util.JdbcUtils;
import ai.chat2db.spi.util.SqlUtils;
import com.alibaba.druid.DbType;
Expand All @@ -28,6 +27,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -61,12 +61,15 @@ public ListResult<ExecuteResult> execute(DlExecuteParam param) {
CommandExecutor executor = Chat2DBContext.getMetaData().getCommandExecutor();
Command command = commandConverter.param2model(param);
List<ExecuteResult> results = executor.execute(command);
return reBuildHeader(results,param.getSchemaName(),param.getDatabaseName());
}

private ListResult<ExecuteResult> reBuildHeader(List<ExecuteResult> results,String schemaName,String databaseName){
ListResult<ExecuteResult> listResult = ListResult.of(results);
for (ExecuteResult executeResult : results) {
List<Header> headers = executeResult.getHeaderList();
if (executeResult.getSuccess() && executeResult.isCanEdit() && CollectionUtils.isNotEmpty(headers)) {
headers = setColumnInfo(headers, executeResult.getTableName(), param.getSchemaName(),
param.getDatabaseName());
headers = setColumnInfo(headers, executeResult.getTableName(), schemaName, databaseName);
executeResult.setHeaderList(headers);
}
if (!executeResult.getSuccess()) {
Expand All @@ -77,12 +80,13 @@ public ListResult<ExecuteResult> execute(DlExecuteParam param) {
addOperationLog(executeResult);
}
return listResult;
}

// if ("SQLSERVER".equalsIgnoreCase(type)) {
// RemoveSpecialGO(param);
// }


@Override
public ListResult<ExecuteResult> executeSelectTable(DlExecuteParam param) {
Command command = commandConverter.param2model(param);
List<ExecuteResult> results = Chat2DBContext.getMetaData().getCommandExecutor().executeSelectTable(command);
return reBuildHeader(results,param.getSchemaName(),param.getDatabaseName());
}

@Override
Expand Down Expand Up @@ -159,8 +163,9 @@ public DataResult<Long> count(DlCountParam param) {
@Override
public DataResult<String> updateSelectResult(UpdateSelectResultParam param) {
SqlBuilder sqlBuilder = Chat2DBContext.getSqlBuilder();
String sql = sqlBuilder.generateSqlBasedOnResults(param.getTableName(), param.getHeaderList(),
param.getOperations());
QueryResult queryResult = new QueryResult();
BeanUtils.copyProperties(param, queryResult);
String sql = sqlBuilder.buildSqlByQuery(queryResult);
return DataResult.of(sql);
}

Expand Down
Loading

0 comments on commit 0fe586d

Please sign in to comment.