Fixing an issue with output parameters that are of type IntPtr
[castle.git] / ActiveRecord / Castle.ActiveRecord.Tests / Model / CompositeModel / Agent.cs
blobcb986fadf7bed13940288e4106b9a920f6e3dd30
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;
20 using NHibernate;
22 using Castle.ActiveRecord.Framework;
25 [ActiveRecord("Agents")]
26 public class Agent : ActiveRecordBase
28 private AgentKey _userKey;
29 private Org _org;
30 private IList _groups;
31 private int _version;
33 public Agent()
35 _groups = new ArrayList();
36 _version = -1;
39 public Agent(AgentKey key) : this()
41 _userKey = key;
44 [CompositeKey]
45 public AgentKey Key
47 get { return _userKey; }
48 set { _userKey = value; }
51 public String OrgId
53 get { return _userKey.OrgId; }
56 public String Name
58 get { return _userKey.Name; }
61 [Version(UnsavedValue="negative")]
62 public int Version
64 get{ return _version; }
65 set{ _version = value; }
68 [BelongsTo("OrgId", Insert=false, Update=false)]
69 public Org Org
71 get { return _org; }
72 set { _org = value; }
75 [HasAndBelongsToMany(typeof (Group),
76 Table = "GroupAgents",
77 ColumnRef = "GroupId",
78 CompositeKeyColumnKeys = new String[]{"OrgId","Name"},
79 Lazy = true,
80 Cascade = ManyRelationCascadeEnum.SaveUpdate)]
81 public IList Groups
83 get { return _groups; }
84 set { _groups = value; }
87 public static void DeleteAll()
89 ActiveRecordBase.DeleteAll( typeof(Agent) );
92 public static Agent[] FindAll()
94 return (Agent[]) ActiveRecordBase.FindAll( typeof(Agent) );
97 public static Agent Find(object key)
99 return (Agent) ActiveRecordBase.FindByPrimaryKey( typeof(Agent), key );
102 /// <summary>
103 /// We make it visible only to for test cases' assertions
104 /// </summary>
105 public static ISessionFactoryHolder Holder
107 get { return ActiveRecordMediator.GetSessionFactoryHolder(); }
110 public void CustomAction()
112 Execute(new NHibernateDelegate(MyCustomMethod));
115 private object MyCustomMethod(ISession session, object userInstance)
117 session.Delete(userInstance);
118 session.Flush();
120 return null;