openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@bea.com>
Subject RE: Trimming Strings from Database Query Results
Date Mon, 30 Oct 2006 19:34:24 GMT
> I am finding that all strings had trailing blanks trimmed 
> when retrieved in
> toplink, whereas the trailing blanks are preserved in 
> openJpa.  I can add
> the many trim methods needed to my code if necessary, but I 
> was wondering if
> there is any way to do this via a property setting.  I could 
> not find any.

Hi,

The untrimmed fields are String fields, not char fields, correct?

There aren't any property settings to tell OpenJPA to trim String
fields, but I believe that you could implement something that did this
quite easily by extending the DB2Dictionary and overriding the
getString() method to do something like so:

package com.example;

import java.sql.ResultSet;

public class TrimmingDB2Dictionary 
    extends org.apache.openjpa.jdbc.sql.DB2Dictionary {

    @Override
    public String getString(ResultSet rs, int col) {
        String str = super.getString(rs, col);
        if (str != null)
            str = str.trim();
        return str;
    }
}

Then, you'll change your DBDictionary property like so:

    <property name="openjpa.jdbc.DBDictionary"
value="com.example.TrimmingDB2Dictionary(StoreCharsAsNumbers=false)"/>


-Patrick
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

Mime
View raw message