mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 10:43:06 +08:00
export info
This commit is contained in:
@ -6,6 +6,7 @@ import ai.chat2db.spi.model.AsyncContext;
|
||||
import ai.chat2db.spi.model.Procedure;
|
||||
import ai.chat2db.spi.sql.SQLExecutor;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
@ -13,6 +14,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
public class MysqlDBManage extends DefaultDBManage implements DBManage {
|
||||
@Override
|
||||
public void exportDatabase(Connection connection, String databaseName, String schemaName, AsyncContext asyncContext) throws SQLException {
|
||||
@ -52,13 +54,14 @@ public class MysqlDBManage extends DefaultDBManage implements DBManage {
|
||||
}
|
||||
|
||||
private void exportTables(Connection connection, String databaseName, String schemaName, AsyncContext asyncContext) throws SQLException {
|
||||
asyncContext.write("SET FOREIGN_KEY_CHECKS=0;");
|
||||
asyncContext.write("SET FOREIGN_KEY_CHECKS=0;\n");
|
||||
try (ResultSet resultSet = connection.getMetaData().getTables(databaseName, null, null, new String[]{"TABLE", "SYSTEM TABLE"})) {
|
||||
while (resultSet.next()) {
|
||||
String tableName = resultSet.getString("TABLE_NAME");
|
||||
exportTable(connection, databaseName, schemaName, tableName, asyncContext);
|
||||
}
|
||||
}
|
||||
asyncContext.write("SET FOREIGN_KEY_CHECKS=1;");
|
||||
}
|
||||
|
||||
|
||||
@ -76,6 +79,9 @@ public class MysqlDBManage extends DefaultDBManage implements DBManage {
|
||||
exportTableData(connection, databaseName, schemaName, tableName, asyncContext);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("export table error", e);
|
||||
asyncContext.getCall().error(String.format("export table %s error:%s", tableName,e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -195,6 +196,11 @@ public class DatabaseServiceImpl implements DatabaseService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Map<String, Object> map) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
|
||||
|
@ -192,6 +192,7 @@ public class DefaultDBManage implements DBManage {
|
||||
public void exportTableData(Connection connection, String databaseName, String schemaName, String tableName, AsyncContext asyncContext) {
|
||||
SqlBuilder sqlBuilder = Chat2DBContext.getSqlBuilder();
|
||||
String tableQuerySql = sqlBuilder.buildTableQuerySql(databaseName, schemaName, tableName);
|
||||
asyncContext.info("export table data sql: " + tableQuerySql);
|
||||
SQLExecutor.getInstance().execute(connection, tableQuerySql, 1000, resultSet -> {
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
List<String> columnList = ResultSetUtils.getRsHeader(resultSet);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package ai.chat2db.spi.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface AsyncCall {
|
||||
|
||||
|
||||
@ -12,6 +14,9 @@ public interface AsyncCall {
|
||||
void error(String message);
|
||||
|
||||
|
||||
void update(Map<String,Object> map);
|
||||
|
||||
|
||||
void finish();
|
||||
|
||||
}
|
||||
|
@ -15,11 +15,11 @@ import java.util.function.Consumer;
|
||||
@SuperBuilder
|
||||
public class AsyncContext {
|
||||
|
||||
private PrintWriter writer;
|
||||
protected PrintWriter writer;
|
||||
|
||||
private boolean containsData;
|
||||
protected boolean containsData;
|
||||
|
||||
private AsyncCall call;
|
||||
protected AsyncCall call;
|
||||
|
||||
public void setProgress(Integer progress) {
|
||||
if (call != null) {
|
||||
|
Reference in New Issue
Block a user