Clover.NET coverage report - Coverage for s2dao.net

Coverage timestamp: 2006年5月30日 11:48:56

File Stats: LOC: 91   Methods: 8
NCLOC: 62 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Dao.Id\IdentifierGeneratorFactory.cs 83.3% 95.0% 87.5% 91.2%
coverage coverage
1   #region Copyright
2   /*
3   * Copyright 2005 the Seasar Foundation and the Others.
4   *
5   * Licensed under the Apache License, Version 2.0 (the "License");
6   * you may not use this file except in compliance with the License.
7   * You may obtain a copy of the License at
8   *
9   * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14   * either express or implied. See the License for the specific language
15   * governing permissions and limitations under the License.
16   */
17   #endregion
18  
19   using System;
20   using System.Collections;
21   using System.Reflection;
22   using Seasar.Dao.Attrs;
23   using Seasar.Framework.Util;
24  
25   namespace Seasar.Dao.Id
26   {
27   /// <summary>
28   /// IdentifierGeneratorFactory の概要の説明です。
29   /// </summary>
30   public class IdentifierGeneratorFactory
31   {
32   private static Hashtable generatorTypes = new Hashtable();
33  
34 1 static IdentifierGeneratorFactory()
35   {
36 1 AddIdentifierGeneratorType("assigned", typeof(AssignedIdentifierGenerator));
37 1 AddIdentifierGeneratorType("identity", typeof(IdentityIdentifierGenerator));
38 1 AddIdentifierGeneratorType("sequence", typeof(SequenceIdentifierGenerator));
39   }
40  
41 0 private IdentifierGeneratorFactory()
42   {
43   }
44  
45 3 public static void AddIdentifierGeneratorType(string name, Type type)
46   {
47 3 generatorTypes[name] = type;
48   }
49  
50 59 public static IIdentifierGenerator CreateIdentifierGenerator(
51   string propertyName, IDbms dbms)
52   {
53 59 return CreateIdentifierGenerator(propertyName, dbms, null);
54   }
55  
56 65 public static IIdentifierGenerator CreateIdentifierGenerator(
57   string propertyName, IDbms dbms, IDAttribute idAttr)
58   {
59 65 if(idAttr == null)
60 60 return new AssignedIdentifierGenerator(propertyName, dbms);
61 5 Type type = GetGeneratorType(idAttr.ID);
62 5 IIdentifierGenerator generator = CreateIdentifierGenerator(type, propertyName, dbms);
63 5 if(idAttr.SequenceName != null)
64 2 SetProperty(generator, "SequenceName", idAttr.SequenceName);
65 5 return generator;
66   }
67  
68 5 protected static Type GetGeneratorType(string name)
69   {
70 5 Type type = (Type) generatorTypes[name];
71 5 if(type != null) return type;
72 0 return ClassUtil.ForName(name, AppDomain.CurrentDomain.GetAssemblies());
73   }
74  
75 5 protected static IIdentifierGenerator CreateIdentifierGenerator(
76   Type type, string propertyName, IDbms dbms)
77   {
78 5 ConstructorInfo constructor =
79   ClassUtil.GetConstructorInfo(type, new Type[] { typeof(string), typeof(IDbms) });
80 5 return (IIdentifierGenerator)
81   ConstructorUtil.NewInstance(constructor, new object[] { propertyName, dbms });
82   }
83  
84 2 protected static void SetProperty(IIdentifierGenerator generator, string propertyName, string value)
85   {
86 2 PropertyInfo property = generator.GetType().GetProperty(propertyName);
87 2 property.SetValue(generator, value, null);
88   }
89   }
90   }
91