ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Butler <jeffgbut...@gmail.com>
Subject Re: Trim on left side in where clause expressions
Date Mon, 23 Feb 2009 21:54:59 GMT
This is possible in a couple of ways - you could do it with a plugin,
or by extending the generated example classes.

With a plugin, the basic idea is to add methods to the example's inner
Criteria class to deal with the RTRIM function (and LTRIM too???).  I
was going to explain how, but an example is better.  See here:

http://svn.apache.org/repos/asf/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/plugins/CaseInsensitiveLikePlugin.java

This plugin adds case insensitive LIKE expressions to the generated
example class.  You could use it as a model for developing your own
plugin.

The Ibator documentation includes a page on extending the example
classes that shows how to accomplish this by extension.

If you have a lot of CHAR fields that you want to use, then the plugin
would be better.

Hope that helps -
Jeff Butler


On Mon, Feb 23, 2009 at 4:43 AM, Anders Andersen <anders.andersen@cph.dk> wrote:
> Hi,
>
> We are trying to use iBATIS/Ibator on a database that is traditionally updated via optimistic
locking.
> Doing so we have come across a problem with our where clauses and the code that is generated
> by Ibator, because most fields in our database are of type CHAR. In Ibator there is a
supported
> property called "trimStrings" on the <javaModelGenerator> element, however this
only trim strings
> on the right side of the where clause expressions (e.g. WHERE MYFIELD = rtrim('     Hello
 ')) and
> we need the left side to be trimmed as well. We can of cause changed the Ibator generated
code
> but that would be a manually process that would be overwritten next time we run Ibator.
>
> We have tried to look at the possibilities for extending Ibator via Plug-In's or the
like, but have not
> found a good point of entry for this yet. However we have localized the place in the
Ibator code
> that we could change to solve this - it is ExampleGenerator.java:
>
> -- snip --
> private Method getSingleValueMethod(IntrospectedColumn introspectedColumn,
>  String nameFragment, String operator) {
>
>       ...
>
>
>        sb.append(introspectedColumn.getAliasedActualColumnName());
>
>        sb.append(' ');
>
>        sb.append(operator);
>
>        sb.append("\", "); //$NON-NLS-1$
>
>
>
>        ...
>    }
> -- snip --
>
> should be changed to
>
> -- snip --
> private Method getSingleValueMethod(IntrospectedColumn introspectedColumn,
>  String nameFragment, String operator) {
>       ...
>
>        sb.append("rtrim(" + introspectedColumn.getAliasedActualColumnName()+ ")");
>        sb.append(' ');
>        sb.append(operator);
>        sb.append("\", "); //$NON-NLS-1$
>
>        ...
>    }
> -- snip --
>
> Is this possible through a plug-in or otherwise?
>
> Any information that can help us solve this will be highly appreciated!
>
>
> Venlig hilsen / Kind regards
>
> Anders Andersen
>
> IT Consultant - IT afdelingen / IT department
> Copenhagen Airports A/S
> Lufthavnsboulevarden 6, DK-2770 Kastrup
> Tel./Phone no.: +45 60660306
> e-mail: anders.andersen@cph.dk
>

Mime
View raw message