当前位置: 首页>>代码示例>>Java>>正文


Java TableBuilder类代码示例

本文整理汇总了Java中com.healthmarketscience.jackcess.TableBuilder的典型用法代码示例。如果您正苦于以下问题:Java TableBuilder类的具体用法?Java TableBuilder怎么用?Java TableBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TableBuilder类属于com.healthmarketscience.jackcess包,在下文中一共展示了TableBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createUniqueTable

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的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);
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:21,代码来源:ImportUtil.java

示例2: x_testCreateIsoFile

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的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();
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:17,代码来源:IndexCodesTest.java

示例3: testLongValueAsMiddleColumn

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的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();
  }
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:24,代码来源:LongValueTest.java

示例4: testAutoNumber

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的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();
  }
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:17,代码来源:AutoNumberTest.java

示例5: testInsertLongAutoNumber

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的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();
  }    
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:17,代码来源:AutoNumberTest.java

示例6: testInsertLongAutoNumberPK

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的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();
  }    
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:18,代码来源:AutoNumberTest.java

示例7: JackcessDenseObjectMatrix2D

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的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);
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:38,代码来源:JackcessDenseObjectMatrix2D.java

示例8: importResultSet

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的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();
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:54,代码来源:ImportUtil.java

示例9: createTable

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的package包/类
/**
 * Create a new table in this database
 * @param name Name of the table to create
 * @param columns List of Columns in the table
 * @param indexes List of IndexBuilders describing indexes for the table
 * @deprecated use {@link TableBuilder} instead
 */
