本文整理汇总了Java中com.healthmarketscience.jackcess.ColumnBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ColumnBuilder类的具体用法?Java ColumnBuilder怎么用?Java ColumnBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ColumnBuilder类属于com.healthmarketscience.jackcess包,在下文中一共展示了ColumnBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUniqueTable
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
/**
* Returns a new table with a unique name and the given table definition.
*/
private static Table createUniqueTable(Database db, String name,
List<ColumnBuilder> columns,
ResultSetMetaData md,
ImportFilter filter)
throws IOException, SQLException
{
// otherwise, find unique name and create new table
String baseName = name;
int counter = 2;
while(db.getTable(name) != null) {
name = baseName + (counter++);
}
return new TableBuilder(name)
.addColumns(filter.filterColumns(columns, md))
.toTable(db);
}
示例2: getColumnBitFlags
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
/**
* 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;
}
示例3: validateColumn
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
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);
}
示例4: addColumn
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
public ColumnImpl addColumn(ColumnBuilder column) throws IOException {
_column = column;
validateAddColumn();
// assign column number and do some assorted column bookkeeping
short columnNumber = (short)_table.getMaxColumnCount();
_column.setColumnNumber(columnNumber);
if(_column.getType().isLongValue()) {
_colState = new ColumnState();
}
getPageChannel().startExclusiveWrite();
try {
return _table.mutateAddColumn(this);
} finally {
getPageChannel().finishWrite();
}
}
示例5: x_testCreateIsoFile
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
public void x_testCreateIsoFile() throws Exception
{
Database db = create(Database.FileFormat.V2000, true);
Table t = new TableBuilder("test")
.addColumn(new ColumnBuilder("row", DataType.TEXT))
.addColumn(new ColumnBuilder("data", DataType.TEXT))
.toTable(db);
for(int i = 0; i < 256; ++i) {
String str = "AA" + ((char)i) + "AA";
t.addRow("row" + i, str);
}
db.close();
}
示例6: testLongValueAsMiddleColumn
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
public void testLongValueAsMiddleColumn() throws Exception
{
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = createMem(fileFormat);
Table newTable = new TableBuilder("NewTable")
.addColumn(new ColumnBuilder("a").setSQLType(Types.INTEGER))
.addColumn(new ColumnBuilder("b").setSQLType(Types.LONGVARCHAR))
.addColumn(new ColumnBuilder("c").setSQLType(Types.VARCHAR))
.toTable(db);
String lval = createString(2000); // "--2000 chars long text--";
String tval = createString(40); // "--40chars long text--";
newTable.addRow(new Integer(1), lval, tval);
newTable = db.getTable("NewTable");
Map<String, Object> readRow = newTable.getNextRow();
assertEquals(new Integer(1), readRow.get("a"));
assertEquals(lval, readRow.get("b"));
assertEquals(tval, readRow.get("c"));
db.close();
}
}
示例7: testAutoNumber
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
public void testAutoNumber() throws Exception
{
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = createMem(fileFormat);
Table table = new TableBuilder("test")
.addColumn(new ColumnBuilder("a", DataType.LONG)
.setAutoNumber(true))
.addColumn(new ColumnBuilder("b", DataType.TEXT))
.toTable(db);
doTestAutoNumber(table);
db.close();
}
}
示例8: testInsertLongAutoNumber
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
public void testInsertLongAutoNumber() throws Exception
{
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = createMem(fileFormat);
Table table = new TableBuilder("test")
.addColumn(new ColumnBuilder("a", DataType.LONG)
.setAutoNumber(true))
.addColumn(new ColumnBuilder("b", DataType.TEXT))
.toTable(db);
doTestInsertLongAutoNumber(table);
db.close();
}
}
示例9: testInsertLongAutoNumberPK
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
public void testInsertLongAutoNumberPK() throws Exception
{
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = createMem(fileFormat);
Table table = new TableBuilder("test")
.addColumn(new ColumnBuilder("a", DataType.LONG)
.setAutoNumber(true))
.addColumn(new ColumnBuilder("b", DataType.TEXT))
.setPrimaryKey("a")
.toTable(db);
doTestInsertLongAutoNumber(table);
db.close();
}
}
示例10: JackcessDenseObjectMatrix2D
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
public JackcessDenseObjectMatrix2D(File file, String tablename, Matrix matrix)
throws IOException {
super(matrix.getRowCount(), matrix.getColumnCount());
try {
database = DatabaseBuilder.create(FileFormat.V2010, file);
TableBuilder tb = new TableBuilder(tablename);
for (int i = 0; i < matrix.getColumnCount(); i++) {
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());
}
table = tb.toTable(database);
for (int r = 0; r < matrix.getRowCount(); r++) {
Object[] data = new Object[(int) matrix.getColumnCount()];
for (int c = 0; c < matrix.getColumnCount(); c++) {
data[c] = matrix.getAsObject(r, c);
}
table.addRow(data);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例11: toColumns
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
/**
* Returns a List of Column instances converted from the given
* ResultSetMetaData (this is the same method used by the various {@code
* importResultSet()} methods).
*
* @return a List of Columns
*/
public static List<ColumnBuilder> toColumns(ResultSetMetaData md)
throws SQLException
{
List<ColumnBuilder> columns = new LinkedList<ColumnBuilder>();
for (int i = 1; i <= md.getColumnCount(); i++) {
ColumnBuilder column = new ColumnBuilder(md.getColumnName(i))
.escapeName();
int lengthInUnits = md.getColumnDisplaySize(i);
column.setSQLType(md.getColumnType(i), lengthInUnits);
DataType type = column.getType();
// we check for isTrueVariableLength here to avoid setting the length
// for a NUMERIC column, which pretends to be var-len, even though it
// isn't
if(type.isTrueVariableLength() && !type.isLongValue()) {
column.setLengthInUnits((short)lengthInUnits);
}
if(type.getHasScalePrecision()) {
int scale = md.getScale(i);
int precision = md.getPrecision(i);
if(type.isValidScale(scale)) {
column.setScale((byte)scale);
}
if(type.isValidPrecision(precision)) {
column.setPrecision((byte)precision);
}
}
columns.add(column);
}
return columns;
}
示例12: importResultSet
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
/**
* Copy an existing JDBC ResultSet into a new (or optionally existing) table
* in this database.
*
* @param name Name of the new table to create
* @param source ResultSet to copy from
* @param filter valid import filter
* @param useExistingTable if {@code true} use current table if it already
* exists, otherwise, create new table with unique
* name
*
* @return the name of the imported table
*
* @see Builder
*/
public static String importResultSet(ResultSet source, Database db,
String name, ImportFilter filter,
boolean useExistingTable)
throws SQLException, IOException
{
ResultSetMetaData md = source.getMetaData();
name = TableBuilder.escapeIdentifier(name);
Table table = null;
if(!useExistingTable || ((table = db.getTable(name)) == null)) {
List<ColumnBuilder> columns = toColumns(md);
table = createUniqueTable(db, name, columns, md, filter);
}
List<Object[]> rows = new ArrayList<Object[]>(COPY_TABLE_BATCH_SIZE);
int numColumns = md.getColumnCount();
while (source.next()) {
Object[] row = new Object[numColumns];
for (int i = 0; i < row.length; i++) {
row[i] = source.getObject(i + 1);
}
row = filter.filterRow(row);
if(row == null) {
continue;
}
rows.add(row);
if (rows.size() == COPY_TABLE_BATCH_SIZE) {
table.addRows(rows);
rows.clear();
}
}
if (rows.size() > 0) {
table.addRows(rows);
}
return table.getName();
}
示例13: countVariableLength
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
/**
* @param columns A list of columns in a table definition
* @return The number of variable length columns found in the list
* @usage _advanced_method_
*/
public static short countVariableLength(List<ColumnBuilder> columns) {
short rtn = 0;
for (ColumnBuilder col : columns) {
if (col.isVariableLength()) {
rtn++;
}
}
return rtn;
}
示例14: writeColUsageMapDefinitions
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
protected static void writeColUsageMapDefinitions(
TableCreator creator, ByteBuffer buffer)
throws IOException
{
// write long value column usage map references
for(ColumnBuilder lvalCol : creator.getLongValueColumns()) {
writeColUsageMapDefinition(creator, lvalCol, buffer);
}
}
示例15: writeColUsageMapDefinition
import com.healthmarketscience.jackcess.ColumnBuilder; //导入依赖的package包/类
protected static void writeColUsageMapDefinition(
TableMutator creator, ColumnBuilder lvalCol, ByteBuffer buffer)
throws IOException
{
TableMutator.ColumnState colState = creator.getColumnState(lvalCol);
buffer.putShort(lvalCol.getColumnNumber());
// owned pages umap (both are on same page)
buffer.put(colState.getUmapOwnedRowNumber());
ByteUtil.put3ByteInt(buffer, colState.getUmapPageNumber());
// free space pages umap
buffer.put(colState.getUmapFreeRowNumber());
ByteUtil.put3ByteInt(buffer, colState.getUmapPageNumber());
}