From 1fb83a8c3edefbc2a43d26cc6db835e592d65934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Fri, 3 Sep 2010 01:13:15 -0400 Subject: 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. --- src/lq/QuoteUtils.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/lq/QuoteUtils.java (limited to 'src/lq/QuoteUtils.java') 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 getQuotes() { + PersistenceManager pm = PMF.get().getPersistenceManager(); + try { + List quotes = (List) pm.newQuery(Quote.class).execute(); + pm.retrieveAll(quotes); + return quotes; + } + finally { + pm.close(); + } + } + + public static List getQuotesOrderedByIdDesc() { + List quotes = getQuotes(); + Collections.sort(quotes, + new Comparator() { + public int compare(Quote q1, Quote q2) { + return Long.signum(q2.getId() - q1.getId()); + } + }); + return quotes; + } + + public static List getQuotesOrderedByScoreDesc() { + List quotes = getQuotes(); + Collections.sort(quotes, + new Comparator() { + public int compare(Quote q1, Quote q2) { + throw new RuntimeException("Score ordering not yet implemented"); + } + }); + return quotes; + } + + public static List getQuotesOrderedByDateDesc() { + List quotes = getQuotes(); + Collections.sort(quotes, + new Comparator() { + public int compare(Quote q1, Quote q2) { + return q2.getQuoteDate().compareTo(q1.getQuoteDate()); + } + }); + return quotes; + } +} -- cgit v1.2.3