@Deprecated
public void createTable(String name, List<ColumnBuilder> columns,
                        List<IndexBuilder> indexes)
  throws IOException
{
  new TableBuilder(name)
    .addColumns(columns)
    .addIndexes(indexes)
    .toTable(this);
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:18,代码来源:DatabaseImpl.java

示例10: testGobalReferenceUsageMap

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的package包/类
public void testGobalReferenceUsageMap() throws Exception
{
  Database db = openCopy(
      Database.FileFormat.V2000, 
      new File("src/test/data/V2000/testRefGlobalV2000.mdb"));

  Table t = new TableBuilder("Test2")
    .addColumn(new ColumnBuilder("id", DataType.LONG))
    .addColumn(new ColumnBuilder("data1", DataType.TEXT))
    .addColumn(new ColumnBuilder("data2", DataType.TEXT))
    .toTable(db);


  ((DatabaseImpl)db).getPageChannel().startWrite();
  try {
    List<Object[]> rows = new ArrayList<Object[]>();
    for(int i = 0; i < 300000; ++i) {
      String s1 = "r" + i + "-" + createString(100);
      String s2 = "r" + i + "-" + createString(200);

      rows.add(new Object[]{i, s1, s2});

      if((i % 2000) == 0) {
        t.addRows(rows);
        rows.clear();
      }
    }
  } finally {
    ((DatabaseImpl)db).getPageChannel().finishWrite();
  }

  db.close();
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:34,代码来源:UsageMapTest.java

示例11: doTestCodecHandler

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的package包/类
private static void doTestCodecHandler(boolean simple) throws Exception
{
  for(Database.FileFormat ff : SUPPORTED_FILEFORMATS) {
    Database db = TestUtil.create(ff);
    int pageSize = ((DatabaseImpl)db).getFormat().PAGE_SIZE;
    File dbFile = db.getFile();
    db.close();

    // apply encoding to file
    encodeFile(dbFile, pageSize, simple);

    db = new DatabaseBuilder(dbFile)
      .setCodecProvider(simple ? SIMPLE_PROVIDER : FULL_PROVIDER)
      .open();

    Table t1 = new TableBuilder("test1")
      .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true))
      .addColumn(new ColumnBuilder("data", DataType.TEXT).setLength(250))
      .setPrimaryKey("id")
      .addIndex(new IndexBuilder("data_idx").addColumns("data"))
      .toTable(db);

    Table t2 = new TableBuilder("test2")
      .addColumn(new ColumnBuilder("id", DataType.LONG).setAutoNumber(true))
      .addColumn(new ColumnBuilder("data", DataType.TEXT).setLength(250))
      .setPrimaryKey("id")
      .addIndex(new IndexBuilder("data_idx").addColumns("data"))
      .toTable(db);

    int autonum = 1;
    for(int i = 1; i < 2; ++i) {
      writeData(t1, t2, autonum, autonum + 100);
      autonum += 100;
    }

    db.close();
  }
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:39,代码来源:CodecHandlerTest.java

示例12: testAutoNumberGuid

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的package包/类
public void testAutoNumberGuid() throws Exception 
{
  for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
    Database db = createMem(fileFormat);

    Table table = new TableBuilder("test")
      .addColumn(new ColumnBuilder("a", DataType.GUID)
                .setAutoNumber(true))
      .addColumn(new ColumnBuilder("b", DataType.TEXT))
      .toTable(db);

    Object[] row = {null, "row1"};
    assertSame(row, table.addRow(row));
    assertTrue(ColumnImpl.isGUIDValue(row[0]));
    row = table.addRow(13, "row2");
    assertTrue(ColumnImpl.isGUIDValue(row[0]));
    row = table.addRow("flubber", "row3");
    assertTrue(ColumnImpl.isGUIDValue(row[0]));

    Object[] smallRow = {Column.AUTO_NUMBER};
    row = table.addRow(smallRow);
    assertNotSame(row, smallRow);
    assertTrue(ColumnImpl.isGUIDValue(row[0]));

    db.close();
  }
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:28,代码来源:AutoNumberTest.java

示例13: basicEscapingIdentifier

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的package包/类
public static String basicEscapingIdentifier(String name) {
	if (name.startsWith("~"))
		return null;
	String nl = name.toUpperCase();
	if (TableBuilder.isReservedWord(nl) 
			) {
		xescapedIdentifiers.add(nl);
	}
	if(nl.startsWith("X")&&TableBuilder.isReservedWord(nl.substring(1))){
		alreadyEscapedIdentifiers.add(nl.substring(1));
	}
    String escaped = name
					.replaceAll("[/\\\\$%^:-]", "_").replaceAll("~", "M_")
							.replaceAll("\\.", "_").replaceAll("\'", "").replaceAll("#", "_")
			.replaceAll("\"", "").replaceAll("\\+", "").replaceAll("\\(", "_").replaceAll("\\)", "_");
	
	escaped=replaceNoRomanCharacters(escaped);
	
	if (KEYWORDLIST.contains(escaped.toUpperCase())) {
		escaped = "\"" + escaped + "\"";
	}
	if (Character.isDigit(escaped.trim().charAt(0))) {
		escaped = "Z_" + escaped.trim();
	}
	if (escaped.charAt(0) == '_') {
		escaped = "Z" + escaped;
	}
	return escaped.toUpperCase();
}
 
开发者ID:andrew-nguyen,项目名称:ucanaccess,代码行数:30,代码来源:SQLConverter.java

示例14: createTable

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的package包/类
public void createTable(String tableName, String[] types, String[] defaults, Boolean[] notNulls)
		throws IOException, SQLException {
	UcanaccessConnection conn = UcanaccessConnection.getCtxConnection();
	Database db = conn.getDbIO();
	TableBuilder tb=new TableBuilder(tableName);
	tb.addColumns(getColumns(tableName, types));
	List<IndexBuilder> arcl=getIndexBuilders(tableName);
	for(IndexBuilder ixb:arcl){
		tb.addIndex(ixb);
	}
	IndexBuilder ibpk = getIndexBuilderPK(tableName);
	
	checkPK(arcl, ibpk);
	if (ibpk != null)
		arcl.add(ibpk);
	
	Table table = tb.toTable(db);
	saveColumnsDefaults(defaults,notNulls, table);
    LoadJet lj=new LoadJet(conn.getHSQLDBConnection(),db);
	lj.loadDefaultValues(table);
	Statement st = null;
	try {
		st = conn.createStatement();
		ResultSet rs = st.executeQuery("SELECT * FROM " + tableName);
		List<String> clns = this.getColumnNames(tableName);
		while (rs.next()) {
			Object[] record = new Object[clns.size()];
			int i = 0;
			for (String columnName : clns) {
				record[i++] = rs.getObject(columnName);
			}
			new InsertCommand(table, record, null).persist();
		}
	} finally {
		if (st != null) {
			st.close();
		}
	}
}
 
开发者ID:andrew-nguyen,项目名称:ucanaccess,代码行数:40,代码来源:Persist2Jet.java

示例15: createTable

import com.healthmarketscience.jackcess.TableBuilder; //导入依赖的package包/类
/**
 * Creates the table in the database.
 * @usage _advanced_method_
 */
public TableImpl createTable(TableBuilder table) throws IOException {

  _name = table.getName();
  _columns = table.getColumns();
  _indexes = table.getIndexes();
  if(_indexes == null) {
    _indexes = Collections.<IndexBuilder>emptyList();
  }

  validate();

  // assign column numbers and do some assorted column bookkeeping
  short columnNumber = (short) 0;
  for(ColumnBuilder col : _columns) {
    col.setColumnNumber(columnNumber++);
    if(col.getType().isLongValue()) {
      _lvalCols.add(col);
      // only lval columns need extra state
      _columnStates.put(col, new ColumnState());
    }
  }

  if(hasIndexes()) {
    // sort out index numbers (and backing index data).  
    for(IndexBuilder idx : _indexes) {
      idx.setIndexNumber(_logicalIndexCount++);
      findIndexDataState(idx);
    }
  }

  getPageChannel().startExclusiveWrite();
  try {
    
    // reserve some pages
    _tdefPageNumber = reservePageNumber();
    _umapPageNumber = reservePageNumber();
  
    //Write the tdef page to disk.
    TableImpl.writeTableDefinition(this);

    // update the database with the new table info
    getDatabase().addNewTable(_name, _tdefPageNumber, DatabaseImpl.TYPE_TABLE, 
                              null, null);

    TableImpl newTable = getDatabase().getTable(_name);

    // add any table properties
    boolean addedProps = false;
    Map<String,PropertyMap.Property> props = table.getProperties();
    if(props != null) {
      newTable.getProperties().putAll(props.values());
      addedProps = true;
    }
    for(ColumnBuilder cb : _columns) {
      Map<String,PropertyMap.Property> colProps = cb.getProperties();
      if(colProps != null) {
        newTable.getColumn(cb.getName()).getProperties()
          .putAll(colProps.values());
        addedProps = true;
      }
    }

    // all table and column props are saved together
    if(addedProps) {
      newTable.getProperties().save();
    }

    return newTable;

  } finally {
    getPageChannel().finishWrite();
  }
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:78,代码来源:TableCreator.java


注:本文中的com.healthmarketscience.jackcess.TableBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。