城通分享格式适配, 优化日志打印

This commit is contained in:
QAIU
2025-03-28 17:59:28 +08:00
parent 74ed7475c9
commit 527dd0eeb4
4 changed files with 51 additions and 15 deletions

View File

@@ -6,6 +6,8 @@ import io.vertx.codegen.format.CamelCase;
import io.vertx.codegen.format.Case;
import io.vertx.codegen.format.LowerCamelCase;
import io.vertx.codegen.format.SnakeCase;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.jdbcclient.JDBCPool;
import io.vertx.sqlclient.templates.annotations.Column;
import io.vertx.sqlclient.templates.annotations.RowMapped;
@@ -14,9 +16,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* 创建表
@@ -161,17 +161,27 @@ public class CreateTable {
return sql.substring(0, sql.length() - 1) + endStr;
}
public static void createTable(JDBCPool pool, JDBCType type) {
public static Future<Void> createTable(JDBCPool pool, JDBCType type) {
Set<Class<?>> tableClassList = ReflectionUtil.getReflections().getTypesAnnotatedWith(Table.class);
if (tableClassList.isEmpty()) LOGGER.info("Table model class not fount");
List<Future<Object>> futures = new ArrayList<>();
tableClassList.forEach(clazz -> {
String createTableSQL = getCreateTableSQL(clazz, type);
pool.query(createTableSQL).execute().onSuccess(
rs -> LOGGER.info("table auto generate:\n" + createTableSQL)
).onFailure(e -> {
Future<Object> future = pool.query(createTableSQL).execute().compose(rs -> {
LOGGER.info("table auto generate:\n" + createTableSQL);
return Future.succeededFuture();
}).onFailure(e -> {
LOGGER.error(e.getMessage() + " SQL: \n" + createTableSQL);
});
futures.add(future);
});
Promise<Void> promise = Promise.promise();
Future.all(futures).onSuccess(r -> {
LOGGER.info("create table success");
promise.complete();
}).onFailure(promise::fail);
return promise.future();
}
}

View File

@@ -3,6 +3,7 @@ package cn.qaiu.db.pool;
import cn.qaiu.db.ddl.CreateTable;
import cn.qaiu.db.ddl.CreateDatabase;
import cn.qaiu.vx.core.util.VertxHolder;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.jdbcclient.JDBCPool;
@@ -80,10 +81,10 @@ public class JDBCPoolInit {
* init h2db<br>
* 这个方法只允许调用一次
*/
synchronized public void initPool() {
synchronized public Future<Void> initPool() {
if (pool != null) {
LOGGER.error("pool 重复初始化");
return;
return null;
}
// 初始化数据库连接
@@ -92,8 +93,8 @@ public class JDBCPoolInit {
CreateDatabase.createDatabase(dbConfig);
}
pool = JDBCPool.pool(vertx, dbConfig);
CreateTable.createTable(pool, type);
LOGGER.info("数据库连接初始化: URL=" + url);
return CreateTable.createTable(pool, type);
}
/**