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
;
27 private readonly ISessionManager sessionManager
;
29 public BlogDao(ISessionManager sessionManager
)
31 this.sessionManager
= sessionManager
;
34 public Blog
Create(Blog blog
)
36 using(ISession session
= sessionManager
.OpenSession())
38 if (blog
.Posts
== null)
40 blog
.Posts
= new ArrayList();
49 public void Update(Blog blog
)
51 using(ISession session
= sessionManager
.OpenSession())
58 /// Usually will be invoked only by the
61 public void DeleteAll()
63 using(ISession session
= sessionManager
.OpenSession())
65 session
.Delete("from Blog");
71 using(ISession session
= sessionManager
.OpenSession())
73 return session
.Find("from Blog");
77 public Blog
Find(String blogName
)
79 using(ISession session
= sessionManager
.OpenSession())
81 IList list
= session
.Find(
82 "from Blog as a where a.Name=:name", blogName
, NHibernateUtil
.String
);
86 return list
[0] as Blog
;
95 public IList
FindLatest(int howMany
)
97 using(ISession session
= sessionManager
.OpenSession())
99 IList list
= session
.Find("from Blog order by id desc");
101 if (list
.Count
> howMany
)
103 list
= ListUtil
.Limit(howMany
, list
);