Author: pete.muir(a)jboss.org
Date: 2010-06-16 16:05:50 -0400 (Wed, 16 Jun 2010)
New Revision: 6462
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java
Log:
get the history working again
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java 2010-06-16
19:33:43 UTC (rev 6461)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java 2010-06-16
20:05:50 UTC (rev 6462)
@@ -83,7 +83,6 @@
this.note = "";
this.text = "";
this.user = "";
- this.language = Language.TEXT;
}
public int getId()
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java 2010-06-16
19:33:43 UTC (rev 6461)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java 2010-06-16
20:05:50 UTC (rev 6462)
@@ -145,7 +145,7 @@
@Produces @Named
public List<CodeFragment> getRecentCodeFragments()
{
- Query query = entityManager.createQuery("SELECT c FROM CodeFragment c WHERE
hash=null ORDER BY datetime DESC ");
+ Query query = entityManager.createQuery("SELECT c FROM CodeFragment c WHERE
c.hash=null ORDER BY datetime DESC ");
query.setMaxResults(MAX_RECENT_FRAGMENTS);
@SuppressWarnings("unchecked")
@@ -156,28 +156,23 @@
public List<CodeFragment> searchCodeFragments(CodeFragment code, int page,
Paginator paginator)
{
- StringBuilder sb = new StringBuilder();
-
- String delim = "";
+ StringBuilder sb = new StringBuilder().append("SELECT c FROM CodeFragment c
WHERE c.hash=null");
+
if (!code.getUser().trim().equals(""))
{
- sb.append("c.user = \'" + code.getUser().trim().toLowerCase() +
"\'");
- delim = " AND";
+ sb.append(" AND c.user =
\'").append(code.getUser().trim().toLowerCase()).append("\'");
}
if (code.getLanguage() != null)
{
- sb.append(delim).append(" c.language = \'" +
code.getLanguage().name() + "\'");
- delim = " AND";
+ sb.append(" AND c.language =
\'").append(code.getLanguage().name()).append(("\'"));
}
if (!code.getNote().trim().equals(""))
{
- sb.append(delim).append(" c.note LIKE \'%" +
code.getNote().trim().toLowerCase() + "%\'");
- delim = " AND";
+ sb.append(" AND c.note LIKE
\'%").append(code.getNote().trim().toLowerCase()).append("%\'");
}
if (!code.getText().trim().equals(""))
{
- sb.append(delim).append(" c.text LIKE \'%" +
code.getText().toLowerCase() + "%\'");
- delim = " AND";
+ sb.append(" AND c.text LIKE
\'%").append(code.getText().toLowerCase()).append("%\'");
}
if (code.getDatetime() != null)
{
@@ -189,15 +184,13 @@
String formattedDate1 = formatter.format(code.getDatetime());
String formattedDate2 = formatter.format(date2);
- sb.append(delim).append(" c.datetime between \'" + formattedDate1
+ "\' and \'" + formattedDate2 + "\'");
- delim = " AND";
+ sb.append(" AND c.datetime between
\'").append(formattedDate1).append("\' and
\'").append(formattedDate2).append("\'");
}
-
- if (sb.toString().length() == 0)
- sb.append("1 = \'1\'");
-
- Query q = entityManager.createQuery("SELECT c FROM CodeFragment c WHERE
hash=null AND " + sb.toString() + " ORDER BY datetime DESC");
- int allRecords = q.getResultList().size();
+ sb.append(" ORDER BY datetime DESC");
+ String queryString = sb.toString();
+
+ Query q = entityManager.createQuery(queryString);
+
q.setFirstResult(page * PAGE_SIZE);
q.setMaxResults(PAGE_SIZE);
@@ -205,8 +198,8 @@
List<CodeFragment> codes = q.getResultList();
paginator.setPage(page);
- paginator.setRecordsCount(allRecords);
- paginator.setPagesCount(allRecords / PAGE_SIZE);
+ paginator.setRecordsCount(codes.size());
+ paginator.setPagesCount(codes.size() / PAGE_SIZE);
return codes;
}