New test.
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlBulkCopyColumnMapping.cs
1 //
2 // System.Data.SqlClient.SqlBulkCopyColumnMapping.cs
3 //
4 // Author:
5 //   Umadevi S <sumadevi@novell.com>
6 //
7
8 //
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32
33 namespace System.Data.SqlClient
34 {
35         /// <summary>
36         /// Class that defines the mapping between a column in the destination table and an
37         /// column in the datasource of SqlBulkCopy's instance
38         /// </summary>
39         
40         public sealed class SqlBulkCopyColumnMapping {
41
42         #region Fields
43         
44         int sourceOrdinal = 0;
45         int destinationOrdinal = 0;
46         string sourceColumn = null;
47         string destinationColumn = null;
48
49         #endregion //Fields
50
51         #region Constructors
52         
53         public SqlBulkCopyColumnMapping(){
54         
55         }
56         
57         public SqlBulkCopyColumnMapping(int sourceColumnOrdinal, int destinationOrdinal){
58                 this.sourceOrdinal = sourceColumnOrdinal;
59                 this.destinationOrdinal = destinationOrdinal;
60         }
61
62         public SqlBulkCopyColumnMapping(int sourceColumnOrdinal, string destinationColumn){
63                 this.sourceOrdinal = sourceColumnOrdinal;
64                 this.destinationColumn = destinationColumn;     
65         }
66
67         public SqlBulkCopyColumnMapping(string sourceColumn, int destinationOrdinal){
68                 this.sourceColumn = sourceColumn;               
69                 this.destinationOrdinal = destinationOrdinal;
70         }
71
72         public SqlBulkCopyColumnMapping(string sourceColumn, string destinationColumn){
73                 this.sourceColumn = sourceColumn;
74                 this.destinationColumn = destinationColumn;
75         }
76
77         # endregion //Constructors      
78
79         # region Properties
80         
81         public String DestinationColumn {
82                 get {
83                         if (this.destinationColumn != null)
84                                 return destinationColumn;
85                         else
86                                 return string.Empty; //ms:doesnot return null.
87                 }
88                 set {
89                         // ms: whenever the name is set the ordinal is reset to -1
90                         this.destinationOrdinal = -1;
91                         this.destinationColumn = value;
92                 }
93         }
94         
95         public String SourceColumn {
96                 get {
97                         if (this.sourceColumn != null)
98                                 return sourceColumn;
99                         else
100                                 return string.Empty;//ms doesnot return null
101                 }
102                 set {
103                         // ms: whenever the name is set the ordinal is reset to -1
104                         this.sourceOrdinal = -1;
105                         this.sourceColumn = value;
106                 }
107                                                                                                     
108         }
109
110
111         public int DestinationOrdinal {
112                 get {
113                          return this.destinationOrdinal;
114                 }
115                 set {
116                         // ms: whenever the ordinal is set, the name is null
117                         if (value < 0)
118                                 throw new ArgumentOutOfRangeException();
119                         this.destinationColumn = null;
120                         this.destinationOrdinal =  value;
121                 }
122                                                                                                     
123         }
124         
125         public int SourceOrdinal {
126                 get {
127                          return this.sourceOrdinal;
128                 }
129                 set {
130                         // ms: whenever the ordinal is set, the name is null
131                         if (value < 0)
132                                 throw new ArgumentOutOfRangeException();
133                         this.sourceColumn = null;
134                         this.sourceOrdinal =  value;
135                 }
136                                                                                                     
137         }
138
139         #endregion //Properties 
140         
141         }
142
143 }
144
145
146 #endif
147