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
17 using System
.Collections
;
19 using Castle
.Applications
.MindDump
.Model
;
20 using Castle
.Facilities
.NHibernateIntegration
;
26 private readonly ISessionManager sessionManager
;
28 public PostDao(ISessionManager sessionManager
)
30 this.sessionManager
= sessionManager
;
33 public Post
Create(Post post
)
35 using(ISession session
= sessionManager
.OpenSession())
43 public void Update(Post post
)
45 using(ISession session
= sessionManager
.OpenSession())
52 /// Usually will be invoked only be the
55 public void DeleteAll()
57 using(ISession session
= sessionManager
.OpenSession())
59 session
.Delete("from Post");
65 using(ISession session
= sessionManager
.OpenSession())
67 return session
.Find("from Post order by id desc");
71 public IList
Find(Blog blog
)
73 using(ISession session
= sessionManager
.OpenSession())
75 IList list
= session
.Find(
76 "from Post as a where a.Blog.Id=:name", blog
.Id
, NHibernateUtil
.Int64
);
82 public Post
Find(long id
)
84 using(ISession session
= sessionManager
.OpenSession())
86 IList list
= session
.Find(
87 "from Post as a where a.id=:name order by id desc", id
, NHibernateUtil
.Int64
);
91 return list
[0] as Post
;
100 public IList
FindLatest(int howMany
)
102 using(ISession session
= sessionManager
.OpenSession())
104 IList list
= session
.Find("from Post order by id desc");
106 if (list
.Count
> howMany
)
108 list
= ListUtil
.Limit(howMany
, list
);