Package edu.caltech.nanodb.relations
Class ColumnType
- java.lang.Object
-
- edu.caltech.nanodb.relations.ColumnType
-
- All Implemented Interfaces:
java.io.Serializable
public class ColumnType extends java.lang.Object implements java.io.Serializable
The type of a single column in a relation. The type is composed of two parts. The first part is present in all attribute-types, and is the "base type" of the attribute, such as INTEGER, TIMESTAMP, or CHARACTER. These values are represented by theSQLDataType
enumeration. However, some of these types also require additional information about their length, precision, or other details. This second part is included as values in this class. The two parts together represent the type of a particular attribute.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private SQLDataType
baseType
The base SQL data-type for the attribute.static ColumnType
BIGINT
static ColumnType
DATE
static ColumnType
DATETIME
static int
DEFAULT_PRECISION
static int
DEFAULT_SCALE
static ColumnType
DOUBLE
static ColumnType
FILE_POINTER
static ColumnType
FLOAT
static ColumnType
INTEGER
private int
length
For CHAR and VARCHAR attributes, this contains the length (or maximum length) of the character-sequence.private int
precision
For NUMERIC attributes, this contains the precision of the number, or the total number of significant digits in the number.private int
scale
For NUMERIC attributes, this contains the scale of the number, or the number of significant digits that are to the right of the decimal place.static ColumnType
SMALLINT
static ColumnType
TIME
static ColumnType
TIMESTAMP
static ColumnType
TINYINT
-
Constructor Summary
Constructors Constructor Description ColumnType(SQLDataType baseType)
Construct a new attribute-type instance, with the specified base SQL datatype.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ColumnType
CHAR(int length)
boolean
equals(java.lang.Object obj)
Returns true if obj is another ColumnType object with the same type information, including both base type and any relevant size information.SQLDataType
getBaseType()
Returns the base datatype for the attribute.int
getLength()
Returns the length of the data for CHAR and VARCHAR attributes.int
getPrecision()
Returns the precision of the data for NUMERIC attributes.int
getScale()
Returns the scale of the data for NUMERIC attributes.int
hashCode()
boolean
hasLength()
Returns true if this column type supports/requires a length, or false if the type does not.static ColumnType
NUMERIC()
static ColumnType
NUMERIC(int precision)
static ColumnType
NUMERIC(int precision, int scale)
void
setLength(int val)
Specify the length of the data for CHAR and VARCHAR attributes.void
setPrecision(int val)
Specify the precision of the data for NUMERIC attributes.void
setScale(int val)
Specify the scale of the data for NUMERIC attributes.java.lang.String
toString()
static ColumnType
VARCHAR(int length)
-
-
-
Field Detail
-
DEFAULT_PRECISION
public static final int DEFAULT_PRECISION
- See Also:
- Constant Field Values
-
DEFAULT_SCALE
public static final int DEFAULT_SCALE
- See Also:
- Constant Field Values
-
INTEGER
public static final ColumnType INTEGER
-
SMALLINT
public static final ColumnType SMALLINT
-
BIGINT
public static final ColumnType BIGINT
-
TINYINT
public static final ColumnType TINYINT
-
FLOAT
public static final ColumnType FLOAT
-
DOUBLE
public static final ColumnType DOUBLE
-
DATE
public static final ColumnType DATE
-
TIME
public static final ColumnType TIME
-
DATETIME
public static final ColumnType DATETIME
-
TIMESTAMP
public static final ColumnType TIMESTAMP
-
FILE_POINTER
public static final ColumnType FILE_POINTER
-
baseType
private SQLDataType baseType
The base SQL data-type for the attribute.
-
length
private int length
For CHAR and VARCHAR attributes, this contains the length (or maximum length) of the character-sequence. This value must be at least 1; zero and negative values are invalid.This value is required in CHAR and VARCHAR attribute-declarations, but we default to a length of 1 here.
-
precision
private int precision
For NUMERIC attributes, this contains the precision of the number, or the total number of significant digits in the number.The default precision value used is
DEFAULT_PRECISION
.
-
scale
private int scale
For NUMERIC attributes, this contains the scale of the number, or the number of significant digits that are to the right of the decimal place.The SQL Standard says that the default scale should be zero, which although this seems a bit useless, that's what we do.
-
-
Constructor Detail
-
ColumnType
public ColumnType(SQLDataType baseType)
Construct a new attribute-type instance, with the specified base SQL datatype. Note that more information may be needed to complete the attribute-type information, depending on the SQL datatype that is being used.- Parameters:
baseType
- the base SQL datatype for this column type
-
-
Method Detail
-
VARCHAR
public static ColumnType VARCHAR(int length)
-
CHAR
public static ColumnType CHAR(int length)
-
NUMERIC
public static ColumnType NUMERIC()
-
NUMERIC
public static ColumnType NUMERIC(int precision)
-
NUMERIC
public static ColumnType NUMERIC(int precision, int scale)
-
equals
public boolean equals(java.lang.Object obj)
Returns true if obj is another ColumnType object with the same type information, including both base type and any relevant size information.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getBaseType
public SQLDataType getBaseType()
Returns the base datatype for the attribute.- Returns:
- the base SQL datatype for the attribute
-
hasLength
public boolean hasLength()
Returns true if this column type supports/requires a length, or false if the type does not.- Returns:
- true if this column type supports/requires a length, or false if the type does not
-
setLength
public void setLength(int val)
Specify the length of the data for CHAR and VARCHAR attributes.- Parameters:
val
- the length of the data-type- Throws:
java.lang.IllegalStateException
- if the attribute's base-type is not CHAR or VARCHAR.java.lang.IllegalArgumentException
- if the specified length is zero or negative.
-
getLength
public int getLength()
Returns the length of the data for CHAR and VARCHAR attributes.- Returns:
- the length of the data-type
- Throws:
java.lang.IllegalStateException
- if the attribute's base-type is not CHAR or VARCHAR.
-
setPrecision
public void setPrecision(int val)
Specify the precision of the data for NUMERIC attributes.- Parameters:
val
- the precision of the data-type- Throws:
java.lang.IllegalStateException
- if the attribute's base-type is not NUMERIC.java.lang.IllegalArgumentException
- if the specified precision is zero or negative, or if the specified precision is less than the scale.
-
getPrecision
public int getPrecision()
Returns the precision of the data for NUMERIC attributes.- Returns:
- the precision of the data-type
- Throws:
java.lang.IllegalStateException
- if the attribute's base-type is not NUMERIC.
-
setScale
public void setScale(int val)
Specify the scale of the data for NUMERIC attributes.- Parameters:
val
- the scale of the data-type- Throws:
java.lang.IllegalStateException
- if the attribute's base-type is not NUMERIC.java.lang.IllegalArgumentException
- if the specified scale is negative, or if the specified scale is greater than the precision.
-
getScale
public int getScale()
Returns the scale of the data for NUMERIC attributes.- Returns:
- the scale of the data-type
- Throws:
java.lang.IllegalStateException
- if the attribute's base-type is not NUMERIC.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-