📄 datatype.java
字号:
/* Derby - Class org.apache.derby.iapi.types.DataType Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.iapi.types;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.BooleanDataValue;import org.apache.derby.iapi.types.CloneableObject;import org.apache.derby.iapi.types.Orderable;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.services.i18n.MessageService;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.i18n.LocaleFinder;import java.io.InputStream;import java.sql.Date;import java.sql.Time;import java.sql.Timestamp;import java.sql.PreparedStatement;import java.sql.SQLException;import java.sql.ResultSet;import java.util.Calendar;/** * * DataType is the superclass for all data types. * It provides common behavior * for datavalue descriptors -- it throws * exceptions for all of the get* and setvalue(*) methods of * DataValueDescriptor; the subtypes need only * override the one for the type they represent * and all types it can also be returned as, * and the methods dealing with nulls. * * Since all types satisfy getString * DataType does not define that * interfaces of DataValueDescriptor. * * DataType is a little glue for columns to hold * values with. * */public abstract class DataType implements DataValueDescriptor, CloneableObject{ /* * DataValueDescriptor Interface */ /** * Gets the value in the data value descriptor as a boolean. * Throws an exception if the data value is not receivable as a boolean. * * @return The data value as a boolean. * * @exception StandardException Thrown on error */ public boolean getBoolean() throws StandardException { throw dataTypeConversion("boolean"); } /** * Gets the value in the data value descriptor as a byte. * Throws an exception if the data value is not receivable as a byte. * * @return The data value as a byte. * * @exception StandardException Thrown on error */ public byte getByte() throws StandardException { throw dataTypeConversion("byte"); } /** * Gets the value in the data value descriptor as a short. * Throws an exception if the data value is not receivable as a short. * * @return The data value as a short. * * @exception StandardException Thrown on error */ public short getShort() throws StandardException { throw dataTypeConversion("short"); } /** * Gets the value in the data value descriptor as a int. * Throws an exception if the data value is not receivable as a int. * * @return The data value as a int. * * @exception StandardException Thrown on error */ public int getInt() throws StandardException { throw dataTypeConversion("int"); } /** * Gets the value in the data value descriptor as a long. * Throws an exception if the data value is not receivable as a long. * * @return The data value as a long. * * @exception StandardException Thrown on error */ public long getLong() throws StandardException { throw dataTypeConversion("long"); } /** * Gets the value in the data value descriptor as a float. * Throws an exception if the data value is not receivable as a float. * * @return The data value as a float. * * @exception StandardException Thrown on error */ public float getFloat() throws StandardException { throw dataTypeConversion("float"); } /** * Gets the value in the data value descriptor as a double. * Throws an exception if the data value is not receivable as a double. * * @return The data value as a double. * * @exception StandardException Thrown on error */ public double getDouble() throws StandardException { throw dataTypeConversion("double"); } public int typeToBigDecimal() throws StandardException { throw dataTypeConversion("java.math.BigDecimal"); } /** * Gets the value in the data value descriptor as a byte[]. * Throws an exception if the data value is not receivable as a Binary or Varbinary. * * @return The Binary value as a byte[]. * * @exception StandardException Thrown on error */ public byte[] getBytes() throws StandardException { throw dataTypeConversion("byte[]"); } /** * Gets the value in the data value descriptor as a java.sql.Date. * Throws an exception if the data value is not receivable as a Date. * @param cal calendar for object creation * @return The data value as a java.sql.Date. * * @exception StandardException Thrown on error */ public Date getDate( Calendar cal) throws StandardException { throw dataTypeConversion("java.sql.Date"); } /** * Gets the value in the data value descriptor as a java.sql.Time. * Throws an exception if the data value is not receivable as a Time. * @param cal calendar for object creation * @return The data value as a java.sql.Time. * * @exception StandardException Thrown on error */ public Time getTime( Calendar cal) throws StandardException { throw dataTypeConversion("java.sql.Time"); } /** * Gets the value in the data value descriptor as a java.sql.Timestamp. * Throws an exception if the data value is not receivable as a Timestamp. * @param cal calendar for object creation * @return The data value as a java.sql.Timestamp. * * @exception StandardException Thrown on error */ public Timestamp getTimestamp( Calendar cal) throws StandardException { throw dataTypeConversion("java.sql.Timestamp"); } /** * Gets the value in the data stream descriptor as an InputStream. * Throws an exception if the data value is not receivable as a stream. * * @return The data value as an InputStream. * * @exception StandardException Thrown on error */ public InputStream getStream() throws StandardException { throw dataTypeConversion( MessageService.getTextMessage(SQLState.LANG_STREAM)); } /* * Column interface */ /** * The is null operator as called from the language module, as opposed to * the storage module. * * * @return A SQL boolean value telling whether the operand is null * */ public final BooleanDataValue isNullOp() { return SQLBoolean.truthValue(isNull()); } /** * The is not null operator as called from the language module, as opposed to * the storage module. * * * @return A SQL boolean value telling whether the operand is not null * */ public final BooleanDataValue isNotNull() { return SQLBoolean.truthValue(!isNull()); } /** * Set the value of this DataValueDescriptor. * At DataType level just throws an error lower classes will override * * @param theValue The Time value to set this DataValueDescriptor to * * @return This DataValueDescriptor * */ public void setValue(Time theValue) throws StandardException { setValue( theValue, (Calendar) null); } /** * Set the value of this DataValueDescriptor. * At DataType level just throws an error lower classes will override * * @param theValue The Time value to set this DataValueDescriptor to * @param cal The time zone from the calendar is used to construct the database time value * * @return This DataValueDescriptor * */ public void setValue(Time theValue, Calendar cal) throws StandardException { throwLangSetMismatch("java.sql.Time"); } /** * Set the value of this DataValueDescriptor. * At DataType level just throws an error lower classes will override * * @param theValue The Timestamp value to set this DataValueDescriptor to * * @return This DataValueDescriptor * */ public void setValue(Timestamp theValue) throws StandardException { setValue( theValue, (Calendar) null); } /** * Set the value of this DataValueDescriptor. * At DataType level just throws an error lower classes will override * * @param theValue The Timestamp value to set this DataValueDescriptor to * @param cal The time zone from the calendar is used to construct the database timestamp value * * @return This DataValueDescriptor * */ public void setValue(Timestamp theValue, Calendar cal) throws StandardException { throwLangSetMismatch("java.sql.Timestamp"); } /** * Set the value of this DataValueDescriptor. * At DataType level just throws an error lower classes will override * * @param theValue The Date value to set this DataValueDescriptor to * * @return This DataValueDescriptor * */ public void setValue(Date theValue) throws StandardException { setValue( theValue, (Calendar) null); } /** * Set the value of this DataValueDescriptor. * At DataType level just throws an error lower classes will override * * @param theValue The Date value to set this DataValueDescriptor to * @param cal The time zone from the calendar is used to construct the database date value * * @return This DataValueDescriptor * */ public void setValue(Date theValue, Calendar cal) throws StandardException { throwLangSetMismatch("java.sql.Date"); } /** * Set the value of this DataValueDescriptor. * At DataType level just throws an error lower classes will override * * @param theValue The BigDecimal value to set this DataValueDescriptor to * * @return This DataValueDescriptor * */ public void setValue(String theValue) throws StandardException { throwLangSetMismatch("java.lang.String"); } /** * Set the value of this DataValueDescriptor to the given int value * At DataType level just throws an error lower classes will override * * @param theValue The value to set this DataValueDescriptor to * * @return This DataValueDescriptor * * @exception StandardException Thrown on error */ public void setValue(int theValue) throws StandardException { throwLangSetMismatch("int"); } /** * Set the value of this DataValueDescriptor to the given double value * At DataType level just throws an error lower classes will override * * @param theValue The value to set this DataValueDescriptor to * * @return This DataValueDescriptor * * @exception StandardException Thrown on error */ public void setValue(double theValue) throws StandardException { throwLangSetMismatch("double"); } /** * Set the value of this DataValueDescriptor to the given float value * At DataType level just throws an error lower classes will override * * @param theValue The value to set this DataValueDescriptor to * * @return This DataValueDescriptor * * @exception StandardException Thrown on error */ public void setValue(float theValue) throws StandardException { throwLangSetMismatch("float"); } /** * Set the value of this DataValueDescriptor to the given short value * At DataType level just throws an error lower classes will override * * @param theValue The value to set this DataValueDescriptor to * * @return This DataValueDescriptor * * @exception StandardException Thrown on error */ public void setValue(short theValue) throws StandardException { throwLangSetMismatch("short"); } /** * Set the value of this DataValueDescriptor to the given long value * At DataType level just throws an error lower classes will override * * @param theValue The value to set this DataValueDescriptor to * * @return This DataValueDescriptor * * @exception StandardException Thrown on error */ public void setValue(long theValue) throws StandardException { throwLangSetMismatch("long"); } /** * Set the value of this DataValueDescriptor to the given byte value * At DataType level just throws an error lower classes will override * * @param theValue The value to set this DataValueDescriptor to * * @return This DataValueDescriptor * * @exception StandardException Thrown on error */ public void setValue(byte theValue) throws StandardException { throwLangSetMismatch("byte"); } /** * Set the value. * At DataType level just throws an error lower classes will override * * @param theValue Contains the boolean value to set this to * * @return This value * */ public void setValue(boolean theValue) throws StandardException { throwLangSetMismatch("boolean"); } /** * Set the value of this DataValueDescriptor. * At DataType level just throws an error lower classes will override * * @param theValue The byte value to set this DataValueDescriptor to * * @return This DataValueDescriptor * */ public void setValue(byte[] theValue) throws StandardException { throwLangSetMismatch("byte[]"); } /** Only to be called when the application sets a value using BigDecimal */ public void setBigDecimal(Number bigDecimal) throws StandardException { throwLangSetMismatch("java.math.BigDecimal"); } public final void setValue(DataValueDescriptor dvd) throws StandardException { if (dvd.isNull()) { setToNull(); return; } try { setFrom(dvd); } catch (StandardException se) { String msgId = se.getMessageId(); if (SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE.equals(msgId)) throw outOfRange(); if (SQLState.LANG_FORMAT_EXCEPTION.equals(msgId)) throw invalidFormat(); throw se; } } protected void setFrom(DataValueDescriptor dvd) throws StandardException { throw StandardException.newException(SQLState.NOT_IMPLEMENTED); } /** * @see DataValueDescriptor#setToNull */ public void setToNull() { restoreToNull();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -