/** * Sets the type for the new column based on the given SQL type, target * data length (in type specific units), and target FileFormat. */ public ColumnBuilder setSQLType(int type, int lengthInUnits, Database.FileFormat fileFormat) throws SQLException { return setType(DataType.fromSQLType(type, lengthInUnits, fileFormat)); }
protected void validateColumn(Set<String> colNames, ColumnBuilder column) { // FIXME for now, we can't create complex columns if(column.getType() == DataType.COMPLEX_TYPE) { throw new UnsupportedOperationException(withErrorContext( "Complex column creation is not yet implemented")); } column.validate(getFormat()); if(!colNames.add(DatabaseImpl.toLookupName(column.getName()))) { throw new IllegalArgumentException(withErrorContext( "duplicate column name: " + column.getName())); } setColumnSortOrder(column); }
/** * Convenience method to set the various info for a calculated type (flag, * result type property and expression) */ public ColumnBuilder setCalculatedInfo(String expression) { setCalculated(true); putProperty(PropertyMap.EXPRESSION_PROP, expression); return putProperty(PropertyMap.RESULT_TYPE_PROP, getType().getValue()); }
@Override short getColumnNumber(String colName) { for(ColumnBuilder col : _columns) { if(col.getName().equalsIgnoreCase(colName)) { return col.getColumnNumber(); } } return IndexData.COLUMN_UNUSED; }
/** * Constructs a byte containing the flags for this column. */ private static byte getColumnBitFlags(ColumnBuilder col) { byte flags = UPDATABLE_FLAG_MASK; if(!col.isVariableLength()) { flags |= FIXED_LEN_FLAG_MASK; } if(col.isAutoNumber()) { byte autoNumFlags = 0; switch(col.getType()) { case LONG: case COMPLEX_TYPE: autoNumFlags = AUTO_NUMBER_FLAG_MASK; break; case GUID: autoNumFlags = AUTO_NUMBER_GUID_FLAG_MASK; break; default: // unknown autonum type } flags |= autoNumFlags; } if(col.isHyperlink()) { flags |= HYPERLINK_FLAG_MASK; } return flags; }
String name = rs.getString("COLUMN_NAME"); String nname = getNormalizedName(name, columnMap); ColumnBuilder cb = new ColumnBuilder(nname); short length = (short) rs.getInt("COLUMN_SIZE"); byte scale = (byte) rs.getInt("DECIMAL_DIGITS"); || types[seq].equalsIgnoreCase(AccessType.HYPERLINK.name())) { dt = DataType.MEMO; cb.setType(dt); if (types[seq].equalsIgnoreCase(AccessType.HYPERLINK.name())) { cb.setHyperlink(true); cb.setType(dt); || types[seq].equalsIgnoreCase(AccessType.AUTOINCREMENT.name()))) { dt = TypesMap.map2Jackcess(AccessType.valueOf(types[seq].toUpperCase(Locale.US))); cb.setType(dt); cb.setLengthInUnits((short) dt.getFixedSize()); cb.setType(dt); if (length > 0 && dt.equals(DataType.TEXT)) { cb.setLengthInUnits(length); cb.setScale(scale); if (length > 0) { cb.setPrecision(length); if (types[seq].equalsIgnoreCase(AccessType.COUNTER.name()) || types[seq].equalsIgnoreCase(AccessType.AUTOINCREMENT.name())) {
/** * Sets all attributes except name from the given Column template (including * all column properties except GUID). */ public ColumnBuilder setFromColumn(Column template) throws IOException { DataType type = template.getType(); setType(type); setLength(template.getLength()); setAutoNumber(template.isAutoNumber()); if(type.getHasScalePrecision()) { setScale(template.getScale()); setPrecision(template.getPrecision()); } setCalculated(template.isCalculated()); setCompressedUnicode(template.isCompressedUnicode()); setHyperlink(template.isHyperlink()); if(template instanceof ColumnImpl) { setTextSortOrder(((ColumnImpl)template).getTextSortOrder()); } PropertyMap colProps = template.getProperties(); for(PropertyMap.Property colProp : colProps) { // copy everything but guid if(!PropertyMap.GUID_PROP.equalsIgnoreCase(colProp.getName())) { setProperty(colProp.getName(), colProp); } } return this; }
getName(), format.MAX_COLUMN_NAME_LENGTH, "column"); if(getType() == null) { throw new IllegalArgumentException(withErrorContext("must have type")); if(getType().isUnsupported()) { throw new IllegalArgumentException(withErrorContext( "Cannot create column with unsupported type " + getType())); if(!format.isSupportedDataType(getType())) { throw new IllegalArgumentException(withErrorContext( "Database format " + format + " does not support type " + getType())); if(!getType().isVariableLength()) { if(getLength() < getType().getFixedSize()) { throw new IllegalArgumentException(withErrorContext( "Invalid fixed length size " + getLength())); } else if(!getType().isLongValue()) { if(!getType().isValidSize(getLength())) { throw new IllegalArgumentException(withErrorContext( "Var length must be from " + getType().getMinSize() + " to " + getType().getMaxSize() + " inclusive, found " + getLength())); if(getType().getHasScalePrecision()) { if(!getType().isValidScale(getScale())) { throw new IllegalArgumentException(withErrorContext( "Scale must be from " + getType().getMinScale() + " to " + getType().getMaxScale() + " inclusive, found " + getScale()));
ColumnBuilder column = new ColumnBuilder(md.getColumnLabel(i)) .escapeName(); int lengthInUnits = md.getColumnDisplaySize(i); column.setSQLType(md.getColumnType(i), lengthInUnits); DataType type = column.getType(); column.setLengthInUnits((short)lengthInUnits); int precision = md.getPrecision(i); if(type.isValidScale(scale)) { column.setScale((byte)scale); column.setPrecision((byte)precision);
buffer.put(col.getType().getValue()); buffer.putShort(col.getColumnNumber()); //Column Number if(col.isVariableLength()) { buffer.putShort(colOffsets.getNextVariableOffset(col)); } else { buffer.putShort(col.getColumnNumber()); //Column Number again if(col.getType().isTextual()) { writeSortOrder(buffer, col.getTextSortOrder(), mutator.getFormat()); } else { if(col.getType().getHasScalePrecision() && !col.isCalculated()) { buffer.put(col.getPrecision()); // numeric precision buffer.put(col.getScale()); // numeric scale } else { buffer.put((byte) 0x00); //unused if(col.isCalculated()) { buffer.put(CALCULATED_EXT_FLAG_MASK); } else if (col.isCompressedUnicode()) { //Compressed buffer.put(COMPRESSED_UNICODE_EXT_FLAG_MASK); } else { if(col.isVariableLength()) { buffer.putShort((short) 0);
if (columnName.equals("")) columnName = "NA"; tb.addColumn(new ColumnBuilder(columnName).setType( DataType.MEMO).toColumn()); hNodeIdList.add(hNode.getId());
ColumnBuilder cb = new ColumnBuilder("Column" + i); switch (matrix.getValueType()) { case DOUBLE: cb.setSQLType(Types.DOUBLE); break; case INT: cb.setSQLType(Types.INTEGER); break; default: cb.setSQLType(Types.VARCHAR); break; tb.addColumn(cb.toColumn());
columns.add(new ColumnBuilder((String)columnNames[i], DataType.TEXT) .escapeName() .setLength((short)DataType.TEXT.getMaxSize()) .toColumn());
boolean isVarCol = column.isVariableLength(); boolean isLongVal = column.getType().isLongValue(); int nameByteLen = DBMutator.calculateNameLength(column.getName()); mutator.addTdefLen(nameByteLen); if(column.isVariableLength()) { writeName(tableBuffer, column.getName(), mutator.getCharset()); column.getName(), _columns.size()); newCol.setColumnIndex(_columns.size()); Map<String,PropertyMap.Property> colProps = column.getProperties(); if(colProps != null) { newCol.getProperties().putAll(colProps.values());
col.setColumnNumber(columnNumber++); if(col.getType().isLongValue()) { _lvalCols.add(col); Map<String,PropertyMap.Property> colProps = cb.getProperties(); if(colProps != null) { newTable.getColumn(cb.getName()).getProperties() .putAll(colProps.values()); addedProps = true;
private void setColumnSortOrder(ColumnBuilder column) { // set the sort order to the db default (if unspecified) if(column.getType().isTextual() && (column.getTextSortOrder() == null)) { column.setTextSortOrder(getDbSortOrder()); } }
private String withErrorContext(String msg) { return msg + "(Column=" + getName() + ")"; } }
protected void validateAutoNumberColumn(Set<DataType> autoTypes, ColumnBuilder column) { if(!column.getType().isMultipleAutoNumberAllowed() && !autoTypes.add(column.getType())) { throw new IllegalArgumentException(withErrorContext( "Can have at most one AutoNumber column of type " + column.getType() + " per table")); } }
public boolean isVariableLength() { // calculated columns are written as var len return(getType().isVariableLength() || isCalculated()); }