Skip to content

Commit

Permalink
Temporary workarround while waiting for the fix h2database#3016
Browse files Browse the repository at this point in the history
  • Loading branch information
ebocher committed Sep 2, 2021
1 parent 12e9ebc commit 2d876cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 43 deletions.
4 changes: 2 additions & 2 deletions h2/src/main/org/h2/value/ValueBytesBase.java
Expand Up @@ -30,11 +30,11 @@ abstract class ValueBytesBase extends Value {
int hash;

ValueBytesBase(byte[] value) {
int length = value.length;
/*int length = value.length;
if (length > Constants.MAX_STRING_LENGTH) {
throw DbException.getValueTooLongException(getTypeName(getValueType()),
StringUtils.convertBytesToHex(value, 41), length);
}
}*/
this.value = value;
}

Expand Down
47 changes: 6 additions & 41 deletions h2/src/main/org/h2/value/ValueGeometry.java
Expand Up @@ -5,15 +5,12 @@
*/
package org.h2.value;

import java.util.Arrays;
import static org.h2.util.geometry.EWKBUtils.EWKB_SRID;

import org.h2.api.ErrorCode;
import org.h2.engine.CastDataProvider;
import org.h2.message.DbException;
import org.h2.util.Bits;
import org.h2.util.StringUtils;
import org.h2.util.Utils;
import org.h2.util.geometry.EWKBUtils;
import org.h2.util.geometry.EWKTUtils;
import org.h2.util.geometry.GeometryUtils;
Expand All @@ -30,17 +27,7 @@
* @author Noel Grandin
* @author Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
*/
public final class ValueGeometry extends Value {

/**
* The value.
*/
byte[] value;

/**
* The hash code.
*/
int hash;
public final class ValueGeometry extends ValueBytesBase {

private static final double[] UNKNOWN_ENVELOPE = new double[0];

Expand Down Expand Up @@ -73,6 +60,7 @@ public final class ValueGeometry extends Value {
* @param envelope the envelope
*/
private ValueGeometry(byte[] bytes, double[] envelope) {
super(bytes);
if (bytes.length < 9 || bytes[0] != 0) {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, StringUtils.convertBytesToHex(bytes));
}
Expand All @@ -86,7 +74,8 @@ private ValueGeometry(byte[] bytes, double[] envelope) {
/**
* Get or create a geometry value for the given geometry.
*
* @param o the geometry object (of type org.locationtech.jts.geom.Geometry)
* @param o the geometry object (of type
* org.locationtech.jts.geom.Geometry)
* @return the value
*/
public static ValueGeometry getFromGeometry(Object o) {
Expand Down Expand Up @@ -119,8 +108,7 @@ public static ValueGeometry get(String s) {
}

/**
* Get or create a geometry value for the given internal EWKB
* representation.
* Get or create a geometry value for the given internal EWKB representation.
*
* @param bytes the WKB representation of the geometry. May not be modified.
* @return the value
Expand Down Expand Up @@ -264,7 +252,7 @@ public StringBuilder getSQL(StringBuilder builder, int sqlFlags) {
EWKBUtils.parseEWKB(value, new EWKTTarget(builder.append('\''), getDimensionSystem()));
builder.append('\'');
} else {
return StringUtils.convertBytesToHex(builder.append("X'"), value).append('\'');
super.getSQL(builder, DEFAULT_SQL_FLAGS);
}
return builder;
}
Expand All @@ -279,27 +267,4 @@ public int getMemory() {
return value.length * 20 + 24;
}

@Override
public final int hashCode() {
int h = hash;
if (h == 0) {
h = getClass().hashCode() ^ Utils.getByteArrayHash(value);
if (h == 0) {
h = 1_234_570_417;
}
hash = h;
}
return h;
}

@Override
public final boolean equals(Object other) {
return other != null && getClass() == other.getClass() && Arrays.equals(value, ((ValueBytesBase) other).value);
}

@Override
public int compareTypeSafe(Value v, CompareMode mode, CastDataProvider provider) {
return Bits.compareNotNullUnsigned(value, ((ValueBytesBase) v).value);
}

}

0 comments on commit 2d876cc

Please sign in to comment.