Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / ActiveRecord / Castle.ActiveRecord / Attributes / RelationAttribute.cs
blob8f9f4f70be3a09475174c7ab94bd8f1790da3c0d
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.ActiveRecord
17 using System;
18 using Castle.ActiveRecord.Framework.Internal;
20 /// <summary>
21 /// Define the relation type for a relation.
22 /// </summary>
23 [Serializable]
24 public enum RelationType
26 /// <summary>
27 /// Let Active Record guess what is the type of the relation.
28 /// </summary>
29 Guess,
30 /// <summary>
31 /// An bag of items (allow duplicates)
32 /// </summary>
33 Bag,
34 /// <summary>
35 /// A set of unique items
36 /// </summary>
37 Set,
38 /// <summary>
39 /// A bag of items with id
40 /// </summary>
41 IdBag,
42 /// <summary>
43 /// Map of key/value pairs (IDictionary)
44 /// </summary>
45 Map,
46 /// <summary>
47 /// A list of items - position in the list has meaning
48 /// </summary>
49 List
52 /// <summary>
53 /// Base class to define common relation information
54 /// </summary>
55 [AttributeUsage(AttributeTargets.Property), Serializable]
56 public abstract class RelationAttribute : BaseAttribute
58 internal Type mapType;
59 internal String table;
60 internal String schema;
61 internal String orderBy;
62 internal String where;
63 internal String sort;
64 internal String index;
65 internal String indexType;
66 internal String element, elementType;
67 internal bool lazy;
68 internal bool lazySpecified = false;
69 internal bool inverse;
70 internal ManyRelationCascadeEnum cascade = ManyRelationCascadeEnum.None;
71 internal RelationType relType = RelationType.Guess;
72 internal NotFoundBehaviour notFoundBehaviour = NotFoundBehaviour.Default;
73 private int batchSize = 1;
75 /// <summary>
76 /// Gets or sets the type of the relation.
77 /// </summary>
78 /// <value>The type of the relation.</value>
79 public RelationType RelationType
81 get { return relType; }
82 set { relType = value; }
85 /// <summary>
86 /// Gets or sets the type of the map.
87 /// </summary>
88 /// <value>The type of the map.</value>
89 public Type MapType
91 get { return mapType; }
92 set { mapType = value; }
95 /// <summary>
96 /// Gets or sets the table for this relation
97 /// </summary>
98 /// <value>The table.</value>
99 public String Table
101 get { return table; }
102 set { table = value; }
105 /// <summary>
106 /// Gets or sets the schema for this relation (dbo., etc)
107 /// </summary>
108 /// <value>The schema name.</value>
109 public String Schema
111 get { return schema; }
112 set { schema = value; }
115 /// <summary>
116 /// Gets or sets a value indicating whether this <see cref="RelationAttribute"/> is lazy.
117 /// </summary>
118 /// <value><c>true</c> if lazy; otherwise, <c>false</c>.</value>
119 public bool Lazy
123 if(lazySpecified)
124 return lazy;
125 return ActiveRecordModel.isLazyByDefault;
129 lazy = value;
130 lazySpecified = true;
134 /// <summary>
135 /// Gets or sets a value indicating whether this <see cref="RelationAttribute"/> is inverse.
136 /// </summary>
137 /// <value><c>true</c> if inverse; otherwise, <c>false</c>.</value>
138 public bool Inverse
140 get { return inverse; }
141 set { inverse = value; }
144 /// <summary>
145 /// Gets or sets the cascade options for this <see cref="RelationAttribute"/>
146 /// </summary>
147 /// <value>The cascade.</value>
148 public ManyRelationCascadeEnum Cascade
150 get { return cascade; }
151 set { cascade = value; }
154 /// <summary>
155 /// Gets or sets the order by clause for this relation. This is a SQL order, not HQL.
156 /// </summary>
157 public String OrderBy
159 get { return orderBy; }
160 set { orderBy = value; }
163 /// <summary>
164 /// Gets or sets the where clause for this relation
165 /// </summary>
166 public String Where
168 get { return where; }
169 set { where = value; }
172 /// <summary>
173 /// Only used with sets. The value can be <c>unsorted</c>, <c>natural</c> and the name of a class implementing <c>System.Collections.IComparer</c>
174 /// </summary>
175 public String Sort
177 get { return sort; }
178 set { sort = value; }
181 /// <summary>
182 /// Only used with maps or lists
183 /// </summary>
184 public string Index
186 get { return index; }
187 set { index = value; }
190 /// <summary>
191 /// Only used with maps
192 /// </summary>
193 public string IndexType
195 get { return indexType; }
196 set { indexType = value; }
199 /// <summary>
200 /// Use for simple types.
201 /// </summary>
202 public string Element
204 get { return element; }
205 set { element = value; }
208 /// <summary>
209 /// Use for simple types.
210 /// </summary>
211 public string ElementType
213 get { return elementType; }
214 set { elementType = value; }
217 /// <summary>
218 /// Gets or sets the way broken relations are handled.
219 /// </summary>
220 /// <value>The behaviour.</value>
221 public NotFoundBehaviour NotFoundBehaviour
223 get { return notFoundBehaviour; }
224 set { notFoundBehaviour = value; }
227 /// <summary>
228 /// From NHibernate documentation:
229 /// Specify a "batch size" for batch fetching of collections.
230 /// </summary>
231 public int BatchSize
233 get { return batchSize; }
234 set { batchSize = value; }