Skip to content

Commit 8edfa68

Browse files
committed
batch export
1 parent c8e5af3 commit 8edfa68

4 files changed

Lines changed: 65 additions & 5 deletions

File tree

chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlDBManage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ public class MysqlDBManage extends DefaultDBManage implements DBManage {
1515
@Override
1616
public void exportDatabase(Connection connection, String databaseName, String schemaName, AsyncContext asyncContext) throws SQLException {
1717
exportTables(connection, databaseName, schemaName, asyncContext);
18+
asyncContext.setProgress(50);
1819
exportViews(connection, databaseName, asyncContext);
20+
asyncContext.setProgress(60);
1921
exportProcedures(connection, asyncContext);
22+
asyncContext.setProgress(70);
2023
exportTriggers(connection, asyncContext);
24+
asyncContext.setProgress(90);
2125
exportFunctions(connection, databaseName, asyncContext);
26+
asyncContext.finish();
2227
}
2328

2429
private void exportFunctions(Connection connection, String databaseName, AsyncContext asyncContext) throws SQLException {

chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DatabaseServiceImpl.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,27 @@ public ActionResult modifySchema(SchemaOperationParam param) {
179179
public String exportDatabase(DatabaseExportParam param) throws SQLException {
180180
AsyncContext asyncContext = new AsyncContext();
181181
asyncContext.setContainsData(param.getContainData());
182-
asyncContext.setConsumer(aLong -> log.info("exportDatabase success"));
182+
asyncContext.setCall(new AsyncCall() {
183+
@Override
184+
public void setProgress(int progress) {
185+
186+
}
187+
188+
@Override
189+
public void info(String message) {
190+
191+
}
192+
193+
@Override
194+
public void error(String message) {
195+
196+
}
197+
198+
@Override
199+
public void finish() {
200+
201+
}
202+
});
183203
Chat2DBContext.getDBManage().exportDatabase(Chat2DBContext.getConnection(),
184204
param.getDatabaseName(),
185205
param.getSchemaName(), asyncContext);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ai.chat2db.spi.model;
2+
3+
public interface AsyncCall {
4+
5+
6+
void setProgress(int progress);
7+
8+
9+
void info(String message);
10+
11+
12+
void error(String message);
13+
14+
15+
void finish();
16+
17+
}

chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/AsyncContext.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,29 @@ public class AsyncContext {
1818

1919
private boolean containsData;
2020

21-
private Consumer<Long> consumer;
21+
private AsyncCall call;
2222

23-
public void addProgress(Long progress) {
24-
if (consumer != null) {
25-
consumer.accept(progress);
23+
public void setProgress(Integer progress) {
24+
if (call != null) {
25+
call.setProgress(progress);
26+
}
27+
}
28+
29+
public void info(String message) {
30+
if (call != null) {
31+
call.info(message);
32+
}
33+
}
34+
35+
public void error(String message) {
36+
if (call != null) {
37+
call.error(message);
38+
}
39+
}
40+
41+
public void finish() {
42+
if (call != null) {
43+
call.finish();
2644
}
2745
}
2846

0 commit comments

Comments
 (0)