DataType.java

Index Score
org.apache.derby.iapi.types
Apache Derby

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
DOC_COMMENTNumber of javadoc comment lines
COMMENTSComment lines
DECL_COMMENTSComments in declarations
RETURNSNumber of return points from functions
INTERFACE_COMPLEXITYInterface complexity
LINESNumber of lines in the source file
SIZESize of the file in bytes
FUNCTIONSNumber of function declarations
PARAMSNumber of formal parameter declarations
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
CYCLOMATICCyclomatic complexity
EXEC_COMMENTSComments in executable code
JAVA0034JAVA0034 Missing braces in if statement
LOCLines of code
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0106JAVA0106 Unnecessary import from current package
BLOCKSNumber of blocks
JAVA0285JAVA0285 Dereference of potentially null variable
ELOCEffective lines of code
JAVA0145JAVA0145 Tab character used in source file
JAVA0173JAVA0173 Unused method parameter
PROGRAM_VOCABHalstead program vocabulary
UNIQUE_OPERANDSNumber of unique operands
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
UNIQUE_OPERATORSNumber of unique operators
EXITSProcedure exits
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
WHITESPACENumber of whitespace lines
COMPARISONSNumber of comparison operators
LOGICAL_LINESNumber of statements
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
BLOCK_COMMENTNumber of block comment lines
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0117JAVA0117 Missing javadoc: method 'method'
LINE_COMMENTNumber of line comments
/* Derby - Class org.apache.derby.iapi.types.DataType Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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.lang.Comparable; 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, Comparable { /* * 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)); } /** * Gets the value in the data stream descriptor as a trace string. * This default implementation simply forwards the call to * <code>getString</code>. * * @return The data value in a representation suitable for tracing. * @throws StandardException if getting the data value fails. * @see DataValueDescriptor#getString */ public String getTraceString() throws StandardException { return getString(); } /** * Recycle this DataType object. * * @return this object with value set to null */ public DataValueDescriptor recycle() { restoreToNull(); return this; } /* * 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 * * @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 * * @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 * * @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 * * @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 * * @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 * * @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 * */ 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 * */ 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; } } /** * Set the value of this DataValueDescriptor based on the value * of the specified DataValueDescriptor. * * @param dvd The DataValueDescriptor that holds the value to * which we want to set this DataValueDescriptor's value. * */ protected void setFrom(DataValueDescriptor dvd) throws StandardException { throw StandardException.newException(SQLState.NOT_IMPLEMENTED); } /** * @see DataValueDescriptor#setToNull */ public void setToNull() { restoreToNull(); } /** * @see DataValueDescriptor#setObjectForCast * * @exception StandardException * thrown on failure * */ public void setObjectForCast(Object theValue, boolean instanceOfResultType, String resultTypeClassName) throws StandardException { if (theValue == null) { setToNull(); return; } /* * Is the object of the right type? (only do the check if value is * non-null */ if (!instanceOfResultType) { throw StandardException.newException( SQLState.LANG_DATA_TYPE_SET_MISMATCH, theValue.getClass().getName(), getTypeName(resultTypeClassName)); } setObject(theValue); } /** * Set the value from an non-null object. Usually overridden. * This implementation throws an exception. * The object will have been correctly typed from the call to setObjectForCast. */ void setObject(Object theValue) throws StandardException { genericSetObject(theValue); } /** * Get the type name of this value, possibly overriding * with the passed in class name (for user/java types). * @param className */ String getTypeName(String className) { return getTypeName(); } /** * 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 Object getObject() throws StandardException { throw dataTypeConversion("java.lang.Object"); } void genericSetObject(Object theValue) throws StandardException { throwLangSetMismatch(theValue); } /** * From CloneableObject * * @return clone of me as an Object */ public Object cloneObject() { return getClone(); } // International support /** * International version of getString(). Overridden for date, time, * and timestamp in SQLDate, SQLTime, SQLTimestamp. * * @exception StandardException Thrown on error */ protected String getNationalString(LocaleFinder localeFinder) throws StandardException { return getString(); } public void throwLangSetMismatch(Object value) throws StandardException { throwLangSetMismatch(value.getClass().getName()); } void throwLangSetMismatch(String argTypeName) throws StandardException { throw StandardException.newException(SQLState.LANG_DATA_TYPE_SET_MISMATCH, argTypeName, this.getTypeName()); } public void setInto(PreparedStatement ps, int position) throws SQLException, StandardException { ps.setObject(position, getObject()); } /** Set this value into a ResultSet for a subsequent ResultSet.insertRow or ResultSet.updateRow. This method will only be called for non-null values. @exception SQLException thrown by the ResultSet object @exception StandardException thrown by me accessing my value. */ public void setInto(ResultSet rs, int position) throws SQLException, StandardException { rs.updateObject(position, getObject()); } /** * Default normalization method. No information needed from DataTypeDescriptor. * * @param desiredType The type to normalize the source column to * @param source The value to normalize * * * @exception StandardException Thrown normalization error. */ public void normalize( DataTypeDescriptor desiredType, DataValueDescriptor source) throws StandardException { ((DataValueDescriptor) this).setValue(source); } /** * Each built-in type in JSQL has a precedence. This precedence determines * how to do type promotion when using binary operators. For example, float * has a higher precedence than int, so when adding an int to a float, the * result type is float. * * The precedence for some types is arbitrary. For example, it doesn't * matter what the precedence of the boolean type is, since it can't be * mixed with other types. But the precedence for the number types is * critical. The SQL standard requires that exact numeric types be * promoted to approximate numeric when one operator uses both. Also, * the precedence is arranged so that one will not lose precision when * promoting a type. * * @return The precedence of this type. */ public int typePrecedence() { return -1; } /** * The = operator as called from the language module, as opposed to * the storage module. This default implementations uses compare(). * * @param left The value on the left side of the = * @param right The value on the right side of the = * * @return A SQL boolean value telling whether the two parameters are equal * * @exception StandardException Thrown on error */ public BooleanDataValue equals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException { return SQLBoolean.truthValue(left, right, left.compare(right) == 0); } /** * The <> operator as called from the language module, as opposed to * the storage module. This default implementations uses compare(). * * @param left The value on the left side of the <> * @param right The value on the right side of the <> * * @return A SQL boolean value telling whether the two parameters * are not equal * * @exception StandardException Thrown on error */ public BooleanDataValue notEquals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException { return SQLBoolean.truthValue(left, right, left.compare(right) != 0); } /** * The < operator as called from the language module, as opposed to * the storage module. * * @param left The value on the left side of the < * @param right The value on the right side of the < * * @return A SQL boolean value telling whether the first operand is less * than the second operand * * @exception StandardException Thrown on error */ public BooleanDataValue lessThan(DataValueDescriptor left, DataValueDescriptor right) throws StandardException { return SQLBoolean.truthValue(left, right, left.compare(right) < 0); } /** * The > operator as called from the language module, as opposed to * the storage module. This default implementations uses compare(). * * @param left The value on the left side of the > * @param right The value on the right side of the > * * @return A SQL boolean value telling whether the first operand is greater * than the second operand * * @exception StandardException Thrown on error */ public BooleanDataValue greaterThan(DataValueDescriptor left, DataValueDescriptor right) throws StandardException { return SQLBoolean.truthValue(left, right, left.compare(right) > 0); } /** * The <= operator as called from the language module, as opposed to * the storage module. This default implementations uses compare(). * * @param left The value on the left side of the <= * @param right The value on the right side of the <= * * @return A SQL boolean value telling whether the first operand is less * than or equal to the second operand * * @exception StandardException Thrown on error */ public BooleanDataValue lessOrEquals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException { return SQLBoolean.truthValue(left, right, left.compare(right) <= 0); } /** * The >= operator as called from the language module, as opposed to * the storage module. This default implementation uses compare(). * * @param left The value on the left side of the >= * @param right The value on the right side of the >= * * @return A SQL boolean value telling whether the first operand is greater * than or equal to the second operand * * @exception StandardException Thrown on error */ public BooleanDataValue greaterOrEquals(DataValueDescriptor left, DataValueDescriptor right) throws StandardException { return SQLBoolean.truthValue(left, right, left.compare(right) >= 0); } public boolean compare(int op, DataValueDescriptor other, boolean orderedNulls, boolean unknownRV) throws StandardException { /* Use compare method from dominant type, flipping the operator * to reflect flipping of sides. */ if (typePrecedence() < other.typePrecedence()) { return other.compare(flip(op), this, orderedNulls, unknownRV); } int result = compare(other); switch(op) { case ORDER_OP_LESSTHAN: return (result < 0); // this < other case ORDER_OP_EQUALS: return (result == 0); // this == other case ORDER_OP_LESSOREQUALS: return (result <= 0); // this <= other // flipped operators case ORDER_OP_GREATERTHAN: return (result > 0); // this > other case ORDER_OP_GREATEROREQUALS: return (result >= 0); // this >= other default: if (SanityManager.DEBUG) SanityManager.THROWASSERT("Invalid Operator"); return false; } } /** * Compare this Orderable with another, with configurable null ordering. * The caller gets to determine how nulls * should be treated - they can either be ordered values or unknown * values. The caller also gets to decide, if they are ordered, * whether they should be lower than non-NULL values, or higher * * @param op Orderable.ORDER_OP_EQUALS means do an = comparison. * Orderable.ORDER_OP_LESSTHAN means compare this < other. * Orderable.ORDER_OP_LESSOREQUALS means compare this <= other. * @param other The DataValueDescriptor to compare this one to. * @param orderedNulls True means to treat nulls as ordered values, * that is, treat SQL null as equal to null, and either greater or less * than all other values. * False means to treat nulls as unknown values, * that is, the result of any comparison with a null * is the UNKNOWN truth value. * @param nullsOrderedLow True means NULL less than non-NULL, * false means NULL greater than non-NULL. * Only relevant if orderedNulls is true. * @param unknownRV The return value to use if the result of the * comparison is the UNKNOWN truth value. In other * words, if orderedNulls is false, and a null is * involved in the comparison, return unknownRV. * This parameter is not used orderedNulls is true. * * @return true if the comparison is true (duh!) * * @exception StandardException Thrown on error */ public boolean compare(int op, DataValueDescriptor other, boolean orderedNulls, boolean nullsOrderedLow, boolean unknownRV) throws StandardException { /* Use compare method from dominant type, flipping the operator * to reflect flipping of sides. */ if (typePrecedence() < other.typePrecedence()) { return other.compare(flip(op), this, orderedNulls, nullsOrderedLow, unknownRV); } int result = compare(other, nullsOrderedLow); switch(op) { case ORDER_OP_LESSTHAN: return (result < 0); // this < other case ORDER_OP_EQUALS: return (result == 0); // this == other case ORDER_OP_LESSOREQUALS: return (result <= 0); // this <= other // flipped operators case ORDER_OP_GREATERTHAN: return (result > 0); // this > other case ORDER_OP_GREATEROREQUALS: return (result >= 0); // this >= other default: if (SanityManager.DEBUG) SanityManager.THROWASSERT("Invalid Operator"); return false; } } /** * Compare this Orderable with another, with configurable null ordering. * This method treats nulls as ordered values, but allows the caller * to specify whether they should be lower than all non-NULL values, * or higher than all non-NULL values. * * @param other The Orderable to compare this one to. % @param nullsOrderedLow True if null should be lower than non-NULL * * @return <0 - this Orderable is less than other. * 0 - this Orderable equals other. * >0 - this Orderable is greater than other. * * The code should not explicitly look for -1, or 1. * * @exception StandardException Thrown on error */ public int compare(DataValueDescriptor other, boolean nullsOrderedLow) throws StandardException { if (this.isNull() || other.isNull()) { if (!isNull()) return nullsOrderedLow ? 1 : -1; if (!other.isNull()) return nullsOrderedLow ? -1 : 1; return 0; // both null } return compare(other); } /** * Wrapper method for the "compare(DataValueDescriptor)" method of * this class. Allows sorting of an array of DataValueDescriptors * using the JVMs own sorting algorithm. Currently used for * execution-time sorting of IN-list values to allow proper handling * (i.e. elimination) of duplicates. * * @see java.lang.Comparable#compareTo */ public int compareTo(Object otherDVD) { DataValueDescriptor other = (DataValueDescriptor)otherDVD; try { // Use compare method from the dominant type. if (typePrecedence() < other.typePrecedence()) return (-1 * other.compare(this)); return compare(other); } catch (StandardException se) { if (SanityManager.DEBUG) { SanityManager.THROWASSERT("Encountered error while " + "trying to compare two DataValueDescriptors: " + se.getMessage()); } /* In case of an error in insane mode, just treat the * values as "equal". */ return 0; } } /** * Flip the operator used in a comparison (< -> >). * This is useful when flipping a comparison due to * type precedence. * * @param operator The operator to flip. * * @return The flipped operator. */ protected static int flip(int operator) { switch (operator) { case Orderable.ORDER_OP_LESSTHAN: // < -> > return Orderable.ORDER_OP_GREATERTHAN; case Orderable.ORDER_OP_LESSOREQUALS: // <= -> >= return Orderable.ORDER_OP_GREATEROREQUALS; case Orderable.ORDER_OP_EQUALS: // = -> = return Orderable.ORDER_OP_EQUALS; default: // These operators only appear due to flipping. // They should never be flipped themselves. if (SanityManager.DEBUG) { SanityManager.THROWASSERT( "Attempting to flip an operator that is not " + "expected to be flipped."); } return operator; } } /* * DataValueDescriptor interface */ /** * @see DataValueDescriptor#coalesce * @exception StandardException Thrown on error */ public DataValueDescriptor coalesce(DataValueDescriptor[] argumentsList, DataValueDescriptor returnValue) throws StandardException { // arguments list should have at least 2 arguments if (SanityManager.DEBUG) { SanityManager.ASSERT(argumentsList != null, "argumentsList expected to be non-null"); SanityManager.ASSERT(argumentsList.length > 1, "argumentsList.length expected to be > 1"); } /* Walk the arguments list until we find a non-null value. Otherwise we will return null */ int index; for (index = 0; index < argumentsList.length; index++) { if (!(argumentsList[index].isNull())) { returnValue.setValue(argumentsList[index]); return returnValue; } } returnValue.setToNull(); return returnValue; } /** * @see DataValueDescriptor#in * @exception StandardException Thrown on error */ public BooleanDataValue in(DataValueDescriptor left, DataValueDescriptor[] inList, boolean orderedList) throws StandardException { BooleanDataValue retval = null; // in list should be non-empty if (SanityManager.DEBUG) { SanityManager.ASSERT(inList != null, "inList expected to be non-null"); SanityManager.ASSERT(inList.length > 0, "inList.length expected to be > 0"); } // if left is null then just return false if (left.isNull()) { return SQLBoolean.truthValue(left, inList[0], false); } int start = 0; int finish = inList.length; /* Do a binary search if the list is ordered until the * range of values to search is 3 or less. * * NOTE: We may have sorted the IN-lst values at compile time using * a specific (dominant) type, but we did *not* actually cast the * values to that type. So it's possible that different IN-list * values have different precedences (verses each other and also * verses the type of the left operand) when we get here. Thus * when we do any comparisons here we have to make sure we always * compare using the dominant type of the two values being compared. * Otherwise we can end up with wrong results when doing the binary * search (ex. as caused by incorrect truncation). DERBY-2256. */ int leftPrecedence = left.typePrecedence(); DataValueDescriptor comparator = null; if (orderedList) { while (finish - start > 2) { int mid = ((finish - start) / 2) + start; comparator = (leftPrecedence < inList[mid].typePrecedence()) ? inList[mid] : left; // Search left retval = comparator.equals(left, inList[mid]); if (retval.equals(true)) { return retval; } BooleanDataValue goLeft = comparator.greaterThan(inList[mid], left); if (goLeft.equals(true)) { // search left finish = mid; } else { // search right start = mid; } } } /* Walk the in list comparing the values. Return as soon as we * find a match. If the list is ordered, return as soon as the left * value is greater than an element in the in list. * * Note: for the same reasons outlined above we must be sure to always * do the comparisons using the dominant type of the two values being * compared. */ for (int index = start; index < finish; index++) { comparator = (leftPrecedence < inList[index].typePrecedence()) ? inList[index] : left; retval = comparator.equals(left, inList[index]); if (retval.equals(true)) { break; } // Can we stop searching? if (orderedList) { BooleanDataValue stop = comparator.greaterThan(inList[index], left); if (stop.equals(true)) { break; } } } return retval; } /* * equals */ public boolean equals(Object other) { if (! (other instanceof DataValueDescriptor)) { return false; } try { return compare(ORDER_OP_EQUALS, (DataValueDescriptor) other, true, false); } catch (StandardException se) { return false; } } public void setValue(InputStream theStream, int valueLength) throws StandardException { throwLangSetMismatch("java.io.InputStream"); } /** Check the value to seem if it conforms to the restrictions imposed by DB2/JCC on host variables for this type. @exception StandardException Variable is too big. */ public void checkHostVariable(int declaredLength) throws StandardException { } /** Return an conversion exception from this type to another. */ protected final StandardException dataTypeConversion(String targetType) { return StandardException.newException(SQLState.LANG_DATA_TYPE_GET_MISMATCH, targetType, this.getTypeName()); } /** Return an out of range exception for this type. */ protected final StandardException outOfRange() { return StandardException.newException( SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE, getTypeName()); } /** Return an out of range exception for this type. */ protected final StandardException invalidFormat() { return StandardException.newException( SQLState.LANG_FORMAT_EXCEPTION, getTypeName()); } }

