From bd7cf278a1ece4169d4ce4c784fa33ea9c931635 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Fri, 3 Sep 2010 17:18:25 -0400 Subject: Rename QuoteUtils to QuoteUtil for consistency. --- src/lq/QuoteUtil.java | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lq/QuoteUtils.java | 106 ------------------------------------------------- 2 files changed, 106 insertions(+), 106 deletions(-) create mode 100644 src/lq/QuoteUtil.java delete mode 100644 src/lq/QuoteUtils.java (limited to 'src') diff --git a/src/lq/QuoteUtil.java b/src/lq/QuoteUtil.java new file mode 100644 index 0000000..5104cb0 --- /dev/null +++ b/src/lq/QuoteUtil.java @@ -0,0 +1,106 @@ +package lq; + +import java.util.Collections; +import java.util.List; +import java.util.Comparator; +import javax.jdo.PersistenceManager; +import javax.jdo.Query; + +public class QuoteUtil { + public static List getQuotes() { + PersistenceManager pm = PMF.get().getPersistenceManager(); + try { + Query quoteQuery = pm.newQuery(Quote.class); + quoteQuery.setFilter("approved == true"); + List quotes = (List) quoteQuery.execute(); + pm.retrieveAll(quotes); + return quotes; + } + finally { + pm.close(); + } + } + + public static List getQuotesPendingApproval() { + PersistenceManager pm = PMF.get().getPersistenceManager(); + try { + Query quoteQuery = pm.newQuery(Quote.class); + quoteQuery.setFilter("approved == null"); + List quotes = (List) quoteQuery.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; + } + + public static void approveQuote(Long id) { + PersistenceManager pm = PMF.get().getPersistenceManager(); + try { + Query quoteQuery = pm.newQuery(Quote.class); + quoteQuery.setFilter("id == idParam"); + quoteQuery.declareParameters("Long idParam"); + List quotes = (List) quoteQuery.execute(id); + + for (Quote quote : quotes) { + quote.setApproved(true); + pm.makePersistent(quote); + } + } + finally { + pm.close(); + } + } + + public static void rejectQuote(Long id) { + PersistenceManager pm = PMF.get().getPersistenceManager(); + try { + Query quoteQuery = pm.newQuery(Quote.class); + quoteQuery.setFilter("id == idParam"); + quoteQuery.declareParameters("Long idParam"); + List quotes = (List) quoteQuery.execute(id); + + for (Quote quote : quotes) { + quote.setApproved(false); + pm.makePersistent(quote); + } + } + finally { + pm.close(); + } + } +} diff --git a/src/lq/QuoteUtils.java b/src/lq/QuoteUtils.java deleted file mode 100644 index ab5cdd1..0000000 --- a/src/lq/QuoteUtils.java +++ /dev/null @@ -1,106 +0,0 @@ -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 { - Query quoteQuery = pm.newQuery(Quote.class); - quoteQuery.setFilter("approved == true"); - List quotes = (List) quoteQuery.execute(); - pm.retrieveAll(quotes); - return quotes; - } - finally { - pm.close(); - } - } - - public static List getQuotesPendingApproval() { - PersistenceManager pm = PMF.get().getPersistenceManager(); - try { - Query quoteQuery = pm.newQuery(Quote.class); - quoteQuery.setFilter("approved == null"); - List quotes = (List) quoteQuery.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; - } - - public static void approveQuote(Long id) { - PersistenceManager pm = PMF.get().getPersistenceManager(); - try { - Query quoteQuery = pm.newQuery(Quote.class); - quoteQuery.setFilter("id == idParam"); - quoteQuery.declareParameters("Long idParam"); - List quotes = (List) quoteQuery.execute(id); - - for (Quote quote : quotes) { - quote.setApproved(true); - pm.makePersistent(quote); - } - } - finally { - pm.close(); - } - } - - public static void rejectQuote(Long id) { - PersistenceManager pm = PMF.get().getPersistenceManager(); - try { - Query quoteQuery = pm.newQuery(Quote.class); - quoteQuery.setFilter("id == idParam"); - quoteQuery.declareParameters("Long idParam"); - List quotes = (List) quoteQuery.execute(id); - - for (Quote quote : quotes) { - quote.setApproved(false); - pm.makePersistent(quote); - } - } - finally { - pm.close(); - } - } -} -- cgit v1.2.3