1 5 package org.h2.value; 6 7 import java.sql.PreparedStatement ; 8 import java.sql.SQLException ; 9 10 13 public class ValueBoolean extends Value { 14 public static final int PRECISION = 1; 15 16 private Boolean value; 17 18 private static final ValueBoolean TRUE = new ValueBoolean(true); 19 private static final ValueBoolean FALSE = new ValueBoolean(false); 20 21 private ValueBoolean(boolean value) { 22 this.value = Boolean.valueOf(""+value); 23 } 24 25 public int getType() { 26 return Value.BOOLEAN; 27 } 28 29 public String getSQL() { 30 return getString(); 31 } 32 33 public String getString() { 34 return value.booleanValue() ? "TRUE" : "FALSE"; 35 } 36 37 public Value negate() throws SQLException { 38 return value.booleanValue() ? FALSE : TRUE; 39 } 40 41 public Boolean getBoolean() { 42 return value; 43 } 44 45 protected int compareSecure(Value o, CompareMode mode) { 46 boolean v2 = ((ValueBoolean) o).value.booleanValue(); 47 boolean v = value.booleanValue(); 48 return (v == v2) ? 0 : (v ? 1 : -1); 49 } 50 51 public long getPrecision() { 52 return PRECISION; 53 } 54 55 public int hashCode() { 56 return value.booleanValue() ? 1 : 0; 57 } 58 59 public Object getObject() { 60 return value; 61 } 62 63 public void set(PreparedStatement prep, int parameterIndex) throws SQLException { 64 prep.setBoolean(parameterIndex, value.booleanValue()); 65 } 66 67 public static ValueBoolean get(boolean b) { 68 return b ? TRUE : FALSE; 69 } 70 71 75 public int getDisplaySize() { 76 return "FALSE".length(); 77 } 78 79 protected boolean isEqual(Value v) { 80 return v instanceof ValueBoolean && value.booleanValue() == ((ValueBoolean)v).value.booleanValue(); 81 } 82 83 } 84 | Popular Tags |