Clover.NET coverage report - Coverage

Coverage timestamp: Friday, May 20, 2005 9:17:00 PM

File Stats: LOC: 135   Methods: 6
NCLOC: 75 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
TypeHandlers\ByteArrayTypeHandler.cs 50.0 % 73.1 % 33.3 % 63.2 %
coverage coverage
1  
2   #region Apache Notice
3   /*****************************************************************************
4   * $Header: $
5   * $Revision: $
6   * $Date: $
7   *
8   * iBATIS.NET Data Mapper
9   * Copyright (C) 2004 - Gilles Bayon
10   *
11   *
12   * Licensed under the Apache License, Version 2.0 (the "License");
13   * you may not use this file except in compliance with the License.
14   * You may obtain a copy of the License at
15   *
16   * http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing, software
19   * distributed under the License is distributed on an "AS IS" BASIS,
20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   * See the License for the specific language governing permissions and
22   * limitations under the License.
23   *
24   ********************************************************************************/
25   #endregion
26  
27   #region using
28   using System;
29   using System.Data;
30   using System.Globalization;
31   using System.IO;
32  
33   using IBatisNet.DataMapper.Configuration.ResultMapping;
34   using IBatisNet.DataMapper.Exceptions;
35   #endregion
36  
37  
38   namespace IBatisNet.DataMapper.TypeHandlers
39   {
40   /// <summary>
41   /// Description résumée de ByteArrayTypeHandler.
42   /// </summary>
43   internal class ByteArrayTypeHandler : BaseTypeHandler
44   {
45  
46  
47   /// <summary>
48   ///
49   /// </summary>
50   /// <param name="mapping"></param>
51   /// <param name="dataReader"></param>
52   /// <returns></returns>
53 2 public override object GetValueByName(ResultProperty mapping, IDataReader dataReader)
54   {
55 2 int index = dataReader.GetOrdinal(mapping.ColumnName);
56  
57 2 if (dataReader.IsDBNull(index) == true)
58   {
59 0 return System.DBNull.Value;
60   }
61   else
62   {
63 2 return GetValueByIndex(index, dataReader);
64   }
65   }
66  
67 0 public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
68   {
69   if (dataReader.IsDBNull(mapping.ColumnIndex) == true)
70   {
71   return System.DBNull.Value;
72   }
73   else
74   {
75   return GetValueByIndex(mapping.ColumnIndex, dataReader);
76   }
77   }
78  
79  
80 2 private byte[] GetValueByIndex(int columnIndex, IDataReader dataReader)
81   {
82 2 int bufferSize = 100; // Size of the BLOB buffer.
83 2 byte[] buffer = new byte[bufferSize]; // The BLOB byte[] buffer to be filled by GetBytes.
84 2 long size = bufferSize; // The bytes returned from GetBytes.
85 2 long startIndex = 0; // The data position in the BLOB output.
86 2 MemoryStream stream = null; // Writes the BLOB to a memory stream.
87  
88   // Create a memory stream to hold the output.
89 2 stream = new MemoryStream();
90  
91   // Reset the starting byte for the new BLOB.
92 2 startIndex = 0;
93  
94   // Read the bytes into outbyte[] and retain the number of bytes returned.
95 2 size = dataReader.GetBytes(columnIndex, startIndex , buffer, 0, bufferSize);
96  
97   // Continue reading and writing while there are bytes beyond the size of the buffer.
98 13 while (size == bufferSize)
99   {
100 11 stream.Write(buffer, 0, (int)size);
101 11 stream.Flush();
102  
103   // Reposition the start index to the end of the last buffer and fill the buffer.
104 11 startIndex += bufferSize;
105 11 size = dataReader.GetBytes(columnIndex, startIndex, buffer, 0, bufferSize);
106   }
107  
108   // Write the remaining buffer.
109 2 stream.Write(buffer, 0, (int)size);
110 2 stream.Flush();
111  
112 2 return stream.ToArray();
113   }
114  
115  
116 0 public override object ValueOf(Type type, string s)
117   {
118   return System.Text.Encoding.Default.GetBytes(s);
119   }
120  
121 0 public override object GetDataBaseValue(object outputValue, Type parameterType )
122   {
123   throw new DataMapperException("NotSupportedException");
124   }
125  
126 0 public override bool IsSimpleType
127   {
128   get
129   {
130   return true;
131   }
132   }
133   }
134   }
135