db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel John Debrunner <...@debrunners.com>
Subject Re: Type system notes
Date Sat, 19 Feb 2005 15:21:56 GMT
RPost wrote:

> The SQLInteger.java has a 'plus' method whose signature is:
>    public NumberDataValue plus(NumberDataValue addend1,
>                                                   NumberDataValue addend2,
>                                                   NumberDataValue result)
> All of the parameters and the return value are interfaces.
> Would you shed some light on the actual technical requirements for the
> 'plus' method?
> In other words, can the type of each parameter and result value literally be
> any and all present and future implementations of the NumberDataValue
> interface? That is, is it a derby requirement that the 'plus' method be
> capable of being called with 'addend1', 'addend2' and 'result' parameters
> being three distinct classes? Or is this just a convenience to make the code
> generation more efficient?

I think the current use and requirements are that all the four types are
the same, and typically, if not always the addend1 is the same instance
as the receiver.

The technical requirement could be more flexible, requiring that the
result is suitable to hold the result of operation and that addend1 and
addend2 can be correctly represented by the receiver.

Thus, given the implementations today, this would work

SQLInteger.plus(SQLInteger, SQLShort, SQLLong)

This would give incorrect results

SQLInteger.plus(SQLInteger, SQLLong, SQLInteger)

Inccorrect results would occur because the plus methods 'pull' arguments
from addend1 and addend2 using the getXXX methods, in this case with
addend2 SQLLong.getInt(). This SQLLong.getInt() matches the Java
operation (int) longValue, thus silently truncating the top 32 bits.

I was saying that the methods should be simplified to say the method
executes on the receiver (self), thus plus (I think) should be defined as

// Perform result = this + val
void plus(NumberDataValue val, NumberDataValue result)

and thinking about interfaces, I think it might be possible to define
plus in NumberDataValue as

// set result to this + val
void plus(DataValueDescriptor val, DataValueDescriptor result)

The advantage of going to the primary type interface DVD, is that it
removes the need to add a cast in before calling plus, as type values
are handled generically in most of the code as DataValueDescriptors.


View raw message