private void loadItems(boolean initScrollbar)
{
// DBReader
BeanListTableInfo lti = (BeanListTableInfo) getTableInfo();
DBReader r = new DBReader();
try
{ // Check command
DBCommand queryCmd = lti.getQueryCmd();
if (queryCmd == null)
throw new ObjectNotValidException(this);
boolean loadPageFromPosition = lti.isValid() && lti.isAllowPagination();
lti.setValid(false);
if (lti.isSortOrderChanged())
{ // Set Sort order
setOrderBy(queryCmd);
lti.setSortOrderChanged(false);
}
// DBReader.open immer nur innerhalb eines try {} finally {} blocks!
r.open(queryCmd, getConnection(queryCmd));
// get position from the session
int position = 0;
int maxItems = 1000;
if (loadPageFromPosition)
{
position = lti.getPosition();
if (position < 0)
{ // position < 0 is not possible, set to 0
position = 0;
}
if (position > lti.getItemCount() - lti.getPageSize())
{ // position > count of entries is not possible, set to max
position = lti.getItemCount() - lti.getPageSize();
}
if (position > 0)
{ // we are not at position 0, "skipping" entries
r.skipRows(position);
}
else
position = 0;
// maxItems
maxItems = lti.getPageSize();
}
// Read all Items
items = r.getBeanList(beanClass, maxItems);
if (items == null)
throw new UnexpectedReturnValueException(items, "DBReader.getBeanList");
generateIdParams(rowset, items);
assignSelectionMap(items);
// set position at session object
if (loadPageFromPosition)
{ // set valid
if (position + items.size() > lti.getItemCount())
{ // Oops: More items than expected.
log.warn("Item count of {} has changed. Adjusting item count.", getPropertyName());
lti.init(position + items.size(), lti.getPageSize());
}
lti.setPosition(position);
lti.setModified(false);
lti.setValid(true);
}
else
{ // Init the list
lti.init(items.size(), 0);
}
}
catch (RuntimeException e)
{
log.error("Error loading bean list " + e.getMessage(), e);
throw e;
}
finally
{
r.close();
// Pagination
if (lti.isAllowPagination())
{ // Scrollbar
if (initScrollbar)
initScrollbar();