Permalink
Browse files

Adding caching and concurrency

  • Loading branch information...
1 parent 58262c8 commit 788a3f8f9b7b55b6113854e8de2c2663b6924742 @ayende committed Apr 1, 2011
@@ -22,6 +22,16 @@ public ActionResult New(string name)
return Json(new { LibraryId = lib.Id }, JsonRequestBehavior.AllowGet);
}
+ public ActionResult Modify(int bookId)
+ {
+ var book = Session.Get<Book>(bookId);
+
+ book.Name = DateTime.Now.ToShortTimeString();
+
+
+ return Json(new { Status = "OK"}, JsonRequestBehavior.AllowGet);
+ }
+
public ActionResult CrateLoad(int size)
{
for (int i = 0; i < size; i++)
@@ -40,11 +50,11 @@ public ActionResult BookIt(int id, string name, string isbn, string grade)
{
Name = name,
Library = Session.Load<Library>(id),
- Attributes =
- {
- ISBN = isbn,
- Grade = grade
- }
+ //Attributes =
+ // {
+ // ISBN = isbn,
+ // Grade = grade
+ // }
};
Session.Save(book);
@@ -226,6 +236,7 @@ public ActionResult Status(int id)
{
var library = Session.Load<Library>(id);
var bookLoans = Session.Query<BookLoan>()
+ .Cacheable()
.Fetch(x => x.Member)
.Fetch(x => x.Book)
.Where(bl => bl.Member.Library.Id == id)
@@ -246,8 +257,6 @@ public ActionResult Status(int id)
Books = library.Books.Select(b => new
{
b.Name,
- b.Attributes.ISBN,
- b.Attributes.Grade,
LoanedTo = bookLoans.Where(x => x.Book == b)
.Select(bl => new
{
@@ -9,7 +9,7 @@ public class Book
public virtual string Name { get; set; }
public virtual Library Library { get; set; }
public virtual ICollection<BookLoan> Loans { get; set; }
-
+ public virtual int Version { get; set; }
private IDictionary attributes = new Hashtable();
public virtual dynamic Attributes
@@ -5,24 +5,26 @@
<class name="Library"
table="Libraries">
-
+ <cache usage="read-write"/>
<id name="Id">
<generator class="hilo"/>
</id>
<property name="Name"/>
<bag name="Members" inverse="true" cascade="all-delete-orphan">
+ <cache usage="read-write"/>
<key column="Library"/>
<one-to-many class="Member"/>
</bag>
<bag name="Books" inverse="true" cascade="all-delete-orphan">
+ <cache usage="read-write"/>
<key column="Library"/>
<one-to-many class="Book"/>
</bag>
</class>
<class name="Member"
table="Members">
-
+ <cache usage="read-write"/>
<id name="Id">
<generator class="identity"/>
</id>
@@ -47,10 +49,13 @@
<class name="Book"
table="Books">
-
+ <cache usage="read-write"/>
<id name="Id">
<generator class="identity"/>
</id>
+ <version name="Version">
+ <column name="Version" default="1"/>
+ </version>
<property name="Name"/>
<many-to-one name="Library"/>
<bag name="Loans" inverse="true" cascade="all-delete-orphan">
@@ -83,9 +88,16 @@
<many-to-one name="Book" />
<many-to-one name="Member"/>
+
+ <filter name="OverdueFilter" condition=":now > DueDate"/>
</class>
<filter-def name="CurrentLibrary" condition="Library = :libraryId">
<filter-param name="libraryId" type="System.Int32"/>
</filter-def>
+
+
+ <filter-def name="OverdueFilter">
+ <filter-param name="now" type="System.DateTime"/>
+ </filter-def>
</hibernate-mapping>

0 comments on commit 788a3f8

Please sign in to comment.