01: /*
02: $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/Table.java,v 1.3 2002/11/01 16:58:00 wbiggs Exp $
03:
04: This file is part of XORM.
05:
06: XORM is free software; you can redistribute it and/or modify
07: it under the terms of the GNU General Public License as published by
08: the Free Software Foundation; either version 2 of the License, or
09: (at your option) any later version.
10:
11: XORM is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU General Public License for more details.
15:
16: You should have received a copy of the GNU General Public License
17: along with XORM; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package org.xorm.datastore;
21:
22: import java.util.Iterator;
23: import java.util.ArrayList;
24: import java.util.LinkedHashSet;
25: import java.util.Set;
26: import java.sql.Connection;
27: import java.sql.SQLException;
28:
29: /**
30: * Represents a database table.
31: */
32: public class Table {
33: private String name;
34: private Column primaryKey;
35: private Set columns = new LinkedHashSet();
36: int numColumns = 0; // accessed by Row constructor
37:
38: public Table(String name) {
39: this .name = name;
40: }
41:
42: public Column getPrimaryKey() {
43: return primaryKey;
44: }
45:
46: public void setPrimaryKey(Column primaryKey) {
47: this .primaryKey = primaryKey;
48: }
49:
50: public Set getColumns() {
51: return columns;
52: }
53:
54: /**
55: * Convenience method to find a matching column.
56: */
57: public Column getColumnByName(String name) {
58: Iterator i = columns.iterator();
59: while (i.hasNext()) {
60: Column c = (Column) i.next();
61: if (c.getName().equals(name))
62: return c;
63: }
64: return null;
65: }
66:
67: /**
68: * Adds a Column to the Table. Returns the index of the column
69: * added. The first column added is 0.
70: */
71: public int addColumn(Column column) {
72: columns.add(column);
73: return numColumns++;
74: }
75:
76: public String getName() {
77: return name;
78: }
79:
80: public void setName(String name) {
81: this.name = name;
82: }
83: }
|