1   package org.unitedfront2.domain;
2   
3   import org.unitedfront2.dao.SampleDomainDao;
4   import org.unitedfront2.dao.SimpleFindable;
5   
6   public class SampleDomainTable extends SimpleTableModule<SampleDomain> {
7   
8       private SampleDomainDao sampleDomainDao;
9   
10      @Override
11      protected SimpleFindable<SampleDomain> getSimpleDao() {
12          return sampleDomainDao;
13      }
14  
15      /**
16       * サンプルドメインを取得します。
17       *
18       * @param code コード
19       * @return サンプルドメイン、見つからなければ <code>null</code>
20       */
21      public SampleDomain findByCode(String code) {
22          return sampleDomainDao.findByCode(code);
23      }
24  
25      /**
26       * サンプルドメインを取得します。
27       *
28       * @param code コード
29       * @return サンプルドメイン
30       * @throws IllegalArgumentException 指定したコードを持つサンプルドメインが存在しない
31       */
32      public SampleDomain getByCode(String code) throws IllegalArgumentException {
33          SampleDomain sampleDomain = findByCode(code);
34          if (sampleDomain == null) {
35              String message = "The sample domain code '" + code + "' not found.";
36              logger.warn(message);
37              throw new IllegalArgumentException(message);
38          }
39          return sampleDomain;
40      }
41  
42      /**
43       * サンプルドメインが存在するか判定します。
44       *
45       * @param code コード
46       * @return 存在するなら <code>true</code> 、存在しないなら <code>false</code>
47       */
48      public boolean existByCode(String code) {
49          return findByCode(code) != null;
50      }
51  
52      /**
53       * 登録されているサンプルドメインの総数を取得します。
54       *
55       * @return サンプルドメインの総数
56       */
57      public int count() {
58          return sampleDomainDao.count();
59      }
60  
61      public void setSampleDomainDao(SampleDomainDao sampleDomainDao) {
62          this.sampleDomainDao = sampleDomainDao;
63      }
64  }