View Javadoc

1   /*
2   Copyright (c) 2008 Health Market Science, Inc.
3   
4   This library is free software; you can redistribute it and/or
5   modify it under the terms of the GNU Lesser General Public
6   License as published by the Free Software Foundation; either
7   version 2.1 of the License, or (at your option) any later version.
8   
9   This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  Lesser General Public License for more details.
13  
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
17  USA
18  
19  You can contact Health Market Science at info@healthmarketscience.com
20  or at the following address:
21  
22  Health Market Science
23  2700 Horizon Drive
24  Suite 200
25  King of Prussia, PA 19406
26  */
27  
28  package com.healthmarketscience.jackcess;
29  
30  import java.io.IOException;
31  import java.util.ArrayList;
32  import java.util.List;
33  
34  /**
35   * Builder style class for constructing a Column.
36   *
37   * @author James Ahlborn
38   */
39  public class TableBuilder {
40  
41    /** name of the new table */
42    private String _name;
43    /** columns for the new table */
44    private List<Column> _columns = new ArrayList<Column>();
45    
46    public TableBuilder(String name) {
47      _name = name;
48    }
49  
50    /**
51     * Adds a Column to the new table.
52     */
53    public TableBuilder addColumn(Column column) {
54      _columns.add(column);
55      return this;
56    }
57  
58    /**
59     * Creates a new Table in the given Database with the currently configured
60     * attributes.
61     */
62    public Table toTable(Database db)
63      throws IOException
64    {
65      db.createTable(_name, _columns);
66      return db.getTable(_name);
67    }
68    
69  }