From dc9630c0c61fcb31138afb750050566a181a8e81 Mon Sep 17 00:00:00 2001
From: Christoph Thelen <christoph.thelen@mni.thm.de>
Date: Thu, 9 Apr 2015 10:30:29 +0200
Subject: [PATCH] Add caching for question sorting

---
 .../java/de/thm/arsnova/dao/CouchDBDao.java   |  3 ++
 .../de/thm/arsnova/entities/SortOrder.java    | 50 ++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
index c17dfbee..03504abb 100644
--- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
@@ -2017,6 +2017,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
 		return qids;
 	}
 
+	@Cacheable(value = "sortorder", key = "#p0.concat('-').concat(#p1).concat('-').concat(#p2)")
 	@Override
 	public SortOrder getSortOrder(String sessionId, String questionVariant, String subject) {
 		String viewString = "";
@@ -2057,6 +2058,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
 		return sortOrder;
 	}
 
+	@CachePut(value = "sortorder", key ="#sortOrder.sessionId.concat('-').concat(#sortOrder.questionVariant).concat('-').concat(#sortOrder.subject)")
 	@Override
 	public SortOrder createOrUpdateSortOrder(SortOrder sortOrder) {
 		try {
@@ -2089,6 +2091,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
 		return null;
 	}
 
+	@CacheEvict(value = "sortorder", key ="#sortOrder.sessionId.concat('-').concat(#sortOrder.questionVariant).concat('-').concat(#sortOrder.subject)")
 	@Override
 	public void deleteSortOrder(SortOrder sortOrder) {
 		try {
diff --git a/src/main/java/de/thm/arsnova/entities/SortOrder.java b/src/main/java/de/thm/arsnova/entities/SortOrder.java
index 468023f5..f31950da 100644
--- a/src/main/java/de/thm/arsnova/entities/SortOrder.java
+++ b/src/main/java/de/thm/arsnova/entities/SortOrder.java
@@ -84,5 +84,53 @@ public class SortOrder {
 
 	public String get_rev() {
 		return _rev;
-	} 
+	}
+
+	@Override
+	public int hashCode() {
+		// auto-generated!
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((questionVariant == null) ? 0 : questionVariant.hashCode());
+		result = prime * result + ((sessionId == null) ? 0 : sessionId.hashCode());
+		result = prime * result + ((subject == null) ? 0 : subject.hashCode());
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		// auto-generated!
+		if (this == obj) {
+			return true;
+		}
+		if (obj == null) {
+			return false;
+		}
+		if (getClass() != obj.getClass()) {
+			return false;
+		}
+		SortOrder other = (SortOrder) obj;
+		if (questionVariant == null) {
+			if (other.questionVariant != null) {
+				return false;
+			}
+		} else if (!questionVariant.equals(other.questionVariant)) {
+			return false;
+		}
+		if (sessionId == null) {
+			if (other.sessionId != null) {
+				return false;
+			}
+		} else if (!sessionId.equals(other.sessionId)) {
+			return false;
+		}
+		if (subject == null) {
+			if (other.subject != null) {
+				return false;
+			}
+		} else if (!subject.equals(other.subject)) {
+			return false;
+		}
+		return true;
+	}
 }
-- 
GitLab