org.eigenbase.sql.type
Class BasicSqlType

java.lang.Object
  extended by org.eigenbase.reltype.RelDataTypeImpl
      extended by org.eigenbase.sql.type.AbstractSqlType
          extended by org.eigenbase.sql.type.BasicSqlType
All Implemented Interfaces:
Serializable, Cloneable, RelDataType, RelDataTypeFamily

public class BasicSqlType
extends AbstractSqlType

BasicSqlType represents a standard atomic SQL type (excluding interval types).

Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/type/BasicSqlType.java#21 $
Author:
jhyde
See Also:
Serialized Form

Field Summary
private  SqlCollation collation
           
private  int precision
           
static int PRECISION_NOT_SPECIFIED
           
private  int scale
           
static int SCALE_NOT_SPECIFIED
           
private  SerializableCharset wrappedCharset
           
 
Fields inherited from class org.eigenbase.sql.type.AbstractSqlType
isNullable, typeName
 
Fields inherited from class org.eigenbase.reltype.RelDataTypeImpl
digest, fieldList, fields
 
Constructor Summary
BasicSqlType(SqlTypeName typeName)
          Constructs a type with no parameters.
BasicSqlType(SqlTypeName typeName, int precision)
          Constructs a type with precision/length but no scale.
BasicSqlType(SqlTypeName typeName, int precision, int scale)
          Constructs a type with precision/length and scale.
 
Method Summary
(package private)  BasicSqlType createWithCharsetAndCollation(Charset charset, SqlCollation collation)
          Constructs a type with charset and collation
(package private)  BasicSqlType createWithNullability(boolean nullable)
          Constructs a type with nullablity
protected  void generateTypeString(StringBuilder sb, boolean withDetail)
          Generates a string representation of this type.
 Charset getCharset()
          Gets this type's character set, or null if this type cannot carry a character set or has no character set defined.
 SqlCollation getCollation()
          Gets this type's collation, or null if this type cannot carry a collation or has no collation defined.
 Object getLimit(boolean sign, SqlTypeName.Limit limit, boolean beyond)
          Returns a value which is a limit for this type.
 int getPrecision()
          Gets the JDBC-defined precision for values of this type.
 int getScale()
          Gets the scale of this type.
 
Methods inherited from class org.eigenbase.sql.type.AbstractSqlType
getFamily, getPrecedenceList, getSqlTypeName, isNullable
 
Methods inherited from class org.eigenbase.reltype.RelDataTypeImpl
computeDigest, equals, getComparability, getComponentType, getField, getFieldCount, getFieldList, getFieldOrdinal, getFields, getFullTypeString, getIntervalQualifier, getSqlIdentifier, hashCode, isStruct, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SCALE_NOT_SPECIFIED

public static final int SCALE_NOT_SPECIFIED
See Also:
Constant Field Values

PRECISION_NOT_SPECIFIED

public static final int PRECISION_NOT_SPECIFIED
See Also:
Constant Field Values

precision

private int precision

scale

private int scale

collation

private SqlCollation collation

wrappedCharset

private SerializableCharset wrappedCharset
Constructor Detail

BasicSqlType

public BasicSqlType(SqlTypeName typeName)
Constructs a type with no parameters. This should only be called from a factory method.

Parameters:
typeName - Type name
"Precondition:"
typeName.allowsNoPrecNoScale(false,false)

BasicSqlType

public BasicSqlType(SqlTypeName typeName,
                    int precision)
Constructs a type with precision/length but no scale.

Parameters:
typeName - Type name
"Precondition:"
typeName.allowsPrecNoScale(true,false)

BasicSqlType

public BasicSqlType(SqlTypeName typeName,
                    int precision,
                    int scale)
Constructs a type with precision/length and scale.

Parameters:
typeName - Type name
"Precondition:"
typeName.allowsPrecScale(true,true)
Method Detail

createWithNullability

BasicSqlType createWithNullability(boolean nullable)
Constructs a type with nullablity


createWithCharsetAndCollation

BasicSqlType createWithCharsetAndCollation(Charset charset,
                                           SqlCollation collation)
Constructs a type with charset and collation

"Precondition:"
SqlTypeUtil.inCharFamily(this)

getPrecision

public int getPrecision()
Description copied from interface: RelDataType
Gets the JDBC-defined precision for values of this type. Note that this is not always the same as the user-specified precision. For example, the type INTEGER has no user-specified precision, but this method returns 10 for an INTEGER type.

Specified by:
getPrecision in interface RelDataType
Overrides:
getPrecision in class RelDataTypeImpl
Returns:
number of decimal digits for exact numeric types; number of decimal digits in mantissa for approximate numeric types; number of decimal digits for fractional seconds of datetime types; length in characters for character types; length in bytes for binary types; length in bits for bit types; 1 for BOOLEAN

getScale

public int getScale()
Description copied from interface: RelDataType
Gets the scale of this type.

Specified by:
getScale in interface RelDataType
Overrides:
getScale in class RelDataTypeImpl
Returns:
number of digits of scale

getCharset

public Charset getCharset()
                   throws RuntimeException
Description copied from interface: RelDataType
Gets this type's character set, or null if this type cannot carry a character set or has no character set defined.

Specified by:
getCharset in interface RelDataType
Overrides:
getCharset in class RelDataTypeImpl
Returns:
charset of type
Throws:
RuntimeException

getCollation

public SqlCollation getCollation()
                          throws RuntimeException
Description copied from interface: RelDataType
Gets this type's collation, or null if this type cannot carry a collation or has no collation defined.

Specified by:
getCollation in interface RelDataType
Overrides:
getCollation in class RelDataTypeImpl
Returns:
collation of type
Throws:
RuntimeException

generateTypeString

protected void generateTypeString(StringBuilder sb,
                                  boolean withDetail)
Description copied from class: RelDataTypeImpl
Generates a string representation of this type.

Specified by:
generateTypeString in class RelDataTypeImpl
Parameters:
sb - StringBuffer into which to generate the string
withDetail - when true, all detail information needed to compute a unique digest (and return from getFullTypeString) should be included;

getLimit

public Object getLimit(boolean sign,
                       SqlTypeName.Limit limit,
                       boolean beyond)
Returns a value which is a limit for this type.

For example,

Datatype sign limit beyond precision scale Returns
Integer true true false -1 -1 2147483647 (2 ^ 31 -1 = MAXINT)
Integer true true true -1 -1 2147483648 (2 ^ 31 = MAXINT + 1)
Integer false true false -1 -1 -2147483648 (-2 ^ 31 = MININT)
Boolean true true false -1 -1 TRUE
Varchar true true false 10 -1 'ZZZZZZZZZZ'

Parameters:
sign - If true, returns upper limit, otherwise lower limit
limit - If true, returns value at or near to overflow; otherwise value at or near to underflow
beyond - If true, returns the value just beyond the limit, otherwise the value at the limit
Returns:
Limit value