01: // Copyright (c) 2008 Health Market Science, Inc.
02:
03: package com.healthmarketscience.jackcess;
04:
05: import java.io.IOException;
06: import java.util.ArrayList;
07: import java.util.List;
08:
09: /**
10: * Builder style class for constructing a Column.
11: *
12: * @author James Ahlborn
13: */
14: public class TableBuilder {
15:
16: /** name of the new table */
17: private String _name;
18: /** columns for the new table */
19: private List<Column> _columns = new ArrayList<Column>();
20:
21: public TableBuilder(String name) {
22: _name = name;
23: }
24:
25: /**
26: * Adds a Column to the new table.
27: */
28: public TableBuilder addColumn(Column column) {
29: _columns.add(column);
30: return this ;
31: }
32:
33: /**
34: * Creates a new Table in the given Database with the currently configured
35: * attributes.
36: */
37: public Table toTable(Database db) throws IOException {
38: db.createTable(_name, _columns);
39: return db.getTable(_name);
40: }
41:
42: }
|