OSDN Git Service

DBFlute-0.9.3に更新
[ea2ddl/ea2ddl.git] / ea2ddl-gen / dbflute / templates / om / csharp / allcommon / cbean / PagingInvoker.vmnet
1 \r
2 using System;\r
3 using System.Collections.Generic;\r
4 \r
5 namespace ${glPackageBaseCommonCBean} {\r
6 \r
7     public class ${glPagingInvokerName}<ENTITY> {\r
8 \r
9         // ===============================================================================\r
10         //                                                                       Attribute\r
11         //                                                                       =========\r
12         protected String _tableDbName;\r
13         protected bool _countLater;\r
14 \r
15         // ===============================================================================\r
16         //                                                                     Constructor\r
17         //                                                                     ===========\r
18         public ${glPagingInvokerName}(String tableDbName) {\r
19             this._tableDbName = tableDbName;\r
20         }\r
21 \r
22         // ===============================================================================\r
23         //                                                                          Invoke\r
24         //                                                                          ======\r
25         public ${glPagingResultBeanName}<ENTITY> InvokePaging(${glPagingHandlerName}<ENTITY> handler) {\r
26             AssertObjectNotNull("handler", handler);\r
27             ${glPagingBeanInterfaceName} pagingBean = handler.PagingBean;\r
28             AssertObjectNotNull("handler.getPagingBean()", pagingBean);\r
29             if (!pagingBean.IsFetchScopeEffective) {\r
30                 String msg = "The paging bean is not effective about fetch-scope!";\r
31                 msg = msg + " When you select page, you should set up fetch-scope of paging bean(Should invoke fetchFirst() and fetchPage()!).";\r
32                 msg = msg + " The paging bean is: " + pagingBean;\r
33                 throw new SystemException(msg);\r
34             }\r
35             int allRecordCount;\r
36             IList<ENTITY> selectedList;\r
37             if (_countLater) {\r
38                 selectedList = handler.Paging();\r
39                 allRecordCount = handler.Count();\r
40             } else {\r
41                 allRecordCount = handler.Count();\r
42                 selectedList = handler.Paging();\r
43             }\r
44             ${glPagingResultBeanName}<ENTITY> rb = new ${glResultBeanBuilderName}<ENTITY>(_tableDbName).BuildPagingResultBean(pagingBean, allRecordCount, selectedList);\r
45             if (IsNecessaryToReadPageAgain(rb)) {\r
46                 pagingBean.FetchPage(rb.AllPageCount);\r
47                 int reAllRecordCount = handler.Count();\r
48                 IList<ENTITY> reSelectedList = handler.Paging();\r
49                 return new ${glResultBeanBuilderName}<ENTITY>(_tableDbName).BuildPagingResultBean(pagingBean, reAllRecordCount, reSelectedList);\r
50             } else {\r
51                 return rb;\r
52             }\r
53         }\r
54 \r
55         protected bool IsNecessaryToReadPageAgain(${glPagingResultBeanName}<ENTITY> rb) {\r
56             return rb.AllRecordCount > 0 && rb.SelectedList.Count == 0;\r
57         }\r
58 \r
59         // ===============================================================================\r
60         //                                                                          Option\r
61         //                                                                          ======\r
62         public ${glPagingInvokerName}<ENTITY> CountLater() {\r
63             _countLater = true; return this;\r
64         }\r
65 \r
66         // ===============================================================================\r
67         //                                                                          Helper\r
68         //                                                                          ======\r
69         protected void AssertObjectNotNull(String variableName, Object value) {\r
70             if (variableName == null) {\r
71                 String msg = "The value should not be null: variableName=" + variableName + " value=" + value;\r
72                 throw new SystemException(msg);\r
73             }\r
74             if (value == null) {\r
75                 String msg = "The value should not be null: variableName=" + variableName;\r
76                 throw new SystemException(msg);\r
77             }\r
78         }\r
79     }\r
80 }\r