batch export

This commit is contained in:
SwallowGG
2024-06-21 19:54:09 +08:00
parent c8e5af3345
commit 8edfa686d4
4 changed files with 65 additions and 5 deletions

View File

@ -15,10 +15,15 @@ public class MysqlDBManage extends DefaultDBManage implements DBManage {
@Override
public void exportDatabase(Connection connection, String databaseName, String schemaName, AsyncContext asyncContext) throws SQLException {
exportTables(connection, databaseName, schemaName, asyncContext);
asyncContext.setProgress(50);
exportViews(connection, databaseName, asyncContext);
asyncContext.setProgress(60);
exportProcedures(connection, asyncContext);
asyncContext.setProgress(70);
exportTriggers(connection, asyncContext);
asyncContext.setProgress(90);
exportFunctions(connection, databaseName, asyncContext);
asyncContext.finish();
}
private void exportFunctions(Connection connection, String databaseName, AsyncContext asyncContext) throws SQLException {

View File

@ -179,7 +179,27 @@ public class DatabaseServiceImpl implements DatabaseService {
public String exportDatabase(DatabaseExportParam param) throws SQLException {
AsyncContext asyncContext = new AsyncContext();
asyncContext.setContainsData(param.getContainData());
asyncContext.setConsumer(aLong -> log.info("exportDatabase success"));
asyncContext.setCall(new AsyncCall() {
@Override
public void setProgress(int progress) {
}
@Override
public void info(String message) {
}
@Override
public void error(String message) {
}
@Override
public void finish() {
}
});
Chat2DBContext.getDBManage().exportDatabase(Chat2DBContext.getConnection(),
param.getDatabaseName(),
param.getSchemaName(), asyncContext);

View File

@ -0,0 +1,17 @@
package ai.chat2db.spi.model;
public interface AsyncCall {
void setProgress(int progress);
void info(String message);
void error(String message);
void finish();
}

View File

@ -18,11 +18,29 @@ public class AsyncContext {
private boolean containsData;
private Consumer<Long> consumer;
private AsyncCall call;
public void addProgress(Long progress) {
if (consumer != null) {
consumer.accept(progress);
public void setProgress(Integer progress) {
if (call != null) {
call.setProgress(progress);
}
}
public void info(String message) {
if (call != null) {
call.info(message);
}
}
public void error(String message) {
if (call != null) {
call.error(message);
}
}
public void finish() {
if (call != null) {
call.finish();
}
}