Package com.healthmarketscience.jackcess
Class ColumnBuilder
- java.lang.Object
-
- com.healthmarketscience.jackcess.ColumnBuilder
-
public class ColumnBuilder extends Object
Builder style class for constructing aColumn. SeeTableBuilderfor example usage. Additionally, a Column can be added to an existing Table using theaddToTable(Table)method.- Author:
- James Ahlborn
- See Also:
TableBuilder- Usage:
- General: This class is general use.
-
-
Constructor Summary
Constructors Constructor Description ColumnBuilder(String name)ColumnBuilder(String name, DataType type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ColumnaddToTable(Table table)Adds a new Column to the given Table with the currently configured attributes.ColumnaddToTableDefinition(TableDefinition table)Adds a new Column to the given TableDefinition with the currently configured attributes.ColumnBuilderescapeName()Escapes the new column's name usingTableBuilder.escapeIdentifier(java.lang.String).shortgetColumnId()shortgetColumnNumber()ComplexColumnDescgetComplexDesc()intgetFixedDataSize()shortgetLength()StringgetName()bytegetPrecision()Map<String,PropertyMap.Property>getProperties()bytegetScale()ColumnImpl.SortOrdergetTextSortOrder()DataTypegetType()booleanisAppendOnly()booleanisAutoNumber()booleanisCalculated()booleanisCompressedUnicode()booleanisHyperlink()booleanisVariableLength()ColumnBuilderputProperty(String name, DataType type, Object value)Sets the column property with the given name and type to the given value.ColumnBuilderputProperty(String name, Object value)Sets the column property with the given name to the given value.ColumnBuildersetAppendOnly(boolean appendOnly)Sets whether or not a memo column keeps the history of its values.ColumnBuildersetAttachment()Makes the new column an attachment column.ColumnBuildersetAutoNumber(boolean autoNumber)Sets whether of not the new column is an auto-number column.ColumnBuildersetCalculated(boolean calculated)Sets whether of not the new column is a calculated column.ColumnBuildersetCalculatedInfo(String expression)Convenience method to set the various info for a calculated type (flag, result type property and expression)voidsetColumnId(short newColumnId)voidsetColumnNumber(short newColumnNumber)ColumnBuildersetCompressedUnicode(boolean compressedUnicode)Sets whether of not the new column allows unicode compression.ColumnBuildersetFromColumn(Column template)Sets all attributes except name from the given Column template (including all column properties except GUID).ColumnBuildersetFromColumn(ColumnBuilder template)Sets all attributes except name from the given Column template.ColumnBuildersetHyperlink(boolean hyperlink)Sets whether of not the new column allows unicode compression.ColumnBuildersetLength(int length)Sets the length (in bytes) for the new column.ColumnBuildersetLengthInUnits(int unitLength)Sets the length (in type specific units) for the new column.ColumnBuildersetMaxLength()Sets the length for the new column to the max length for the type.ColumnBuildersetMaxPrecision()Sets the precision for the new column to the max length for the type.ColumnBuildersetMaxScale()Sets the scale for the new column to the max length for the type.ColumnBuildersetMultiValue(DataType valueType)Makes the new column a multi-value complex column which holds values of the given type, one of BYTE, INT, LONG, FLOAT, DOUBLE, GUID, NUMERIC or TEXT.ColumnBuildersetPrecision(int newPrecision)Sets the precision for the new column.ColumnBuildersetRowSource(String tableOrQuery, int columnCount)Gives a multi-value column a table or a query as the source of the values which ms access offers.ColumnBuildersetScale(int newScale)Sets the scale for the new column.ColumnBuildersetSQLType(int type)Sets the type for the new column based on the given SQL type.ColumnBuildersetSQLType(int type, int lengthInUnits)Sets the type for the new column based on the given SQL type and target data length (in type specific units).ColumnBuildersetSQLType(int type, int lengthInUnits, Database.FileFormat fileFormat)Sets the type for the new column based on the given SQL type, target data length (in type specific units), and target FileFormat.voidsetTextSortOrder(ColumnImpl.SortOrder newTextSortOrder)ColumnBuildersetType(DataType type)Sets the type for the new column.ColumnBuildersetValueList(String... values)Gives a multi-value column the list of values which ms access offers.booleanstoreInNullMask()ColumnBuildertoColumn()Creates a new Column with the currently configured attributes.StringtoString()voidvalidate(JetFormat format)Checks that this column definition is valid.
-
-
-
Method Detail
-
getName
public String getName()
-
setType
public ColumnBuilder setType(DataType type)
Sets the type for the new column.
-
getType
public DataType getType()
-
setSQLType
public ColumnBuilder setSQLType(int type) throws IOException
Sets the type for the new column based on the given SQL type.- Throws:
IOException
-
setSQLType
public ColumnBuilder setSQLType(int type, int lengthInUnits) throws IOException
Sets the type for the new column based on the given SQL type and target data length (in type specific units).- Throws:
IOException
-
setSQLType
public ColumnBuilder setSQLType(int type, int lengthInUnits, Database.FileFormat fileFormat) throws IOException
Sets the type for the new column based on the given SQL type, target data length (in type specific units), and target FileFormat.- Throws:
IOException
-
setPrecision
public ColumnBuilder setPrecision(int newPrecision)
Sets the precision for the new column.
-
getPrecision
public byte getPrecision()
-
setMaxPrecision
public ColumnBuilder setMaxPrecision()
Sets the precision for the new column to the max length for the type. Does nothing for types which do not have a precision.
-
setScale
public ColumnBuilder setScale(int newScale)
Sets the scale for the new column.
-
getScale
public byte getScale()
-
setMaxScale
public ColumnBuilder setMaxScale()
Sets the scale for the new column to the max length for the type. Does nothing for types which do not have a scale.
-
setLength
public ColumnBuilder setLength(int length)
Sets the length (in bytes) for the new column.
-
getLength
public short getLength()
-
setLengthInUnits
public ColumnBuilder setLengthInUnits(int unitLength)
Sets the length (in type specific units) for the new column.
-
setMaxLength
public ColumnBuilder setMaxLength()
Sets the length for the new column to the max length for the type. Does nothing for types which are not variable length.
-
setAutoNumber
public ColumnBuilder setAutoNumber(boolean autoNumber)
Sets whether of not the new column is an auto-number column.
-
isAutoNumber
public boolean isAutoNumber()
-
setCompressedUnicode
public ColumnBuilder setCompressedUnicode(boolean compressedUnicode)
Sets whether of not the new column allows unicode compression.
-
isCompressedUnicode
public boolean isCompressedUnicode()
-
setCalculated
public ColumnBuilder setCalculated(boolean calculated)
Sets whether of not the new column is a calculated column.
-
isCalculated
public boolean isCalculated()
-
setCalculatedInfo
public ColumnBuilder setCalculatedInfo(String expression)
Convenience method to set the various info for a calculated type (flag, result type property and expression)
-
setMultiValue
public ColumnBuilder setMultiValue(DataType valueType)
Makes the new column a multi-value complex column which holds values of the given type, one of BYTE, INT, LONG, FLOAT, DOUBLE, GUID, NUMERIC or TEXT. The values live in a supporting table whose shape comes from the matchingMSysComplexType_table of the database, so the length and the precision of a value are not the caller's to choose.A multi-value column also needs a row source, from either
setValueList(java.lang.String...)orsetRowSource(java.lang.String, int).
-
setValueList
public ColumnBuilder setValueList(String... values)
Gives a multi-value column the list of values which ms access offers. At least one value is necessary, because ms access offers no way to add a value which its row source does not name.
-
setRowSource
public ColumnBuilder setRowSource(String tableOrQuery, int columnCount)
Gives a multi-value column a table or a query as the source of the values which ms access offers.- Parameters:
tableOrQuery- the name of a table or a query, or a SELECT statementcolumnCount- the number of columns it gives
-
setAttachment
public ColumnBuilder setAttachment()
Makes the new column an attachment column. The shape of an attachment comes from theMSysComplexType_Attachmenttable of the database, so an attachment column takes no further settings.
-
setAppendOnly
public ColumnBuilder setAppendOnly(boolean appendOnly)
Sets whether or not a memo column keeps the history of its values. The versions live in a complex column which jackcess adds beside the memo column, and which is read back throughColumn.getComplexInfo()of that added column.
-
isAppendOnly
public boolean isAppendOnly()
-
getComplexDesc
public ComplexColumnDesc getComplexDesc()
- Returns:
- the complex column this builder declares, or
nullif it declares none. Read through this rather than the field, because jackcess builds a complex column of its own which overrides it. - Usage:
- Advanced: This method is for advanced/internal use.
-
isVariableLength
public boolean isVariableLength()
-
setHyperlink
public ColumnBuilder setHyperlink(boolean hyperlink)
Sets whether of not the new column allows unicode compression.
-
isHyperlink
public boolean isHyperlink()
-
putProperty
public ColumnBuilder putProperty(String name, Object value)
Sets the column property with the given name to the given value. Attempts to determine the type of the property (seePropertyMap.put(String,Object)for details on determining the property type).
-
putProperty
public ColumnBuilder putProperty(String name, DataType type, Object value)
Sets the column property with the given name and type to the given value.
-
getProperties
public Map<String,PropertyMap.Property> getProperties()
-
setFromColumn
public ColumnBuilder setFromColumn(Column template) throws IOException
Sets all attributes except name from the given Column template (including all column properties except GUID).- Throws:
IOException
-
setFromColumn
public ColumnBuilder setFromColumn(ColumnBuilder template)
Sets all attributes except name from the given Column template.
-
escapeName
public ColumnBuilder escapeName()
Escapes the new column's name usingTableBuilder.escapeIdentifier(java.lang.String).
-
getColumnNumber
public short getColumnNumber()
- Usage:
- Advanced: This method is for advanced/internal use.
-
setColumnNumber
public void setColumnNumber(short newColumnNumber)
- Usage:
- Advanced: This method is for advanced/internal use.
-
getColumnId
public short getColumnId()
- Usage:
- Advanced: This method is for advanced/internal use.
-
setColumnId
public void setColumnId(short newColumnId)
- Usage:
- Advanced: This method is for advanced/internal use.
-
getTextSortOrder
public ColumnImpl.SortOrder getTextSortOrder()
- Usage:
- Advanced: This method is for advanced/internal use.
-
setTextSortOrder
public void setTextSortOrder(ColumnImpl.SortOrder newTextSortOrder)
- Usage:
- Advanced: This method is for advanced/internal use.
-
storeInNullMask
public boolean storeInNullMask()
- Usage:
- Advanced: This method is for advanced/internal use.
-
getFixedDataSize
public int getFixedDataSize()
- Usage:
- Advanced: This method is for advanced/internal use.
-
validate
public void validate(JetFormat format)
Checks that this column definition is valid.- Throws:
IllegalArgumentException- if this column definition is invalid.- Usage:
- Advanced: This method is for advanced/internal use.
-
toColumn
public ColumnBuilder toColumn()
Creates a new Column with the currently configured attributes.
-
addToTable
public Column addToTable(Table table) throws IOException
Adds a new Column to the given Table with the currently configured attributes.- Throws:
IOException
-
addToTableDefinition
public Column addToTableDefinition(TableDefinition table) throws IOException
Adds a new Column to the given TableDefinition with the currently configured attributes.- Throws:
IOException
-
-