Package org.apache.derby.catalog.types
Class TypeDescriptorImpl
- java.lang.Object
-
- org.apache.derby.catalog.types.TypeDescriptorImpl
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,TypeDescriptor
,Formatable
,TypedFormat
public class TypeDescriptorImpl extends java.lang.Object implements TypeDescriptor, Formatable
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private int
collationType
private boolean
isNullable
private int
maximumWidth
private int
precision
private int
scale
private BaseTypeIdImpl
typeId
This class implements Formatable.-
Fields inherited from interface org.apache.derby.catalog.TypeDescriptor
DOUBLE, INTEGER, INTEGER_NOT_NULL, MAXIMUM_WIDTH_UNKNOWN, SMALLINT, SMALLINT_NOT_NULL
-
-
Constructor Summary
Constructors Constructor Description TypeDescriptorImpl()
Public niladic constructor.TypeDescriptorImpl(BaseTypeIdImpl typeId, boolean isNullable, int maximumWidth)
Constructor for use with non-numeric typesTypeDescriptorImpl(BaseTypeIdImpl typeId, int precision, int scale, boolean isNullable, int maximumWidth)
Constructor for use with numeric typesTypeDescriptorImpl(BaseTypeIdImpl typeId, int precision, int scale, boolean isNullable, int maximumWidth, int collationType)
Constructor to use when the caller doesn't know if it is requesting numeric or no-numeric DTD.TypeDescriptorImpl(TypeDescriptorImpl source, boolean isNullable, int maximumWidth)
Constructor for internal uses onlyTypeDescriptorImpl(TypeDescriptorImpl source, int precision, int scale, boolean isNullable, int maximumWidth)
Constructor for internal uses only.TypeDescriptorImpl(TypeDescriptorImpl source, int precision, int scale, boolean isNullable, int maximumWidth, int collationType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TypeDescriptor[]
copyTypeDescriptors(TypeDescriptor[] original)
copy an array of type descriptorsboolean
equals(java.lang.Object object)
Compare if two TypeDescriptors are exactly the sameint
getCollationType()
Get the collation type for this type.int
getJDBCTypeId()
Get the jdbc type id for this type.int
getMaximumWidth()
Returns the maximum width of the type.int
getMaximumWidthInBytes()
Return the length of this type in bytes.int
getPrecision()
Returns the number of decimal digits for the datatype, if applicable.java.lang.String[]
getRowColumnNames()
If this catalog type is a row multi-set type then return its array of column names.TypeDescriptor[]
getRowTypes()
If this catalog type is a row multi-set type then return its array of catalog types.int
getScale()
Returns the number of digits to the right of the decimal for the datatype, if applicable.java.lang.String
getSQLstring()
Converts this data type descriptor (including length/precision) to a string.int
getTypeFormatId()
Get the formatID which corresponds to this class.BaseTypeIdImpl
getTypeId()
Get the type Id stored within this type descriptor.java.lang.String
getTypeName()
Gets the name of this datatype.boolean
isNullable()
Returns TRUE if the datatype can contain NULL, FALSE if not.boolean
isRowMultiSet()
Return true if this is a Row Multiset typeboolean
isStringType()
Report whether this type is a string type.boolean
isUserDefinedType()
Return true if this is a user defined typevoid
readExternal(java.io.ObjectInput in)
Read this object from a stream of stored objects.void
setCollationType(int collationTypeValue)
java.lang.String
toString()
void
writeExternal(java.io.ObjectOutput out)
Write this object to a stream of stored objects.
-
-
-
Field Detail
-
typeId
private BaseTypeIdImpl typeId
This class implements Formatable. That means that it can write itself to and from a formatted stream. If you add more fields to this class, make sure that you also write/read them with the writeExternal()/readExternal() methods. If, inbetween releases, you add more fields to this class, then you should bump the version number emitted by the getTypeFormatId() method.
-
precision
private int precision
-
scale
private int scale
-
isNullable
private boolean isNullable
-
maximumWidth
private int maximumWidth
-
collationType
private int collationType
- See Also:
TypeDescriptor.getCollationType()
-
-
Constructor Detail
-
TypeDescriptorImpl
public TypeDescriptorImpl()
Public niladic constructor. Needed for Formatable interface to work.
-
TypeDescriptorImpl
public TypeDescriptorImpl(BaseTypeIdImpl typeId, int precision, int scale, boolean isNullable, int maximumWidth)
Constructor for use with numeric types- Parameters:
typeId
- The typeId of the type being describedprecision
- The number of decimal digits.scale
- The number of digits after the decimal point.isNullable
- TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.maximumWidth
- The maximum number of bytes for this datatype
-
TypeDescriptorImpl
public TypeDescriptorImpl(BaseTypeIdImpl typeId, int precision, int scale, boolean isNullable, int maximumWidth, int collationType)
Constructor to use when the caller doesn't know if it is requesting numeric or no-numeric DTD. For instance, when dealing with MAX/MIN aggregrate operators, AggregateNode.bindExpression could be dealing with a character string operand or a numeric operand. The result of MAX/MIN will depend on the type of it's operand. And hence when this constructor gets called by AggregateNode.bindExpression, we don't know what type we are constructing and hence this constructor supports arguments for both numeric and non-numeric types.- Parameters:
typeId
- The typeId of the type being describedprecision
- The number of decimal digits.scale
- The number of digits after the decimal point.isNullable
- TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.maximumWidth
- The maximum number of bytes for this datatypecollationType
- The collation type of a string data type
-
TypeDescriptorImpl
public TypeDescriptorImpl(BaseTypeIdImpl typeId, boolean isNullable, int maximumWidth)
Constructor for use with non-numeric types- Parameters:
typeId
- The typeId of the type being describedisNullable
- TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.maximumWidth
- The maximum number of bytes for this datatype
-
TypeDescriptorImpl
public TypeDescriptorImpl(TypeDescriptorImpl source, int precision, int scale, boolean isNullable, int maximumWidth)
Constructor for internal uses only. (This is useful when the precision and scale are potentially wider than those in the source, like when determining the dominant data type.)- Parameters:
source
- The DTSI to copyprecision
- The number of decimal digits.scale
- The number of digits after the decimal point.isNullable
- TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.maximumWidth
- The maximum number of bytes for this datatype
-
TypeDescriptorImpl
public TypeDescriptorImpl(TypeDescriptorImpl source, int precision, int scale, boolean isNullable, int maximumWidth, int collationType)
-
TypeDescriptorImpl
public TypeDescriptorImpl(TypeDescriptorImpl source, boolean isNullable, int maximumWidth)
Constructor for internal uses only- Parameters:
source
- The DTSI to copyisNullable
- TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.maximumWidth
- The maximum number of bytes for this datatype
-
-
Method Detail
-
copyTypeDescriptors
public static TypeDescriptor[] copyTypeDescriptors(TypeDescriptor[] original)
copy an array of type descriptors
-
getMaximumWidth
public int getMaximumWidth()
Description copied from interface:TypeDescriptor
Returns the maximum width of the type. This may have different meanings for different types. For example, with char, it means the maximum number of characters, while with int, it is the number of bytes (i.e. 4).- Specified by:
getMaximumWidth
in interfaceTypeDescriptor
- Returns:
- the maximum length of this Type; -1 means "unknown/no max length"
- See Also:
TypeDescriptor.getMaximumWidth()
-
getMaximumWidthInBytes
public int getMaximumWidthInBytes()
Return the length of this type in bytes. Note that while the JDBC API _does_ define a need for returning length in bytes of a type, it doesn't state clearly what that means for the various types. We assume therefore that the values here are meant to match those specified by the ODBC specification (esp. since ODBC clients are more likely to need this value than a Java client). The ODBC spec that defines the values we use here can be found at the following link: http://msdn.microsoft.com/library/default.asp?url=/library/ en-us/odbc/htm/odbctransfer_octet_length.asp- Specified by:
getMaximumWidthInBytes
in interfaceTypeDescriptor
- Returns:
- the maximum length of this Type IN BYTES; -1 means "unknown/no max length"
- See Also:
TypeDescriptor.getMaximumWidthInBytes()
-
isStringType
public boolean isStringType()
Report whether this type is a string type.
-
getJDBCTypeId
public int getJDBCTypeId()
Get the jdbc type id for this type. JDBC type can be found in java.sql.Types.- Specified by:
getJDBCTypeId
in interfaceTypeDescriptor
- Returns:
- a jdbc type, e.g. java.sql.Types.DECIMAL
- See Also:
Types
-
getTypeName
public java.lang.String getTypeName()
Gets the name of this datatype.- Specified by:
getTypeName
in interfaceTypeDescriptor
- Returns:
- the name of this datatype
-
getPrecision
public int getPrecision()
Returns the number of decimal digits for the datatype, if applicable.- Specified by:
getPrecision
in interfaceTypeDescriptor
- Returns:
- The number of decimal digits for the datatype. Returns zero for non-numeric datatypes.
-
getScale
public int getScale()
Returns the number of digits to the right of the decimal for the datatype, if applicable.- Specified by:
getScale
in interfaceTypeDescriptor
- Returns:
- The number of digits to the right of the decimal for the datatype. Returns zero for non-numeric datatypes.
-
isNullable
public boolean isNullable()
Returns TRUE if the datatype can contain NULL, FALSE if not. JDBC supports a return value meaning "nullability unknown" - I assume we will never have columns where the nullability is unknown.- Specified by:
isNullable
in interfaceTypeDescriptor
- Returns:
- TRUE if the datatype can contain NULL, FALSE if not.
-
isRowMultiSet
public boolean isRowMultiSet()
Description copied from interface:TypeDescriptor
Return true if this is a Row Multiset type- Specified by:
isRowMultiSet
in interfaceTypeDescriptor
- See Also:
TypeDescriptor.isRowMultiSet()
-
isUserDefinedType
public boolean isUserDefinedType()
Description copied from interface:TypeDescriptor
Return true if this is a user defined type- Specified by:
isUserDefinedType
in interfaceTypeDescriptor
- See Also:
TypeDescriptor.isUserDefinedType()
-
getCollationType
public int getCollationType()
Description copied from interface:TypeDescriptor
Get the collation type for this type. This api applies only to character string types. And its return value is valid only if the collation derivation of this type is "implicit" or "explicit". (In Derby 10.3, collation derivation can't be "explicit". Hence in Derby 10.3, this api should be used only if the collation derivation is "implicit".- Specified by:
getCollationType
in interfaceTypeDescriptor
- Returns:
- collation type which applies to character string types with collation derivation of "implicit" or "explicit". The possible return values in Derby 10.3 will be COLLATION_TYPE_UCS_BASIC and COLLATION_TYPE_TERRITORY_BASED.
- See Also:
TypeDescriptor.getCollationType()
-
setCollationType
public void setCollationType(int collationTypeValue)
-
getSQLstring
public java.lang.String getSQLstring()
Converts this data type descriptor (including length/precision) to a string. E.g. VARCHAR(30) or java.util.Hashtable- Specified by:
getSQLstring
in interfaceTypeDescriptor
- Returns:
- String version of datatype, suitable for running through the Parser.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getTypeId
public BaseTypeIdImpl getTypeId()
Get the type Id stored within this type descriptor.
-
equals
public boolean equals(java.lang.Object object)
Compare if two TypeDescriptors are exactly the same- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- the dataTypeDescriptor to compare to.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
Read this object from a stream of stored objects.- Specified by:
readExternal
in interfacejava.io.Externalizable
- Parameters:
in
- read this.- Throws:
java.io.IOException
- thrown on errorjava.lang.ClassNotFoundException
- thrown on error
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
Write this object to a stream of stored objects.- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Parameters:
out
- write bytes here.- Throws:
java.io.IOException
- thrown on error
-
getTypeFormatId
public int getTypeFormatId()
Get the formatID which corresponds to this class.- Specified by:
getTypeFormatId
in interfaceTypedFormat
- Returns:
- the formatID of this class
-
getRowColumnNames
public java.lang.String[] getRowColumnNames()
Description copied from interface:TypeDescriptor
If this catalog type is a row multi-set type then return its array of column names.- Specified by:
getRowColumnNames
in interfaceTypeDescriptor
- Returns:
- Column names comprising the row, null if this is not a row type.
-
getRowTypes
public TypeDescriptor[] getRowTypes()
Description copied from interface:TypeDescriptor
If this catalog type is a row multi-set type then return its array of catalog types.- Specified by:
getRowTypes
in interfaceTypeDescriptor
- Returns:
- Catalog ypes comprising the row, null if this is not a row type.
-
-