Clover.NET coverage report - Coverage for s2dao.net

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

File Stats: LOC: 185   Methods: 12
NCLOC: 150 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Dao.Impl\AbstractAutoStaticCommand.cs 91.7% 91.8% 91.7% 91.7%
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.Text;
22   using Seasar.Extension.ADO;
23  
24   namespace Seasar.Dao.Impl
25   {
26   public abstract class AbstractAutoStaticCommand : AbstractStaticCommand
27   {
28   private IPropertyType[] propertyTypes;
29  
30 74 public AbstractAutoStaticCommand(IDataSource dataSource,
31   ICommandFactory commandFactory, IBeanMetaData beanMetaData, string[] propertyNames)
32   : base(dataSource, commandFactory, beanMetaData)
33   {
34 74 SetupPropertyTypes(propertyNames);
35 74 SetupSql();
36   }
37  
38 14 public override object Execute(object[] args)
39   {
40 14 AbstractAutoHandler handler = CreateAutoHandler();
41 14 handler.Sql = Sql;
42 14 int rows = handler.Execute(args);
43 14 if(rows != 1) throw new NotSingleRowUpdatedRuntimeException(args[0], rows);
44 12 return rows;
45   }
46  
47   protected IPropertyType[] PropertyTypes
48   {
49 14 get { return propertyTypes; }
50 0 set { propertyTypes = value; }
51   }
52  
53   protected abstract AbstractAutoHandler CreateAutoHandler();
54  
55   protected abstract void SetupPropertyTypes(string[] propertyNames);
56  
57 31 protected void SetupInsertPropertyTypes(string[] propertyNames)
58   {
59 31 ArrayList types = new ArrayList();
60 161 for(int i = 0; i < propertyNames.Length; ++i)
61   {
62 130 IPropertyType pt = BeanMetaData.GetPropertyType(propertyNames[i]);
63 130 if(pt.IsPrimaryKey && !BeanMetaData.IdentifierGenerator.IsSelfGenerate)
64 1 continue;
65 129 types.Add(pt);
66   }
67 31 propertyTypes = (IPropertyType[]) types.ToArray(typeof(IPropertyType));
68   }
69  
70 32 protected void SetupUpdatePropertyTypes(string[] propertyNames)
71   {
72 32 ArrayList types = new ArrayList();
73 167 for(int i = 0; i < propertyNames.Length; ++i)
74   {
75 135 IPropertyType pt = BeanMetaData.GetPropertyType(propertyNames[i]);
76 135 if(pt.IsPrimaryKey) continue;
77 103 types.Add(pt);
78   }
79 32 propertyTypes = (IPropertyType[]) types.ToArray(typeof(IPropertyType));
80   }
81  
82 11 protected virtual void SetupDeletePropertyTypes(string[] propertyNames)
83   {
84   }
85  
86   protected abstract void SetupSql();
87  
88 31 protected void SetupInsertSql()
89   {
90 31 IBeanMetaData bmd = BeanMetaData;
91 31 StringBuilder buf = new StringBuilder(100);
92 31 buf.Append("INSERT INTO ");
93 31 buf.Append(bmd.TableName);
94 31 buf.Append(" (");
95 160 for(int i = 0; i < propertyTypes.Length; ++i)
96   {
97 129 IPropertyType pt = propertyTypes[i];
98 129 buf.Append(pt.ColumnName);
99 129 buf.Append(", ");
100   }
101 31 buf.Length = buf.Length - 2;
102 31 buf.Append(") VALUES (");
103 160 for(int i = 0; i < propertyTypes.Length; ++i)
104   {
105   // Adapterにより切り替える必要あり
106 129 buf.Append("@");
107 129 buf.Append(propertyTypes[i].ColumnName);
108 129 buf.Append(", ");
109   }
110 31 buf.Length = buf.Length - 2;
111 31 buf.Append(")");
112 31 Sql = buf.ToString();
113   }
114  
115 32 protected void SetupUpdateSql()
116   {
117 32 CheckPrimaryKey();
118 32 StringBuilder buf = new StringBuilder(100);
119 32 buf.Append("UPDATE ");
120 32 buf.Append(BeanMetaData.TableName);
121 32 buf.Append(" SET ");
122 135 for(int i = 0; i < propertyTypes.Length; ++i)
123   {
124 103 IPropertyType pt = propertyTypes[i];
125 103 buf.Append(pt.ColumnName);
126 103 buf.Append(" = @");
127 103 buf.Append(pt.ColumnName);
128 103 buf.Append(", ");
129   }
130 32 buf.Length = buf.Length - 2;
131 32 SetupUpdateWhere(buf);
132 32 Sql = buf.ToString();
133   }
134  
135 11 protected void SetupDeleteSql()
136   {
137 11 CheckPrimaryKey();
138 11 StringBuilder buf = new StringBuilder(100);
139 11 buf.Append("DELETE FROM ");
140 11 buf.Append(BeanMetaData.TableName);
141 11 SetupUpdateWhere(buf);
142 11 Sql = buf.ToString();
143   }
144  
145 43 protected void CheckPrimaryKey()
146   {
147 43 IBeanMetaData bmd = BeanMetaData;
148 43 if(bmd.PrimaryKeySize == 0)
149 0 throw new PrimaryKeyNotFoundRuntimeException(bmd.BeanType);
150   }
151  
152 43 protected void SetupUpdateWhere(StringBuilder buf)
153   {
154 43 IBeanMetaData bmd = BeanMetaData;
155 43 buf.Append(" WHERE ");
156 86 for(int i = 0; i < bmd.PrimaryKeySize; ++i)
157   {
158 43 buf.Append(bmd.GetPrimaryKey(i));
159 43 buf.Append(" = @");
160 43 buf.Append(bmd.GetPrimaryKey(i));
161 43 buf.Append(" AND ");
162   }
163 43 buf.Length = buf.Length - 5;
164 43 if(bmd.HasVersionNoPropertyType)
165   {
166 8 IPropertyType pt = bmd.VersionNoPropertyType;
167 8 buf.Append(" AND ");
168 8 buf.Append(pt.ColumnName);
169 8 buf.Append(" = @");
170 8 buf.Append(bmd.VersionNoBindingName);
171   }
172 43 if(bmd.HasTimestampPropertyType)
173   {
174 0 IPropertyType pt = bmd.TimestampPropertyType;
175 0 buf.Append(" AND ");
176 0 buf.Append(pt.ColumnName);
177 0 buf.Append(" = @");
178 0 buf.Append(bmd.TimestampBindingName);
179   }
180   }
181  
182  
183   }
184   }
185