001: /**
002: * com.mckoi.database.interpret.AlterTableAction 09 Sep 2001
003: *
004: * Mckoi SQL Database ( http://www.mckoi.com/database )
005: * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * Version 2 as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License Version 2 for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * Version 2 along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Change Log:
021: *
022: *
023: */package com.mckoi.database.interpret;
024:
025: import java.util.ArrayList;
026: import com.mckoi.database.*;
027:
028: /**
029: * Represents an action in an ALTER TABLE SQL statement.
030: *
031: * @author Tobias Downer
032: */
033:
034: public final class AlterTableAction implements java.io.Serializable,
035: StatementTreeObject, Cloneable {
036:
037: static final long serialVersionUID = -3180332341627416727L;
038:
039: /**
040: * Element parameters to do with the action.
041: */
042: private ArrayList elements;
043:
044: /**
045: * The action to perform.
046: */
047: private String action;
048:
049: /**
050: * Constructor.
051: */
052: public AlterTableAction() {
053: elements = new ArrayList();
054: }
055:
056: /**
057: * Set the action to perform.
058: */
059: public void setAction(String str) {
060: this .action = str;
061: }
062:
063: /**
064: * Adds a parameter to this action.
065: */
066: public void addElement(Object ob) {
067: elements.add(ob);
068: }
069:
070: /**
071: * Returns the name of this action.
072: */
073: public String getAction() {
074: return action;
075: }
076:
077: /**
078: * Returns the ArrayList that represents the parameters of this action.
079: */
080: public ArrayList getElements() {
081: return elements;
082: }
083:
084: /**
085: * Returns element 'n'.
086: */
087: public Object getElement(int n) {
088: return elements.get(n);
089: }
090:
091: // Implemented from StatementTreeObject
092: public void prepareExpressions(ExpressionPreparer preparer)
093: throws DatabaseException {
094: // This must search throw 'elements' for objects that we can prepare
095: for (int i = 0; i < elements.size(); ++i) {
096: Object ob = elements.get(i);
097: if (ob instanceof String) {
098: // Do not need to prepare this
099: } else if (ob instanceof Expression) {
100: ((Expression) ob).prepare(preparer);
101: } else if (ob instanceof StatementTreeObject) {
102: ((StatementTreeObject) ob).prepareExpressions(preparer);
103: } else {
104: throw new DatabaseException("Unrecognised expression: "
105: + ob.getClass());
106: }
107: }
108: }
109:
110: public Object clone() throws CloneNotSupportedException {
111: // Shallow clone
112: AlterTableAction v = (AlterTableAction) super .clone();
113: ArrayList cloned_elements = new ArrayList();
114: v.elements = cloned_elements;
115:
116: for (int i = 0; i < elements.size(); ++i) {
117: Object ob = elements.get(i);
118: if (ob instanceof String) {
119: // Do not need to clone this
120: } else if (ob instanceof Expression) {
121: ob = ((Expression) ob).clone();
122: } else if (ob instanceof StatementTreeObject) {
123: ob = ((StatementTreeObject) ob).clone();
124: } else {
125: throw new CloneNotSupportedException(ob.getClass()
126: .toString());
127: }
128: cloned_elements.add(ob);
129: }
130:
131: return v;
132: }
133:
134: }
|