KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > interpret > AlterTableAction


1 /**
2  * com.mckoi.database.interpret.AlterTableAction 09 Sep 2001
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program 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 Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database.interpret;
26
27 import java.util.ArrayList JavaDoc;
28 import com.mckoi.database.*;
29
30 /**
31  * Represents an action in an ALTER TABLE SQL statement.
32  *
33  * @author Tobias Downer
34  */

35
36 public final class AlterTableAction
37             implements java.io.Serializable JavaDoc, StatementTreeObject, Cloneable JavaDoc {
38
39   static final long serialVersionUID = -3180332341627416727L;
40
41   /**
42    * Element parameters to do with the action.
43    */

44   private ArrayList JavaDoc elements;
45
46   /**
47    * The action to perform.
48    */

49   private String JavaDoc action;
50
51   /**
52    * Constructor.
53    */

54   public AlterTableAction() {
55     elements = new ArrayList JavaDoc();
56   }
57
58   /**
59    * Set the action to perform.
60    */

61   public void setAction(String JavaDoc str) {
62     this.action = str;
63   }
64
65   /**
66    * Adds a parameter to this action.
67    */

68   public void addElement(Object JavaDoc ob) {
69     elements.add(ob);
70   }
71
72   /**
73    * Returns the name of this action.
74    */

75   public String JavaDoc getAction() {
76     return action;
77   }
78
79   /**
80    * Returns the ArrayList that represents the parameters of this action.
81    */

82   public ArrayList JavaDoc getElements() {
83     return elements;
84   }
85
86   /**
87    * Returns element 'n'.
88    */

89   public Object JavaDoc getElement(int n) {
90     return elements.get(n);
91   }
92
93   // Implemented from StatementTreeObject
94
public void prepareExpressions(ExpressionPreparer preparer)
95                                                   throws DatabaseException {
96     // This must search throw 'elements' for objects that we can prepare
97
for (int i = 0; i < elements.size(); ++i) {
98       Object JavaDoc ob = elements.get(i);
99       if (ob instanceof String JavaDoc) {
100         // Do not need to prepare this
101
}
102       else if (ob instanceof Expression) {
103         ((Expression) ob).prepare(preparer);
104       }
105       else if (ob instanceof StatementTreeObject) {
106         ((StatementTreeObject) ob).prepareExpressions(preparer);
107       }
108       else {
109         throw new DatabaseException(
110                                 "Unrecognised expression: " + ob.getClass());
111       }
112     }
113   }
114
115   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
116     // Shallow clone
117
AlterTableAction v = (AlterTableAction) super.clone();
118     ArrayList JavaDoc cloned_elements = new ArrayList JavaDoc();
119     v.elements = cloned_elements;
120
121     for (int i = 0; i < elements.size(); ++i) {
122       Object JavaDoc ob = elements.get(i);
123       if (ob instanceof String JavaDoc) {
124         // Do not need to clone this
125
}
126       else if (ob instanceof Expression) {
127         ob = ((Expression) ob).clone();
128       }
129       else if (ob instanceof StatementTreeObject) {
130         ob = ((StatementTreeObject) ob).clone();
131       }
132       else {
133         throw new CloneNotSupportedException JavaDoc(ob.getClass().toString());
134       }
135       cloned_elements.add(ob);
136     }
137
138     return v;
139   }
140
141 }
142
Popular Tags