mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 10:43:06 +08:00
batch export
This commit is contained in:
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user