Fixing an issue with output parameters that are of type IntPtr
[castle.git] / ActiveRecord / Castle.ActiveRecord / Attributes / PrimaryKeyAttribute.cs
blobe0f0f055279af102aa4aff290c3531ab9d538eea
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;
19 /// <summary>
20 /// Define the possible strategies to set the Primary Key values
21 /// </summary>
22 [Serializable]
23 public enum PrimaryKeyType
25 /// <summary>
26 /// Use Identity column (auto number)
27 /// Note: This force an immediate call to the DB when Create() is called
28 /// </summary>
29 Identity,
30 /// <summary>
31 /// Use a sequence
32 /// </summary>
33 Sequence,
34 /// <summary>
35 /// Use the HiLo algorithm to get the next value
36 /// </summary>
37 HiLo,
38 /// <summary>
39 /// Use a sequence and a HiLo algorithm - better performance on Oracle
40 /// </summary>
41 SeqHiLo,
42 /// <summary>
43 /// Use the hex representation of a unique identifier
44 /// </summary>
45 UuidHex,
46 /// <summary>
47 /// Use the string representation of a unique identifier
48 /// </summary>
49 UuidString,
50 /// <summary>
51 /// Generate a Guid for the primary key
52 /// Note: You should prefer using GuidComb over this value.
53 /// </summary>
54 Guid,
55 /// <summary>
56 /// Generate a Guid in sequence, so it will have better insert performance in the DB.
57 /// </summary>
58 GuidComb,
59 /// <summary>
60 /// Use an identity or sequence if supported by the database, otherwise, use the HiLo algorithm
61 /// </summary>
62 Native,
63 /// <summary>
64 /// The primary key value is always assigned.
65 /// Note: using this you will lose the ability to call Save(), and will need to call Create() or Update()
66 /// explicitly.
67 /// </summary>
68 Assigned,
69 /// <summary>
70 /// This is a foreign key to another table
71 /// </summary>
72 Foreign,
73 /// <summary>
74 /// Returns a <c>Int64</c> constructed from the system
75 /// time and a counter value.
76 /// </summary>
77 /// <remarks>
78 /// Not safe for use in a clustser
79 /// </remarks>
80 Counter,
81 /// <summary>
82 /// Returns a <c>Int64</c>, constructed by counting from
83 /// the maximum primary key value at startup.
84 /// </summary>
85 /// <remarks>
86 /// Not safe for use in a cluster
87 /// </remarks>
88 Increment,
89 /// <summary>
90 /// A custom generator will be provided. See <see cref="PrimaryKeyAttribute.CustomGenerator"/>
91 /// </summary>
92 Custom
95 /// <summary>
96 /// Indicates the property which is the primary key.
97 /// </summary>
98 /// <example><code>
99 /// public class Blog : ActiveRecordBase
100 /// {
101 /// ...
102 ///
103 /// [PrimaryKey(PrimaryKeyType.Native)]
104 /// public int Id
105 /// {
106 /// get { return _id; }
107 /// set { _id = value; }
108 /// }
109 /// </code></example>
110 [AttributeUsage(AttributeTargets.Property, AllowMultiple=false), Serializable]
111 public class PrimaryKeyAttribute : WithAccessAttribute
113 private PrimaryKeyType generator = PrimaryKeyType.Native;
114 private Type customGenerator;
115 private String column;
116 private String unsavedValue;
117 private String sequenceName;
118 private String type;
119 private String _params;
120 private int length;
121 private bool isOverride;
123 /// <summary>
124 /// Initializes a new instance of the <see cref="PrimaryKeyAttribute"/> class.
125 /// </summary>
126 public PrimaryKeyAttribute() : this(PrimaryKeyType.Native)
130 /// <summary>
131 /// Initializes a new instance of the <see cref="PrimaryKeyAttribute"/> class.
132 /// </summary>
133 /// <param name="customGenerator">A custom identifier
134 /// generator (that implements <see cref="NHibernate.Id.IIdentifierGenerator"/>).</param>
135 public PrimaryKeyAttribute(Type customGenerator) : this(PrimaryKeyType.Custom)
137 this.customGenerator = customGenerator;
140 /// <summary>
141 /// Initializes a new instance of the <see cref="PrimaryKeyAttribute"/> class.
142 /// </summary>
143 /// <param name="generator">The generator.</param>
144 public PrimaryKeyAttribute(PrimaryKeyType generator)
146 this.generator = generator;
149 /// <summary>
150 /// Initializes a new instance of the <see cref="PrimaryKeyAttribute"/> class.
151 /// </summary>
152 /// <param name="generator">The generator.</param>
153 /// <param name="column">The PK column.</param>
154 public PrimaryKeyAttribute(PrimaryKeyType generator, String column) : this(generator)
156 this.column = column;
159 /// <summary>
160 /// Initializes a new instance of the <see cref="PrimaryKeyAttribute"/> class.
161 /// </summary>
162 /// <param name="column">The PK column.</param>
163 public PrimaryKeyAttribute(string column)
165 this.column = column;
168 /// <summary>
169 /// Gets or sets the generator.
170 /// </summary>
171 /// <value>The generator.</value>
172 public PrimaryKeyType Generator
174 get { return generator; }
175 set { generator = value; }
178 /// <summary>
179 /// Gets or sets the column name
180 /// </summary>
181 /// <value>The column.</value>
182 public String Column
184 get { return column; }
185 set { column = value; }
188 /// <summary>
189 /// Gets or sets the unsaved value.
190 /// </summary>
191 /// <value>The unsaved value.</value>
192 public String UnsavedValue
194 get { return unsavedValue; }
195 set { unsavedValue = value; }
198 /// <summary>
199 /// Gets or sets the name of the sequence.
200 /// </summary>
201 /// <value>The name of the sequence.</value>
202 public String SequenceName
204 get { return sequenceName; }
205 set { sequenceName = value; }
208 /// <summary>
209 /// Gets or sets the type of the column.
210 /// </summary>
211 /// <value>The type of the column.</value>
212 public String ColumnType
214 get { return type; }
215 set { type = value; }
218 /// <summary>
219 /// Gets or sets the length of values in the column
220 /// </summary>
221 /// <value>The length.</value>
222 public int Length
224 get { return length; }
225 set { length = value; }
228 /// <summary>
229 /// Gets or sets the custom generator.
230 /// The generator must implement <see cref="NHibernate.Id.IIdentifierGenerator"/>
231 /// </summary>
232 /// <value>The custom generator type.</value>
233 public Type CustomGenerator
235 get { return customGenerator; }
236 set { customGenerator = value; }
239 /// <summary>
240 /// Comma separated value of parameters to the generator
241 /// </summary>
242 public String Params
244 get { return _params; }
245 set { _params = value; }
248 /// <summary>
249 /// Set to <c>true</c> if this primary key overrides a primary key in a base class
250 /// </summary>
251 public bool IsOverride
253 get { return isOverride; }
254 set { isOverride = value; }