1 15 package org.apache.tapestry.vlib.pages; 16 17 import java.rmi.RemoteException ; 18 19 import org.apache.tapestry.IRequestCycle; 20 import org.apache.tapestry.html.BasePage; 21 import org.apache.tapestry.vlib.IMessageProperty; 22 import org.apache.tapestry.vlib.VirtualLibraryEngine; 23 import org.apache.tapestry.vlib.components.Browser; 24 import org.apache.tapestry.vlib.ejb.IBookQuery; 25 import org.apache.tapestry.vlib.ejb.MasterQueryParameters; 26 import org.apache.tapestry.vlib.ejb.SortColumn; 27 import org.apache.tapestry.vlib.ejb.SortOrdering; 28 29 35 36 public abstract class BookMatches extends BasePage 37 { 38 private Browser _browser; 39 40 public void finishLoad() 41 { 42 _browser = (Browser) getComponent("browser"); 43 } 44 45 public abstract IBookQuery getBookQuery(); 46 47 public abstract void setBookQuery(IBookQuery bookQuery); 48 49 public abstract SortColumn getSortColumn(); 50 51 public abstract boolean isDescending(); 52 53 public abstract MasterQueryParameters getQueryParameters(); 54 55 public abstract void setQueryParameters(MasterQueryParameters queryParameters); 56 57 61 62 public void performQuery(MasterQueryParameters parameters, IRequestCycle cycle) 63 { 64 setQueryParameters(parameters); 65 66 int count = executeQuery(); 67 68 if (count == 0) 69 { 70 IMessageProperty page = (IMessageProperty) cycle.getPage(); 71 page.setMessage(getMessage("no-matches")); 72 return; 73 } 74 75 _browser.initializeForResultCount(count); 76 cycle.activate(this); 77 } 78 79 public void requery(IRequestCycle cycle) 80 { 81 int count = executeQuery(); 82 83 if (count != _browser.getResultCount()) 84 _browser.initializeForResultCount(count); 85 } 86 87 private int executeQuery() 88 { 89 VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine(); 90 91 MasterQueryParameters parameters = getQueryParameters(); 92 93 SortOrdering ordering = new SortOrdering(getSortColumn(), isDescending()); 94 95 int i = 0; 96 while (true) 97 { 98 try 99 { 100 IBookQuery query = getBookQuery(); 101 102 if (query == null) 103 { 104 query = vengine.createNewQuery(); 105 setBookQuery(query); 106 } 107 108 return query.masterQuery(parameters, ordering); 109 } 110 catch (RemoteException ex) 111 { 112 vengine.rmiFailure("Remote exception processing query.", ex, i++); 113 114 setBookQuery(null); 115 } 116 117 } 118 } 119 120 } | Popular Tags |