mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-29 18:53:12 +08:00
batch export
This commit is contained in:
@ -15,10 +15,15 @@ public class MysqlDBManage extends DefaultDBManage implements DBManage {
|
|||||||
@Override
|
@Override
|
||||||
public void exportDatabase(Connection connection, String databaseName, String schemaName, AsyncContext asyncContext) throws SQLException {
|
public void exportDatabase(Connection connection, String databaseName, String schemaName, AsyncContext asyncContext) throws SQLException {
|
||||||
exportTables(connection, databaseName, schemaName, asyncContext);
|
exportTables(connection, databaseName, schemaName, asyncContext);
|
||||||
|
asyncContext.setProgress(50);
|
||||||
exportViews(connection, databaseName, asyncContext);
|
exportViews(connection, databaseName, asyncContext);
|
||||||
|
asyncContext.setProgress(60);
|
||||||
exportProcedures(connection, asyncContext);
|
exportProcedures(connection, asyncContext);
|
||||||
|
asyncContext.setProgress(70);
|
||||||
exportTriggers(connection, asyncContext);
|
exportTriggers(connection, asyncContext);
|
||||||
|
asyncContext.setProgress(90);
|
||||||
exportFunctions(connection, databaseName, asyncContext);
|
exportFunctions(connection, databaseName, asyncContext);
|
||||||
|
asyncContext.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportFunctions(Connection connection, String databaseName, AsyncContext asyncContext) throws SQLException {
|
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 {
|
public String exportDatabase(DatabaseExportParam param) throws SQLException {
|
||||||
AsyncContext asyncContext = new AsyncContext();
|
AsyncContext asyncContext = new AsyncContext();
|
||||||
asyncContext.setContainsData(param.getContainData());
|
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(),
|
Chat2DBContext.getDBManage().exportDatabase(Chat2DBContext.getConnection(),
|
||||||
param.getDatabaseName(),
|
param.getDatabaseName(),
|
||||||
param.getSchemaName(), asyncContext);
|
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 boolean containsData;
|
||||||
|
|
||||||
private Consumer<Long> consumer;
|
private AsyncCall call;
|
||||||
|
|
||||||
public void addProgress(Long progress) {
|
public void setProgress(Integer progress) {
|
||||||
if (consumer != null) {
|
if (call != null) {
|
||||||
consumer.accept(progress);
|
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