hi alexey,

why don't you use

crit.addLike("upper(name)","ALEX%");

jakob

Alexey Kamenchuk wrote:

Hi,

Is there the good way to customize generated SQL statements?
The solution I found requires adding my custom classes into the
org.apache.ojb.broker.accesslayer.sql package what I particularly dislike.

I need to make query with case-insensitive LIKE-clause, that's something
like this:
SELECT ... WHERE UPPER(name) LIKE UPPER('alex%')

Here is my solution:

I created subclass of SqlSelectStatement and overrode appendCriteria:

protected void appendCriteria(TableAlias alias, PathInfo pathInfo,
SelectionCriteria c, StringBuffer buf)
{
if (c instanceof LikeCriteria)
appendLikeCriteria(alias, pathInfo,(LikeCriteria) c, buf);
else super.appendCriteria(alias, pathInfo, c, buf);
}


and added new method

private void appendLikeCriteria(TableAlias alias, PathInfo pathInfo,
LikeCriteria c, StringBuffer buf)
{
        buf.append(" UPPER(");
        appendColName(alias, pathInfo, c.isTranslateAttribute(), buf);
        buf.append(") ");
        buf.append(c.getClause());
        buf.append(" UPPER(?) ");
}

These two methods reference to TableAlias class, which is declared as
package-private in org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.
That's why I have to place my class into the same package.

This subclass is instantiated in overridden
SqlGeneratorDefaultImpl#getPreparedSelectStatement

Implementing it similarly to the parent I need access to SqlCacheKey class,
which is also not public; hence, the ancestor of SqlGeneratorDefaultImpl is
placed to org.apache.ojb.broker.accesslayer.sql package too.

Best regards,
Alexey.






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to