From 130b839c9d04a0a2da22cba6cde4217e573e75af Mon Sep 17 00:00:00 2001 From: RB Date: Tue, 5 Mar 2024 23:00:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AD=97=E6=AE=B5=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/metadata/impl/Field2Schema.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/rebuild/core/metadata/impl/Field2Schema.java b/src/main/java/com/rebuild/core/metadata/impl/Field2Schema.java index dac34d559..5c92d879e 100644 --- a/src/main/java/com/rebuild/core/metadata/impl/Field2Schema.java +++ b/src/main/java/com/rebuild/core/metadata/impl/Field2Schema.java @@ -438,27 +438,37 @@ public class Field2Schema extends SetUser { meta.setString("displayType", toType.name()); Application.getCommonsService().update(meta, false); - Dialect dialect = Application.getPersistManagerFactory().getDialect(); - final Table table = new Table(field.getOwnEntity(), dialect); - StringBuilder ddl = new StringBuilder(); - table.generateFieldDDL(field, ddl); - - String alterSql = String.format("alter table `%s` change column `%s` ", - field.getOwnEntity().getPhysicalName(), field.getPhysicalName()); - alterSql += ddl.toString().trim(); + // 类型生效 + DynamicMetadataContextHolder.setSkipLanguageRefresh(); + MetadataHelper.getMetadataFactory().refresh(); + field = MetadataHelper.getField(field.getOwnEntity().getName(), field.getName()); + String alterTypeSql = null; try { - Application.getSqlExecutor().executeBatch(new String[]{alterSql}, DDL_TIMEOUT); + Dialect dialect = Application.getPersistManagerFactory().getDialect(); + final Table table = new Table(field.getOwnEntity(), dialect); + StringBuilder ddl = new StringBuilder(); + table.generateFieldDDL(field, ddl); + + alterTypeSql = String.format("alter table `%s` change column `%s` ", + field.getOwnEntity().getPhysicalName(), field.getPhysicalName()); + alterTypeSql += ddl.toString().trim().replace(" ", ""); + + Application.getSqlExecutor().executeBatch(new String[]{alterTypeSql}, DDL_TIMEOUT); + log.info("Cast field type : {}", alterTypeSql); + } catch (Throwable ex) { // 还原 meta.setString("displayType", EasyMetaFactory.getDisplayType(field).name()); Application.getCommonsService().update(meta, false); - log.error("DDL ERROR : \n" + alterSql, ex); + log.error("DDL ERROR : \n" + alterTypeSql, ex); throw new MetadataModificationException(ThrowableUtils.getRootCause(ex).getLocalizedMessage()); + } finally { + MetadataHelper.getMetadataFactory().refresh(); + DynamicMetadataContextHolder.isSkipLanguageRefresh(true); } - MetadataHelper.getMetadataFactory().refresh(); return true; } }