Hi

I'd be willing to take the Comparable part of this patch if it included an addition to our unit-test framework. (hint, hint :-)

Also, see
http://www.h2database.com/html/build.html#providing_patches

Regards, Noel Grandin

On 2012-06-16 15:31, Christopher Deckers wrote:
Hi,

We are using H2 (h2-2012-05-23) and we faced a few issues.

One of them is that I replaced a VARCHAR field with a Java object (OTHER) that contains the string and some additional information. The problem now is that it breaks existing ORDER BY clauses and equality tests with VARCHARs, though it implements the CompareTo method (for objects of same type) and the toString() method.

I think that comparing the serialized bytes is nonsense for the Java object case, and I think that a Java Object's toString and compareTo method should be used when appropriate.

As a temporary(?) solution, I changed the following code:

* In "Value.getHigherOrder(int t1, int t2)", line 325, I added:

if(t1 == Value.STRING && t2 == Value.JAVA_OBJECT || t2 == Value.STRING && t1 == Value.JAVA_OBJECT) {
            return Value.STRING;
        }


* In "ValueJavaObject", I added these:

    @Override
    protected int compareSecure(Value v, CompareMode mode) {
        if(v.getType()  == Value.STRING) {
            Object o = Utils.deserialize(getBytesNoCopy());
            return o.toString().compareTo(v.getString());
        }
        if(v.getType() == Value.JAVA_OBJECT) {
            Object o = Utils.deserialize(getBytesNoCopy());
            if(o instanceof Comparable) {
                Object o2 = Utils.deserialize(v.getBytesNoCopy());
                if(o.getClass() == o2.getClass()) {
                    return ((Comparable)o).compareTo(o2);
                }
            }
        }
        return super.compareSecure(v, mode);
    }

    @Override
    public String getString() {
        return Utils.deserialize(getBytesNoCopy()).toString();
    }


Note: I think JAVA_OBJECT should take low order only for String case which is why I did not try to change "Value.getOrder(int type)".

What do you think of my solution, can there be any problems with what I changed?
Is there something that could be done in H2 itself to solve my issue?

Cheers,
-Christopher

--
You received this message because you are subscribed to the Google Groups "H2 Database" group. To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/hhqWqrVav4cJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.


--
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to