Re: svn commit: r921455 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r921455 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java

Adam Heath-2
[hidden email] wrote:
> Author: adrianc
> Date: Wed Mar 10 17:11:18 2010
> New Revision: 921455
>
> URL: http://svn.apache.org/viewvc?rev=921455&view=rev
> Log:
> Revert rev 902341 - which seemed to cause problems with the Derby database.

To be fair, this is not a problem with the derby database, not at all.
 It's a problem with the code.
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r921455 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java

Adrian Crum
Adam Heath wrote:

> [hidden email] wrote:
>> Author: adrianc
>> Date: Wed Mar 10 17:11:18 2010
>> New Revision: 921455
>>
>> URL: http://svn.apache.org/viewvc?rev=921455&view=rev
>> Log:
>> Revert rev 902341 - which seemed to cause problems with the Derby database.
>
> To be fair, this is not a problem with the derby database, not at all.
>  It's a problem with the code.

Right. I assumed the number of chars returned would be the same as the
number of chars requested. I'll get back to it when I have time.
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r921455 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java

Adam Heath-2
Adrian Crum wrote:

> Adam Heath wrote:
>> [hidden email] wrote:
>>> Author: adrianc
>>> Date: Wed Mar 10 17:11:18 2010
>>> New Revision: 921455
>>>
>>> URL: http://svn.apache.org/viewvc?rev=921455&view=rev
>>> Log:
>>> Revert rev 902341 - which seemed to cause problems with the Derby
>>> database.
>>
>> To be fair, this is not a problem with the derby database, not at all.
>>  It's a problem with the code.
>
> Right. I assumed the number of chars returned would be the same as the
> number of chars requested. I'll get back to it when I have time.

What were you trying to accomplish?
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r921455 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java

Adrian Crum
Adam Heath wrote:

> Adrian Crum wrote:
>> Adam Heath wrote:
>>> [hidden email] wrote:
>>>> Author: adrianc
>>>> Date: Wed Mar 10 17:11:18 2010
>>>> New Revision: 921455
>>>>
>>>> URL: http://svn.apache.org/viewvc?rev=921455&view=rev
>>>> Log:
>>>> Revert rev 902341 - which seemed to cause problems with the Derby
>>>> database.
>>> To be fair, this is not a problem with the derby database, not at all.
>>>  It's a problem with the code.
>> Right. I assumed the number of chars returned would be the same as the
>> number of chars requested. I'll get back to it when I have time.
>
> What were you trying to accomplish?

Eliminate the arbitrary buffer size. If the entire object can be read in
one pass, then do so.

We can tell from the bug reports that Derby will read a CLOB in 8k
chunks. Other databases apparently support reading data in chunks larger
than 8k.

Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r921455 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java

Adam Heath-2
Adrian Crum wrote:

> Adam Heath wrote:
>> Adrian Crum wrote:
>>> Adam Heath wrote:
>>>> [hidden email] wrote:
>>>>> Author: adrianc
>>>>> Date: Wed Mar 10 17:11:18 2010
>>>>> New Revision: 921455
>>>>>
>>>>> URL: http://svn.apache.org/viewvc?rev=921455&view=rev
>>>>> Log:
>>>>> Revert rev 902341 - which seemed to cause problems with the Derby
>>>>> database.
>>>> To be fair, this is not a problem with the derby database, not at all.
>>>>  It's a problem with the code.
>>> Right. I assumed the number of chars returned would be the same as the
>>> number of chars requested. I'll get back to it when I have time.
>>
>> What were you trying to accomplish?
>
> Eliminate the arbitrary buffer size. If the entire object can be read in
> one pass, then do so.
>
> We can tell from the bug reports that Derby will read a CLOB in 8k
> chunks. Other databases apparently support reading data in chunks larger
> than 8k.
>

int sizeToRead = db.getLength(id);
char[] buffer = new char[sizeToRead];
int r;
while (sizeToRead > 0 && (r = db.read(id, buffer, offset, sizeToRead))
!= -1) {
        if (r == sizeToRead) {
                return buffer; // convert to whatever
        } else {
                collector.append(buffer, offset, r);
                offset += r;
                sizeToRead -= r;
        }
}
if (r == -1) {
        throw new Exception("short read");
}
return collector; // convert to whatever