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
.Applications
.MindDump
.Dao
18 using System
.Collections
;
20 using Castle
.Applications
.MindDump
.Model
;
21 using Castle
.Facilities
.NHibernateIntegration
;
25 public class AuthorDao
27 private readonly ISessionManager sessionManager
;
29 public AuthorDao(ISessionManager sessionManager
)
31 this.sessionManager
= sessionManager
;
34 public Author
Create(Author author
)
36 using(ISession session
= sessionManager
.OpenSession())
38 if (author
.Blogs
== null)
40 author
.Blogs
= new ArrayList();
49 public void Update(Author author
)
51 using(ISession session
= sessionManager
.OpenSession())
53 session
.Update(author
);
58 /// Usually will be invoked only by the
61 public void DeleteAll()
63 using(ISession session
= sessionManager
.OpenSession())
65 session
.Delete("from Author");
71 using(ISession session
= sessionManager
.OpenSession())
73 return session
.Find("from Author");
77 public Author
Find(String login
)
79 using(ISession session
= sessionManager
.OpenSession())
81 IList list
= session
.Find(
82 "from Author as a where a.Login=:name", login
, NHibernateUtil
.String
);
86 Author author
= list
[0] as Author
;
88 if (author
.Blogs
.Count
== 1)
90 // We just reference the blog
92 Blog blog
= author
.Blogs
[0] as Blog
;