1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using NHibernate
.Persister
.Entity
;
21 /// Associate meta information related to the
22 /// desired table mapping.
26 /// [ActiveRecord("tb_Order")]
27 /// public class Order : ActiveRecordBase
33 /// If no table is specified, the class name
34 /// is used as table name
36 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=false), Serializable
]
37 public class ActiveRecordAttribute
: BaseAttribute
40 private String schema
;
41 private String discriminatorType
;
42 private String discriminatorValue
;
43 private String discriminatorColumn
;
44 private String discriminatorLength
;
47 private Type persister
;
49 private bool dynamicUpdate
;
50 private bool dynamicInsert
;
51 private bool selectBeforeUpdate
;
52 private bool mutable
= true;
53 private bool useAutoImport
= true;
54 private int batchSize
= 1;
55 private Polymorphism polymorphism
= Polymorphism
.Implicit
;
56 private OptimisticLocking locking
= OptimisticLocking
.Version
;
57 private bool lazySpecified
;
60 /// Uses the class name as table name
62 public ActiveRecordAttribute() {}
65 /// Associates the specified table with the target type
67 /// <param name="table"></param>
68 public ActiveRecordAttribute(String table
)
74 /// Associates the specified table and schema with the target type
76 public ActiveRecordAttribute(String table
, String schema
)
83 /// Gets or sets the table name associated with the type
88 set { table = value; }
92 /// Gets or sets the schema name associated with the type
96 get { return schema; }
97 set { schema = value; }
101 /// Associates a proxy type with the target type
105 get { return proxy; }
106 set { proxy = value; }
110 /// Gets or sets the Discriminator column for
111 /// a table inheritance modeling
113 public String DiscriminatorColumn
115 get { return discriminatorColumn; }
116 set { discriminatorColumn = value; }
120 /// Gets or sets the column type (like string or integer)
121 /// for the discriminator column
123 public String DiscriminatorType
125 get { return discriminatorType; }
126 set { discriminatorType = value; }
130 /// Gets or sets the value that represents the
131 /// target class on the discriminator column
133 public String DiscriminatorValue
135 get { return discriminatorValue; }
136 set { discriminatorValue = value; }
140 /// Gets or sets the length of the discriminator
141 /// column (valid for string type only)
143 public String DiscriminatorLength
145 get { return discriminatorLength; }
146 set { discriminatorLength = value; }
150 /// SQL condition to retrieve objects
154 get { return where; }
155 set { where = value; }
159 /// Enable lazy loading for the type
166 lazySpecified
= true;
172 /// Gets a value indicating whether explicit lazy behavior was specified.
173 /// If explicit lazy behavior was not specified, it goes to the configuration to decide if the type should
176 public bool LazySpecified
178 get { return this.lazySpecified; }
182 /// From NHibernate documentation:
183 /// Specifies that UPDATE SQL should be
184 /// generated at runtime and contain only
185 /// those columns whose values have changed.
187 public bool DynamicUpdate
189 get { return dynamicUpdate; }
190 set { dynamicUpdate = value; }
194 /// From NHibernate documentation:
195 /// Specifies that INSERT SQL should be
196 /// generated at runtime and contain only
197 /// the columns whose values are not null.
199 public bool DynamicInsert
201 get { return dynamicInsert; }
202 set { dynamicInsert = value; }
206 /// From NHibernate documentation:
207 /// Specifies a custom <see cref="IEntityPersister"/>.
209 public Type Persister
211 get { return persister; }
212 set { persister = value; }
216 /// From NHibernate documentation:
217 /// Specifies that NHibernate should never perform an SQL UPDATE
218 /// unless it is certain that an object is actually modified. In
219 /// certain cases (actually, only when a transient object has
220 /// been associated with a new session using update()), this means
221 /// that NHibernate will perform an extra SQL SELECT to determine
222 /// if an UPDATE is actually required.
224 public bool SelectBeforeUpdate
226 get { return selectBeforeUpdate; }
227 set { selectBeforeUpdate = value; }
231 /// From NHibernate documentation:
232 /// Determines whether implicit or explicit query polymorphism is used.
234 public Polymorphism Polymorphism
236 get { return polymorphism; }
237 set { polymorphism = value; }
241 /// From NHibernate documentation:
242 /// Specifies that instances of the class are (not) mutable.
246 get { return mutable; }
247 set { mutable = value; }
251 /// From NHibernate documentation:
252 /// Specify a "batch size" for fetching instances of
253 /// this class by identifier.
257 get { return batchSize; }
258 set { batchSize = value; }
262 /// From NHibernate documentation:
263 /// Determines the optimistic locking strategy.
265 public OptimisticLocking Locking
267 get { return locking; }
268 set { locking = value; }
272 /// From NHibernate documentation:
273 /// The auto-import attribute lets us use
274 /// unqualified class names in the query language,
275 /// by default. The assembly and namespace attributes
276 /// specify the assembly where persistent classes
277 /// are located and the namespace they are declared in.
279 public bool UseAutoImport
281 get { return useAutoImport; }
282 set { useAutoImport = value; }