Re: Nutz(1.b.45) Dao的小建议

27 views
Skip to first unread message

Wendal Chen

unread,
Sep 2, 2012, 5:10:25 AM9/2/12
to xing kenny, nutzam
恩,都是可以接受的修改.

你发起一个pull req吧

2012/9/2 xing kenny <xing.ken...@gmail.com>
两位好!

我最近学习了Nutz(1.b.45) Dao的部分,有下面几个小建议。

      
... ...
@@ -1,4 +1,4 @@
1  
-package org.nutz.dao.impl;
  1
+package org.nutz.dao.impl;
2 2
 
3 3
 import java.sql.Connection;
4 4
 import java.sql.ResultSet;
... ...
@@ -652,9 +652,7 @@ public Pager createPager(int pageNumber, int pageSize) {
652 652
                 return en;
653 653
             }
654 654
         }
655  
-        en = holder.reloadEntity(classOfT); //需要重新载入,以免之前数据库表的信息影响Entity
656  
-        expert.createEntity(this, en);
657  
-        return holder.reloadEntity(classOfT); //再次重新载入,使配置信息与数据库信息相符
  655
+        return holder.reloadEntity(this, classOfT);
658 656
     }
 

66 66
     /**
67 67
      * 重新载入
68 68
      */
69  
-    public <T> Entity<T> reloadEntity(Class<T> classOfT) {
70  
-        Entity<T> re = getEntity(classOfT);
71  
-        if (null != re) {
72  
-            synchronized (map) {
73  
-                map.remove(re.getType());
74  
-            }
  69
+    public <T> Entity<T> reloadEntity(Dao dao, Class<T> classOfT) {
  70
+
  71
+        final Entity<T> re = maker.make(classOfT);
  72
+        synchronized (map) {
  73
+            map.put(classOfT, re);
75 74
         }
76  
-        return getEntity(classOfT);
  75
+        support.expert.createEntity(dao, re);
  76
+        // 最后在数据库中验证一下实体各个字段
  77
+        support.run(new ConnCallback() {
  78
+            public void invoke(Connection conn) throws Exception {
  79
+                support.expert.setupEntityField(conn, re);
  80
+            }
  81
+        });
  82
+        return re;
77 83
     }

2、 Extract NutDaoExecutor._runSelect()  , 参见 https://github.com/xing-kenny/nutz/commit/f169a95ec8772b87d7654b85271ceda46b16a605
3、 UT SimpleDaoTest 的 before() 方法不需要 @Before 声明,参见  https://github.com/xing-kenny/nutz/commit/f3b5a69d4afaab49ecc99c09c211344ccfa35de8
4、 ManyLinkField,ManyManyLinkField,OneLinkField  不需要再声明 ‘implements LinkField’ , 参见 https://github.com/xing-kenny/nutz/commit/8af4a20aecee12cb629d30c0aa18648858d393d0
       从类图上看,声明了不够清爽。       

                                                                                                                                                                                                        此致!
                                                                                                                                                                                                xing kenny




--
Wendal Chen
GuangDong China
Reply all
Reply to author
Forward
0 new messages