1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.devaki.nextobjects.workspace.models.objects;
21 import java.io.Serializable;
22 import java.util.Vector;
23 import org.devaki.nextobjects.workspace.models.PhysicalModel;
24 import org.devaki.nextobjects.workspace.models.columns.Column;
25 import org.devaki.nextobjects.workspace.models.graphics.TableView;
26 import org.devaki.nextobjects.workspace.models.graphics.ObjectView;
27 /***
28 * The class Table represent Table as they are in a database
29 * @author eflorent
30 */
31 public class Table extends BaseClass implements Serializable
32 {
33 /***
34 * Linked constraints
35 */
36 private Vector constraints = new Vector(1);
37 /***
38 * The TableView
39 */
40 private TableView tableView;
41 /***
42 * Construct a new 'Table' object by clonig another
43 * @param pObject the table to clone
44 */
45 public Table(final Table pObject)
46 {
47 super(pObject);
48 tableView = new TableView(this);
49 }
50 /***
51 * Construct a new 'Table' object
52 * @param pModel the context model
53 */
54 public Table(final PhysicalModel pModel)
55 {
56 super(pModel);
57 setName(
58 new StringBuffer()
59 .append("table ")
60 .append(pModel.countTable())
61 .toString());
62 setCode(
63 new StringBuffer()
64 .append("table_")
65 .append(pModel.countTable())
66 .toString());
67 tableView = new TableView(this);
68 }
69 /***
70 * Get the foreign keys for this table.
71 * @return foreign keys
72 */
73 public final Vector getForeignKeys()
74 {
75 Vector columns = this.getColumns();
76 Vector fks = new Vector();
77 for (int i = 0; i < columns.size(); i++)
78 {
79 if (((Column) columns.elementAt(i)).isForeignKey())
80 {
81 fks.addElement(columns.elementAt(i));
82 }
83 }
84 return fks;
85 }
86 /***
87 * Get the primary keys
88 * @return the primary keys
89 */
90 public final Vector getPrimaryKeys()
91 {
92 Vector columns = this.getColumns();
93 Vector pks = new Vector();
94 for (int i = 0; i < columns.size(); i++)
95 {
96 if (((Column) columns.elementAt(i)).isPk())
97 {
98 pks.addElement(columns.elementAt(i));
99 }
100 }
101 return pks;
102 }
103 /***
104 * Get the object view
105 * @return tableview
106 */
107 public final ObjectView getObjectView()
108 {
109 return tableView;
110 }
111 /***
112 * Get the constraints of that table
113 * @return the constraints
114 */
115 public final Vector getConstraints()
116 {
117 return constraints;
118 }
119 /***
120 * Set the constraints of that table
121 * @param vector the new constraints
122 */
123 public final void setConstraints(final Vector vector)
124 {
125 constraints = vector;
126 }
127 }