View Javadoc

1   /*
2   
3   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by the
7   Free Software Foundation; either version 2 of the License, or (at your
8   option) any later version.
9   
10  This program is distributed in the hope that it will
11  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc., 59
17  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 }