* @return The SQL WHERE clause
*/
private static String createSqlWhere(ModelRequest request, ListingDescriptor listing) throws PersistenceException
{
PersistentDescriptor persistents = listing.getPersistents();
PersistentMetaData idPersistentMeta = persistents.getMetaData(listing.getIdPersistent());
StringBuffer condition = new StringBuffer();
if (! StringTools.isTrimEmpty(listing.getCondition()))
{
condition.append(" WHERE " + listing.getCondition());
}
if (listing.getSortColumns().size() > 0)
{
condition.append(" ORDER BY ");
}
for (Iterator i = listing.sortColumnIterator(); i.hasNext();)
{
ColumnDescriptor column = (ColumnDescriptor) i.next();
condition.append(column.getName() + (column.getSort() == SortOrder.DESCENDING ? " DESC" : " ASC"));
if (i.hasNext())
{
condition.append(", ");
}
}
StringBuffer sqlCondition = new StringBuffer();
for (StringTokenizer st = new StringTokenizer(condition.toString()); st.hasMoreTokens();)
{
String token = st.nextToken();
int dotIndex = token.indexOf('.');
if (dotIndex != - 1)
{
String persistent = token.substring(0, dotIndex);
String field = token.substring(dotIndex + 1);
PersistentMetaData meta = persistents.getMetaData(persistent);
if (meta != null)
{
sqlCondition.append(" " + persistent + "." + meta.getDBFieldName(field) + " ");
}
}
else if (token.startsWith("#") || (token.startsWith("'#") && token.endsWith("'")))
{
String paramName = null;