PortletPreferences prefs = request.getPreferences();
windowSize = Integer.parseInt(prefs.getValue(WINDOW_SIZE, "10"));
StatusMessage message = (StatusMessage)PortletMessaging.consume(request, "DatabaseBrowserPortlet", "action");
if (message != null)
{
this.getContext(request).put("statusMsg", message);
}
try
{
if (iterator == null)
{
String sql = getQueryString(request, context);
// System.out.println("buildNormalContext SQL: "+sql);
readUserParameters(request, context);
getRows(request, sql, windowSize);
iterator = getBrowserIterator(request);
start = 0;
}
else
{
if (sortColName != null)
{
iterator.sort(sortColName);
}
}
resultSetSize = iterator.getResultSetSize();
if (start >= resultSetSize)
{
if ((start - windowSize) > 0)
start = resultSetSize - windowSize;
else
start = 0;
}
next = start + windowSize;
prev = start - windowSize;
if (prev < 0 && start > 0)
prev = 0;
iterator.setTop(start);
readLinkParameters(request, context);
if (iterator != null)
{
resultSetSize = iterator.getResultSetSize();
if (next <= resultSetSize)
{
context.put(NEXT, String.valueOf(next));
}
if (prev <= resultSetSize && prev >= 0)
{
context.put(PREVIOUS, String.valueOf(prev));
}
context.put(BROWSER_ITERATOR, iterator);
context.put(BROWSER_TITLE_ITERATOR, iterator
.getResultSetTitleList());
context.put(BROWSER_TABLE_SIZE, new Integer(resultSetSize));
context.put(WINDOW_SIZE, new Integer(windowSize));
context.put(START, new Integer(start));
/*
* System.out.println("buildNormalContext Sort column name=
* "+sortColName); System.out.println("buildNormalContext
* Iterator: "+iterator); System.out.println("buildNormalContext
* Titles= "+iterator.getResultSetTitleList());
* System.out.println("buildNormalContext
* windowSize="+windowSize+" prev="+prev+ " next="+next+"
* start="+start+" resultSetSize="+resultSetSize);
*/
}
} catch (Exception e)
{
String msg = e.toString();
Throwable cause = e.getCause();
if (cause != null)
{
msg = msg + ", " + cause.getMessage();
}
context.put("statusMsg", new StatusMessage(msg, StatusMessage.ERROR));
// log the error msg
log.error("Exception", e);
/*
* TODO: error logging