(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Data / System.Data / DataRelation.cs
blobf249b6f013d2401c365f4c91896504dac603668d
1 //
2 // System.Data.DataRelation.cs
3 //
4 // Author:
5 // Daniel Morgan <danmorg@sc.rr.com>
6 // Alan Tam Siu Lung <Tam@SiuLung.com>
7 // Tim Coleman <tim@timcoleman.com>
8 //
9 // (C) 2002 Daniel Morgan
10 // (C) 2002 Ximian, Inc.
11 // Copyright (C) Tim Coleman, 2003
15 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
17 // Permission is hereby granted, free of charge, to any person obtaining
18 // a copy of this software and associated documentation files (the
19 // "Software"), to deal in the Software without restriction, including
20 // without limitation the rights to use, copy, modify, merge, publish,
21 // distribute, sublicense, and/or sell copies of the Software, and to
22 // permit persons to whom the Software is furnished to do so, subject to
23 // the following conditions:
24 //
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
27 //
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using System;
38 using System.ComponentModel;
39 using System.Runtime.Serialization;
41 namespace System.Data
43 /// <summary>
44 /// DataRelation is used for a parent/child relationship
45 /// between two DataTable objects
46 /// </summary>
47 [Editor]
48 [DefaultProperty ("RelationName")]
49 [Serializable]
50 [MonoTODO]
51 [TypeConverterAttribute (typeof (RelationshipConverter))]
52 public class DataRelation {
53 private DataSet dataSet;
54 private string relationName;
55 private UniqueConstraint parentKeyConstraint;
56 private ForeignKeyConstraint childKeyConstraint;
57 private DataColumn[] parentColumns;
58 private DataColumn[] childColumns;
59 private bool nested;
60 internal bool createConstraints;
61 private PropertyCollection extendedProperties;
62 private PropertyChangedEventHandler onPropertyChangingDelegate;
64 #region Constructors
66 public DataRelation (string relationName, DataColumn parentColumn, DataColumn childColumn)
67 : this(relationName, parentColumn, childColumn, true)
71 public DataRelation (string relationName, DataColumn[] parentColumns, DataColumn[] childColumns)
72 : this(relationName, parentColumns, childColumns, true)
76 public DataRelation (string relationName, DataColumn parentColumn, DataColumn childColumn, bool createConstraints)
77 : this(relationName, new DataColumn[] { parentColumn }, new DataColumn[] { childColumn }, createConstraints)
81 public DataRelation (string relationName, DataColumn[] parentColumns, DataColumn[] childColumns, bool createConstraints)
83 this.extendedProperties = new PropertyCollection();
84 if (relationName == null) relationName = string.Empty;
85 this.relationName = relationName;
86 if (parentColumns == null) throw new ArgumentNullException ();
87 this.parentColumns = parentColumns;
88 if (childColumns == null) throw new ArgumentNullException ();
89 this.childColumns = childColumns;
90 this.createConstraints = createConstraints;
91 if (parentColumns.Length != childColumns.Length)
92 throw new ArgumentException ("ParentColumns and ChildColumns should be the same length");
93 DataTable parentTable = parentColumns[0].Table;
94 DataTable childTable = childColumns[0].Table;
95 if (parentTable.DataSet != childTable.DataSet)
96 throw new InvalidConstraintException ();
97 foreach (DataColumn column in parentColumns)
98 if (column.Table != parentTable)
99 throw new InvalidConstraintException ();
100 foreach (DataColumn column in childColumns)
101 if (column.Table != childTable)
102 throw new InvalidConstraintException ();
104 for (int i=0; i<ChildColumns.Length; i++)
105 if (!( parentColumns[i].DataType.Equals( childColumns[i].DataType)))
106 throw new InvalidConstraintException();
109 [MonoTODO]
110 [Browsable (false)]
111 public DataRelation (string relationName, string parentTableName, string childTableName, string[] parentColumnNames, string[] childColumnNames, bool nested)
113 throw new NotImplementedException ();
116 #if NET_2_0
117 [MonoTODO]
118 public DataRelation (string relationName, string parentTableName, string parentTableNamespace, string childTableName, string childTableNamespace, string[] parentColumnNames, string[] childColumnNames, bool nested)
120 throw new NotImplementedException ();
122 #endif
124 #endregion // Constructors
126 #region Properties
128 [DataCategory ("Data")]
129 [DataSysDescription ("Indicates the child columns of this relation.")]
130 public virtual DataColumn[] ChildColumns {
131 get {
132 return childColumns;
136 public virtual ForeignKeyConstraint ChildKeyConstraint {
137 get {
138 return childKeyConstraint;
142 internal void SetChildKeyConstraint(ForeignKeyConstraint foreignKeyConstraint) {
143 childKeyConstraint = foreignKeyConstraint;
146 public virtual DataTable ChildTable {
147 get {
148 return childColumns[0].Table;
152 [Browsable (false)]
153 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
154 public virtual DataSet DataSet {
155 get {
156 return childColumns[0].Table.DataSet;
160 [Browsable (false)]
161 [DataCategory ("Data")]
162 [DataSysDescription ("The collection that holds custom user information.")]
163 public PropertyCollection ExtendedProperties {
164 get {
165 if (extendedProperties == null)
166 extendedProperties = new PropertyCollection();
167 return extendedProperties;
171 [DataCategory ("Data")]
172 [DataSysDescription ("Indicates whether relations are nested.")]
173 [DefaultValue (false)]
174 public virtual bool Nested {
175 get {
176 return nested;
179 set {
180 nested = value;
184 [DataCategory ("Data")]
185 [DataSysDescription ("Indicates the parent columns of this relation.")]
186 public virtual DataColumn[] ParentColumns {
187 get {
188 return parentColumns;
192 public virtual UniqueConstraint ParentKeyConstraint {
193 get {
194 return parentKeyConstraint;
198 internal void SetParentKeyConstraint(UniqueConstraint uniqueConstraint) {
199 parentKeyConstraint = uniqueConstraint;
202 internal void SetDataSet(DataSet ds) {
203 dataSet = ds;
206 public virtual DataTable ParentTable {
207 get {
208 return parentColumns[0].Table;
212 [DataCategory ("Data")]
213 [DataSysDescription ("The name used to look up this relation in the Relations collection of a DataSet.")]
214 [DefaultValue ("")]
215 public virtual string RelationName {
216 get {
217 return relationName;
220 set {
221 relationName = value;
225 #endregion // Properties
227 #region Methods
229 protected void CheckStateForProperty ()
231 // TODO: check consistency of constraints
232 DataTable parentTable = parentColumns[0].Table;
233 DataTable childTable = parentColumns[0].Table;
234 if (parentTable.DataSet != childTable.DataSet)
235 throw new DataException ();
236 bool allColumnsEqual = false;
237 for (int colCnt = 0; colCnt < parentColumns.Length; ++colCnt) {
238 if (!parentColumns [colCnt].DataType.Equals (childColumns [colCnt].DataType))
239 throw new DataException ();
240 if (parentColumns [colCnt] != childColumns [colCnt]) allColumnsEqual = false;
242 if (allColumnsEqual) throw new DataException ();
245 protected internal void OnPropertyChanging (PropertyChangedEventArgs pcevent)
247 if (onPropertyChangingDelegate != null)
248 onPropertyChangingDelegate (this, pcevent);
251 protected internal void RaisePropertyChanging (string name)
253 OnPropertyChanging(new PropertyChangedEventArgs(name));
256 public override string ToString ()
258 return relationName;
261 #endregion // Methods