The table below shows all metrics for DataType.java.

MetricValueDescription
BLOCKS97.00Number of blocks
BLOCK_COMMENT68.00Number of block comment lines
COMMENTS577.00Comment lines
COMMENT_DENSITY 1.67Comment density
COMPARISONS44.00Number of comparison operators
CYCLOMATIC121.00Cyclomatic complexity
DECL_COMMENTS66.00Comments in declarations
DOC_COMMENT493.00Number of javadoc comment lines
ELOC346.00Effective lines of code
EXEC_COMMENTS21.00Comments in executable code
EXITS48.00Procedure exits
FUNCTIONS68.00Number of function declarations
HALSTEAD_DIFFICULTY94.57Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY214.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 1.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 1.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 7.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 1.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 5.00JAVA0106 Unnecessary import from current package
JAVA0108 3.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 8.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA011512.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 1.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 1.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 1.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA01452007.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 3.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 4.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1230.00Number of lines in the source file
LINE_COMMENT16.00Number of line comments
LOC531.00Lines of code
LOGICAL_LINES156.00Number of statements
LOOPS 3.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS848.00Number of operands
OPERATORS1627.00Number of operators
PARAMS74.00Number of formal parameter declarations
PROGRAM_LENGTH2475.00Halstead program length
PROGRAM_VOCAB329.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS140.00Number of return points from functions
SIZE34458.00Size of the file in bytes
UNIQUE_OPERANDS269.00Number of unique operands
UNIQUE_OPERATORS60.00Number of unique operators
WHITESPACE122.00Number of whitespace lines