summaryrefslogtreecommitdiff
path: root/src/lq/QuoteUtils.java
diff options
context:
space:
mode:
authorKjetil Ørbekk <orbekk@pvv.ntnu.no>2010-09-03 01:13:15 -0400
committerKjetil Ørbekk <orbekk@pvv.ntnu.no>2010-09-03 01:13:15 -0400
commit1fb83a8c3edefbc2a43d26cc6db835e592d65934 (patch)
tree73047a16e263ae3f84031bc2d82e3961d2140430 /src/lq/QuoteUtils.java
parentb2dd8bf148b70c3076625840f908b5c7d32e9ee1 (diff)
Quote listing
Ported the quotes.jsp page from the old quote system. This commit contains some utility classes related to this. DropData is a temporary hack to remove all data in the datastore. TODO: Remove this when we are finished migrating the application.
Diffstat (limited to 'src/lq/QuoteUtils.java')
-rw-r--r--src/lq/QuoteUtils.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/lq/QuoteUtils.java b/src/lq/QuoteUtils.java
new file mode 100644
index 0000000..f19dbf6
--- /dev/null
+++ b/src/lq/QuoteUtils.java
@@ -0,0 +1,54 @@
+package lq;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Comparator;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+
+public class QuoteUtils {
+ public static List<Quote> getQuotes() {
+ PersistenceManager pm = PMF.get().getPersistenceManager();
+ try {
+ List<Quote> quotes = (List<Quote>) pm.newQuery(Quote.class).execute();
+ pm.retrieveAll(quotes);
+ return quotes;
+ }
+ finally {
+ pm.close();
+ }
+ }
+
+ public static List<Quote> getQuotesOrderedByIdDesc() {
+ List<Quote> quotes = getQuotes();
+ Collections.sort(quotes,
+ new Comparator<Quote>() {
+ public int compare(Quote q1, Quote q2) {
+ return Long.signum(q2.getId() - q1.getId());
+ }
+ });
+ return quotes;
+ }
+
+ public static List<Quote> getQuotesOrderedByScoreDesc() {
+ List<Quote> quotes = getQuotes();
+ Collections.sort(quotes,
+ new Comparator<Quote>() {
+ public int compare(Quote q1, Quote q2) {
+ throw new RuntimeException("Score ordering not yet implemented");
+ }
+ });
+ return quotes;
+ }
+
+ public static List<Quote> getQuotesOrderedByDateDesc() {
+ List<Quote> quotes = getQuotes();
+ Collections.sort(quotes,
+ new Comparator<Quote>() {
+ public int compare(Quote q1, Quote q2) {
+ return q2.getQuoteDate().compareTo(q1.getQuoteDate());
+ }
+ });
+ return quotes;
+ }
+}