001: /*
002: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003: * (http://h2database.com/html/license.html).
004: * Initial Developer: H2 Group
005: */
006: package org.h2.value;
007:
008: import java.io.InputStream;
009: import java.io.Reader;
010: import java.math.BigDecimal;
011: import java.sql.Date;
012: import java.sql.PreparedStatement;
013: import java.sql.SQLException;
014: import java.sql.Time;
015: import java.sql.Timestamp;
016:
017: import org.h2.message.Message;
018:
019: /**
020: * Implementation of NULL. NULL is not a regular data type.
021: */
022: public class ValueNull extends Value {
023:
024: public static final ValueNull INSTANCE = new ValueNull();
025: public static final ValueNull DELETED = new ValueNull();
026:
027: public static final int PRECISION = 1;
028: public static final int DISPLAY_SIZE = 4; // null
029:
030: private ValueNull() {
031: }
032:
033: public String getSQL() {
034: return "NULL";
035: }
036:
037: public int getType() {
038: return Value.NULL;
039: }
040:
041: public String getString() {
042: return null;
043: }
044:
045: public Boolean getBoolean() throws SQLException {
046: return null;
047: }
048:
049: public Date getDate() throws SQLException {
050: return null;
051: }
052:
053: public Time getTime() throws SQLException {
054: return null;
055: }
056:
057: public Timestamp getTimestamp() throws SQLException {
058: return null;
059: }
060:
061: public byte[] getBytes() throws SQLException {
062: return null;
063: }
064:
065: public byte getByte() throws SQLException {
066: return 0;
067: }
068:
069: public short getShort() throws SQLException {
070: return 0;
071: }
072:
073: public BigDecimal getBigDecimal() throws SQLException {
074: return null;
075: }
076:
077: public double getDouble() throws SQLException {
078: return 0.0;
079: }
080:
081: public float getFloat() throws SQLException {
082: return 0.0F;
083: }
084:
085: public int getInt() throws SQLException {
086: return 0;
087: }
088:
089: public long getLong() throws SQLException {
090: return 0;
091: }
092:
093: public InputStream getInputStream() throws SQLException {
094: return null;
095: }
096:
097: public Reader getReader() throws SQLException {
098: return null;
099: }
100:
101: public Value convertTo(int type) throws SQLException {
102: return this ;
103: }
104:
105: protected int compareSecure(Value v, CompareMode mode) {
106: throw Message.getInternalError("compare null");
107: }
108:
109: public long getPrecision() {
110: return PRECISION;
111: }
112:
113: public int hashCode() {
114: return 0;
115: }
116:
117: public Object getObject() {
118: return null;
119: }
120:
121: public void set(PreparedStatement prep, int parameterIndex)
122: throws SQLException {
123: prep.setNull(parameterIndex, DataType
124: .convertTypeToSQLType(Value.NULL));
125: }
126:
127: public int getDisplaySize() {
128: return DISPLAY_SIZE;
129: }
130:
131: public boolean equals(Object other) {
132: return other == this;
133: }
134:
135: }
|