From 6b2ede7aaf1aca8eb95ee51283c7091e1963a688 Mon Sep 17 00:00:00 2001 From: Wizzer Date: Fri, 10 May 2024 18:01:36 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E9=80=9A=E8=BF=87map=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E8=A1=A8=E7=BB=93=E6=9E=84=E6=96=B0=E5=A2=9E=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=9A=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AEcustomtyp?= =?UTF-8?q?e=E3=80=81=E8=A1=A8=E6=B3=A8=E9=87=8A=E3=80=81=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nutz/dao/impl/entity/MapEntityMaker.java | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/org/nutz/dao/impl/entity/MapEntityMaker.java b/src/org/nutz/dao/impl/entity/MapEntityMaker.java index ea54e0d0a..19e12d3fc 100644 --- a/src/org/nutz/dao/impl/entity/MapEntityMaker.java +++ b/src/org/nutz/dao/impl/entity/MapEntityMaker.java @@ -1,12 +1,5 @@ package org.nutz.dao.impl.entity; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Map; -import java.util.Map.Entry; - -import javax.sql.DataSource; - import org.nutz.dao.entity.Entity; import org.nutz.dao.entity.annotation.ColType; import org.nutz.dao.impl.EntityHolder; @@ -21,6 +14,12 @@ import org.nutz.log.Log; import org.nutz.log.Logs; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Map; +import java.util.Map.Entry; + public class MapEntityMaker { private static final Log log = Logs.get(); @@ -31,9 +30,18 @@ public class MapEntityMaker { @SuppressWarnings({"unchecked", "rawtypes"}) public > Entity make(String tableName, T map) { + return this.make(tableName, map, false, false, null); + } + + public > Entity make(String tableName, T map, boolean hasColumnComment, boolean hasTableComment, String tableComment) { final NutEntity en = new NutEntity(map.getClass()); en.setTableName(tableName); en.setViewName(tableName); + en.setHasColumnComment(hasColumnComment); + en.setHasTableComment(hasTableComment); + if (tableComment != null) { + en.setTableComment(tableComment); + } boolean check = false; for (Entry entry : map.entrySet()) { String key = entry.getKey(); @@ -51,7 +59,7 @@ else if (key.startsWith(".")) { Object value = entry.getValue(); Mirror mirror = Mirror.me(value); NutMappingField ef = new NutMappingField(en); - + ef.setHasColumnComment(hasColumnComment); while (true) { if (key.startsWith("+")) { ef.setAsAutoIncreasement(); @@ -113,13 +121,24 @@ else if (key.startsWith(".")) { ef.setWidth((Integer) w); } } + + // 字段备注 + if (map.containsKey("." + key + ".comment")) { + ef.setColumnComment((String) map.get("." + key + ".comment")); + } + + // 自定义字段类型 + if (map.containsKey("." + key + ".customtype")) { + ef.setCustomDbType((String) map.get("." + key + ".customtype")); + } + ef.setInjecting(new InjectToMap(key)); // 这里比较纠结,回设的时候应该用什么呢? ef.setEjecting(new EjectFromMap(entry.getKey())); if (ef.isAutoIncreasement() - && ef.isId() - && expert.isSupportAutoIncrement() - && !expert.isSupportGeneratedKeys()) { + && ef.isId() + && expert.isSupportAutoIncrement() + && !expert.isSupportGeneratedKeys()) { en.addAfterInsertMacro(expert.fetchPojoId(en, ef)); } @@ -137,13 +156,11 @@ else if (key.startsWith(".")) { try { conn = dataSource.getConnection(); expert.setupEntityField(conn, en); - } - finally { + } finally { if (conn != null) conn.close(); } - } - catch (SQLException e) { + } catch (SQLException e) { log.debug(e.getMessage(), e); } }