Re: The problem to compile Java stored function in Oracle
On May 31, 3:56 pm, Lew <no...@lewscanon.com> wrote:
On 05/31/2010 04:29 AM, Boris Poliakovsky wrote:
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations
internally
* to work around bugs in some JS interpreters.
*/
private static int safe_add(byte x, byte y)
The Java coding conventions have no underscores in method names, and the =
use
of mixed "camel" case in identifiers, thus, "safeAdd()".
This method adds 'byte's, not 'int' values as implied by the incorrect co=
mment.
{
int rc0 = -1;
try
{
int lsw;
int msw;
lsw = (x& 0xFFFF) + (y& 0xFFFF);
msw = (x>> 16) + (y>> 16) + (lsw>> 16);
rc0 = (msw<< 16) | (lsw& 0xFFFF);
}
catch (Exception e)
{
e.printStackTrace();
rc0 = -1;
}
finally
{
return rc0;
}
}
}
What the hell is this routine? This method is a WTF top to bottom.
Why does a Java method give a rat's ass about bugs in JS interpreters?
The (non-Javadoc!) comment blathers about 'int' addition wrapping at 32 b=
its.
Guess what! That's what 'int' addition does in Java anyway!
Not that that matters, because the arguments are 'byte's, not 'int's.
The result of a (non-existent) exception is to silently compute '-1'?!
Catch 'Exception'? That's an antipattern and in this case a clear subs=
titute
for thought.
Where the hell is that stack trace supposed to show? And what, you nev=
er
heard of an error message or log?
And the method's 'private', yet never used.
I mentioned the shocking lack of indentation in my other post on this que=
stion.
Really, WTF?
--
Lew- Hide quoted text -
- Show quoted text -
Dear Lew,
I have never been working with Java and JavaScript before (I am PL/SQL
developer), but right now I have to translate one JavaScript as Java
Storted Function into Oracle. For begining I took three functions from
this script and translated as I understood.
Could you please explain me haw I can do it properly ?
The source JavaScript functions are following:
- first /*
* Convert a string to an array of little-endian words
* If chrsz is ASCII, characters >255 have their hi-byte silently
ignored.
*/
function str2binl(str)
{
var bin = Array()
var mask = (1 << chrsz) - 1
for(var i = 0; i < str.length * chrsz; i += chrsz)
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32)
return bin
}
- second
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations
internally
* to work around bugs in some JS interpreters.
*/
function safe_add(x, y)
{
var lsw = (x & 0xFFFF) + (y & 0xFFFF)
var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
return (msw << 16) | (lsw & 0xFFFF)
}
Third:
/*
* Bitwise rotate a 32-bit number to the left.
*/
function rol(num, cnt)
{
return (num << cnt) | (num >>> (32 - cnt))
}
With the best regards,
Boris