1 5 package org.h2.value; 6 7 import java.sql.PreparedStatement ; 8 import java.sql.SQLException ; 9 10 import org.h2.util.ByteUtils; 11 12 abstract class ValueBytesBase extends Value { 13 14 private byte[] value; 15 private int hash; 16 17 protected ValueBytesBase(byte[] v) { 18 this.value = v; 19 } 20 21 public String getSQL() { 22 return "X'" + getString() + "'"; 23 } 24 25 public byte[] getBytesNoCopy() { 26 return value; 27 } 28 29 public byte[] getBytes() { 30 return ByteUtils.cloneByteArray(value); 31 } 32 33 protected int compareSecure(Value v, CompareMode mode) { 34 byte[] v2 = ((ValueBytesBase) v).value; 35 return ByteUtils.compareNotNull(value, v2); 36 } 37 38 public String getString() { 39 return ByteUtils.convertBytesToString(value); 40 } 41 42 public long getPrecision() { 43 return value.length; 44 } 45 46 public int hashCode() { 47 if (hash == 0) { 48 hash = ByteUtils.getByteArrayHash(value); 49 } 50 return hash; 51 } 52 53 public Object getObject() { 54 return getBytes(); 55 } 56 57 public void set(PreparedStatement prep, int parameterIndex) throws SQLException { 58 prep.setBytes(parameterIndex, value); 59 } 60 61 public int getDisplaySize() { 62 return value.length * 2; 63 } 64 65 protected boolean isEqual(Value v) { 66 return v instanceof ValueBytesBase && ByteUtils.compareNotNull(value, ((ValueBytesBase)v).value) == 0; 67 } 68 69 73 } 74 | Popular Tags |