Fixing an issue with output parameters that are of type IntPtr
[castle.git] / ActiveRecord / Castle.ActiveRecord.Tests / Model / CompositeModel / Group.cs
blobe9c777cb5a81675f466655a69686b0845e1189bf
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.Tests.Model.CompositeModel
17 using System;
18 using System.Collections;
19 using Castle.ActiveRecord.Framework;
20 using NHibernate;
22 [ActiveRecord("Groups")]
23 public class Group : ActiveRecordBase
25 private int _id;
26 private String _name;
27 private IList _agents;
28 private IList _groups;
29 private bool onSaveCalled, onUpdateCalled, onDeleteCalled, onLoadCalled;
31 public Group()
33 _agents = new ArrayList();
34 _groups = new ArrayList();
37 [PrimaryKey(PrimaryKeyType.Native)]
38 public int Id
40 get { return _id; }
41 set { _id = value; }
44 [Property]
45 public String Name
47 get { return _name; }
48 set { _name = value; }
51 [HasAndBelongsToMany(typeof(Agent), Table = "GroupAgents", CompositeKeyColumnRefs = new String[] {"OrgId", "Name"},
52 ColumnKey = "GroupId", Lazy = true, Inverse=true, Cascade = ManyRelationCascadeEnum.SaveUpdate)]
53 public IList Agents
55 get { return _agents; }
56 set { _agents = value; }
59 [HasAndBelongsToMany(typeof(Group), Table = "GroupOrgs", ColumnRef = "GroupId", ColumnKey = "OrgId", Lazy = true,
60 Inverse=true, Cascade = ManyRelationCascadeEnum.SaveUpdate)]
61 public IList Groups
63 get { return _groups; }
64 set { _groups = value; }
67 public static void DeleteAll()
69 ActiveRecordMediator.DeleteAll(typeof(Group));
72 public static void DeleteAll(string where)
74 ActiveRecordMediator.DeleteAll(typeof(Group), where);
77 public static Group[] FindAll()
79 return (Group[]) ActiveRecordMediator.FindAll(typeof(Group));
82 public static Group Find(int id)
84 return (Group) ActiveRecordMediator.FindByPrimaryKey(typeof(Group), id);
87 public static int FetchCount()
89 return Count(typeof(Group));
92 public static int FetchCount(string filter, params object[] args)
94 return Count(typeof(Group), filter, args);
97 public static bool Exists()
99 return Exists(typeof(Group));
102 public static bool Exists(string filter, params object[] args)
104 return Exists(typeof(Group), filter, args);
107 /// <summary>
108 /// Lifecycle method invoked during Save of the entity
109 /// </summary>
110 protected override void OnSave()
112 onSaveCalled = true;
115 /// <summary>
116 /// Lifecycle method invoked during Update of the entity
117 /// </summary>
118 protected override void OnUpdate()
120 onUpdateCalled = true;
123 /// <summary>
124 /// Lifecycle method invoked during Delete of the entity
125 /// </summary>
126 protected override void OnDelete()
128 onDeleteCalled = true;
131 /// <summary>
132 /// Lifecycle method invoked during Load of the entity
133 /// </summary>
134 protected override void OnLoad(object id)
136 onLoadCalled = true;
139 public bool OnSaveCalled
141 get { return onSaveCalled; }
144 public bool OnUpdateCalled
146 get { return onUpdateCalled; }
149 public bool OnDeleteCalled
151 get { return onDeleteCalled; }
154 public bool OnLoadCalled
156 get { return onLoadCalled; }
159 public ISession CurrentSession
161 get { return (ISession) ActiveRecordMediator.Execute(typeof(Group), new NHibernateDelegate(GrabSession), this); }
164 private object GrabSession(ISession session, object instance)
166 return session;
169 public void CustomAction()
171 ActiveRecordMediator.Execute(typeof(Group), new NHibernateDelegate(MyCustomMethod), this);
174 private object MyCustomMethod(ISession session, object blogInstance)
176 session.Delete(blogInstance);
177 session.Flush();
179 return null;
182 internal static ISessionFactoryHolder Holder
184 get { return ActiveRecordMediator.GetSessionFactoryHolder(); }