Skip to content

Commit

Permalink
Rename QueryInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jun 16, 2010
1 parent 86f78e2 commit 6a89bf7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
Expand Up @@ -36,5 +36,5 @@ public interface CodeFragmentManager

public List<CodeFragment> getRecentCodeFragments();

public List<CodeFragment> searchCodeFragments(CodeFragment code, int page, QueryInfo info);
public List<CodeFragment> searchCodeFragments(CodeFragment code, int page, Paginator info);
}
Expand Up @@ -28,8 +28,6 @@
import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
Expand Down Expand Up @@ -156,14 +154,7 @@ public List<CodeFragment> getRecentCodeFragments()
return codes;
}

/**
* getting codes from database needs new transaction so that we can further
* modify returned Codes without affecting database (when we call this
* function from another session bean
*/

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public List<CodeFragment> searchCodeFragments(CodeFragment code, int page, QueryInfo info)
public List<CodeFragment> searchCodeFragments(CodeFragment code, int page, Paginator paginator)
{
StringBuilder sb = new StringBuilder();

Expand Down Expand Up @@ -213,9 +204,9 @@ public List<CodeFragment> searchCodeFragments(CodeFragment code, int page, Query
@SuppressWarnings("unchecked")
List<CodeFragment> codes = q.getResultList();

info.setPage(page);
info.setRecordsCount(allRecords);
info.setPagesCount(allRecords / PAGE_SIZE);
paginator.setPage(page);
paginator.setRecordsCount(allRecords);
paginator.setPagesCount(allRecords / PAGE_SIZE);

return codes;
}
Expand Down
Expand Up @@ -50,7 +50,7 @@ public class History implements Serializable
@Inject
private CodeFragmentManager codeFragmentManager;

private QueryInfo info;
private Paginator paginator;

private List<CodeFragment> codes;

Expand Down Expand Up @@ -85,12 +85,12 @@ public String newSearch()
// Do the search, called as a "page action"
public String search()
{
this.info = new QueryInfo();
this.paginator = new Paginator();
this.codes = null;

// Perform a seach

this.codes = codeFragmentManager.searchCodeFragments(this.codeFragmentPrototype, this.page, this.info);
this.codes = codeFragmentManager.searchCodeFragments(this.codeFragmentPrototype, this.page, this.paginator);

for (int i = 0; i != this.codes.size(); i++)
{
Expand All @@ -110,13 +110,13 @@ public void setPage(int page)
this.page = page;
}

public QueryInfo getInfo()
public Paginator getPaginator()
{
return info;
return paginator;
}

public void setInfo(QueryInfo info)
public void setPaginator(Paginator paginator)
{
this.info = info;
this.paginator = paginator;
}
}
Expand Up @@ -24,9 +24,9 @@
import java.util.ArrayList;
import java.util.List;

public class QueryInfo
public class Paginator
{

private int recordsCount = 0;
private int pagesCount = 0;
private int numLinks = 8;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void setPagesCount(int pagesCount)

public void setBoundedIndexes(int startIndex, int endIndex)
{
this.indexes = new ArrayList(endIndex - startIndex);
this.indexes = new ArrayList<Integer>(endIndex - startIndex);
for (int i = startIndex; i <= endIndex; i++)
{
this.indexes.add(new Integer(i));
Expand Down
10 changes: 5 additions & 5 deletions jsf/pastecode/src/main/webapp/pagination.xhtml
Expand Up @@ -6,22 +6,22 @@

<ui:composition>

<h:panelGroup rendered="#{history.info.pagesCount gt 1}">
<h:panelGroup rendered="#{history.paginator.pagesCount gt 1}">
<div id="paging" style="width:99%;text-align:center;">

<a href="history.jsf?page=#{(history.info.page-1)>=0?(history.info.page-1):0}" style="text-decoration:none;">
<a href="history.jsf?page=#{(history.paginator.page-1)>=0?(history.paginator.page-1):0}" style="text-decoration:none;">
<span id="edgelink">&lt;&lt;</span>
</a>
&nbsp;

<ui:repeat var="page" value="#{history.info.indexes}">
<ui:repeat var="page" value="#{history.paginator.indexes}">
<a href="history.jsf?page=#{page}" style="text-decoration:none;">
<span id="normallink" style="width:23px;display: inline-block;}">#{(history.info.page eq page)?'(':''}#{page+1}#{(history.info.page eq page)?')':''}</span>
<span id="normallink" style="width:23px;display: inline-block;}">#{(history.paginator.page eq page)?'(':''}#{page+1}#{(history.paginator.page eq page)?')':''}</span>
</a>
</ui:repeat>

&nbsp;
<a href="history.jsf?page=#{(history.info.page+1)>history.info.pagesCount?history.info.pagesCount:(history.info.page+1)}" style="text-decoration:none;">
<a href="history.jsf?page=#{(history.paginator.page+1)>history.paginator.pagesCount?history.paginator.pagesCount:(history.paginator.page+1)}" style="text-decoration:none;">
<span id="edgelink">&gt;&gt;</span>
</a>

Expand Down

0 comments on commit 6a89bf7

Please sign in to comment.