Clover.NET coverage report - Coverage for s2dao.net

Coverage timestamp: 2006年5月18日 15:09:15

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 68 public AbstractAutoStaticCommand(IDataSource dataSource,
31   ICommandFactory commandFactory, IBeanMetaData beanMetaData, string[] propertyNames)
32   : base(dataSource, commandFactory, beanMetaData)
33   {
34 68 SetupPropertyTypes(propertyNames);
35 68 SetupSql();
36   }
37  
38 12 public override object Execute(object[] args)
39   {
40 12 AbstractAutoHandler handler = CreateAutoHandler();
41 12 handler.Sql = Sql;
42 12 int rows = handler.Execute(args);
43 12 if(rows != 1) throw new NotSingleRowUpdatedRuntimeException(args[0], rows);
44 10 return rows;
45   }
46  
47   protected IPropertyType[] PropertyTypes
48   {
49 12 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 27 protected void SetupInsertPropertyTypes(string[] propertyNames)
58   {
59 27 ArrayList types = new ArrayList();
60 145 for(int i = 0; i < propertyNames.Length; ++i)
61   {
62 118 IPropertyType pt = BeanMetaData.GetPropertyType(propertyNames[i]);
63 118 if(pt.IsPrimaryKey && !BeanMetaData.IdentifierGenerator.IsSelfGenerate)
64 1 continue;
65 117 types.Add(pt);
66   }
67 27 propertyTypes = (IPropertyType[]) types.ToArray(typeof(IPropertyType));
68   }
69  
70 30 protected void SetupUpdatePropertyTypes(string[] propertyNames)
71   {
72 30 ArrayList types = new ArrayList();
73 159 for(int i = 0; i < propertyNames.Length; ++i)
74   {
75 129 IPropertyType pt = BeanMetaData.GetPropertyType(propertyNames[i]);
76 129 if(pt.IsPrimaryKey) continue;
77 99 types.Add(pt);
78   }
79 30 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 27 protected void SetupInsertSql()
89   {
90 27 IBeanMetaData bmd = BeanMetaData;
91 27 StringBuilder buf = new StringBuilder(100);
92 27 buf.Append("INSERT INTO ");
93 27 buf.Append(bmd.TableName);
94 27 buf.Append(" (");
95 144 for(int i = 0; i < propertyTypes.Length; ++i)
96   {
97 117 IPropertyType pt = propertyTypes[i];
98 117 buf.Append(pt.ColumnName);
99 117 buf.Append(", ");
100   }
101 27 buf.Length = buf.Length - 2;
102 27 buf.Append(") VALUES (");
103 144 for(int i = 0; i < propertyTypes.Length; ++i)
104   {
105   // Adapterにより切り替える必要あり
106 117 buf.Append("@");
107 117 buf.Append(propertyTypes[i].ColumnName);
108 117 buf.Append(", ");
109   }
110 27 buf.Length = buf.Length - 2;
111 27 buf.Append(")");
112 27 Sql = buf.ToString();
113   }
114  
115 30 protected void SetupUpdateSql()
116   {
117 30 CheckPrimaryKey();
118 30 StringBuilder buf = new StringBuilder(100);
119 30 buf.Append("UPDATE ");
120 30 buf.Append(BeanMetaData.TableName);
121 30 buf.Append(" SET ");
122 129 for(int i = 0; i < propertyTypes.Length; ++i)
123   {
124 99 IPropertyType pt = propertyTypes[i];
125 99 buf.Append(pt.ColumnName);
126 99 buf.Append(" = @");
127 99 buf.Append(pt.ColumnName);
128 99 buf.Append(", ");
129   }
130 30 buf.Length = buf.Length - 2;
131 30 SetupUpdateWhere(buf);
132 30 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 41 protected void CheckPrimaryKey()
146   {
147 41 IBeanMetaData bmd = BeanMetaData;
148 41 if(bmd.PrimaryKeySize == 0)
149 0 throw new PrimaryKeyNotFoundRuntimeException(bmd.BeanType);
150   }
151  
152 41 protected void SetupUpdateWhere(StringBuilder buf)
153   {
154 41 IBeanMetaData bmd = BeanMetaData;
155 41 buf.Append(" WHERE ");
156 82 for(int i = 0; i < bmd.PrimaryKeySize; ++i)
157   {
158 41 buf.Append(bmd.GetPrimaryKey(i));
159 41 buf.Append(" = @");
160 41 buf.Append(bmd.GetPrimaryKey(i));
161 41 buf.Append(" AND ");
162   }
163 41 buf.Length = buf.Length - 5;
164 41 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 41 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