001    package railo.runtime.sql.old;
002    
003    import java.util.Enumeration;
004    import java.util.Hashtable;
005    import java.util.Vector;
006    
007    public final class ZUpdate implements ZStatement        {
008    
009        public ZUpdate(String s)
010        {
011            where_ = null;
012            columns_ = null;
013            table_ = new String(s);
014        }
015    
016        public String getTable()
017        {
018            return table_;
019        }
020    
021        public void addSet(Hashtable hashtable)
022        {
023            set_ = hashtable;
024        }
025    
026        public Hashtable getSet()
027        {
028            return set_;
029        }
030    
031        public void addColumnUpdate(String s, ZExp zexp)
032        {
033            if(set_ == null)
034                set_ = new Hashtable();
035            set_.put(s, zexp);
036            if(columns_ == null)
037                columns_ = new Vector();
038            columns_.addElement(s);
039        }
040    
041        public ZExp getColumnUpdate(String s)
042        {
043            return (ZExp)set_.get(s);
044        }
045    
046        public ZExp getColumnUpdate(int i)
047        {
048            if(--i < 0)
049                return null;
050            if(columns_ == null || i >= columns_.size())
051            {
052                return null;
053            }
054            String s = (String)columns_.elementAt(i);
055            return (ZExp)set_.get(s);
056            
057        }
058    
059        public String getColumnUpdateName(int i)
060        {
061            if(--i < 0)
062                return null;
063            if(columns_ == null || i >= columns_.size())
064                return null;
065            return (String)columns_.elementAt(i);
066        }
067    
068        public int getColumnUpdateCount()
069        {
070            if(set_ == null)
071                return 0;
072            return set_.size();
073        }
074    
075        public void addWhere(ZExp zexp)
076        {
077            where_ = zexp;
078        }
079    
080        public ZExp getWhere()
081        {
082            return where_;
083        }
084    
085        public String toString()
086        {
087            StringBuffer stringbuffer = new StringBuffer("update " + table_);
088            stringbuffer.append(" set ");
089            Enumeration enumeration;
090            if(columns_ != null)
091                enumeration = columns_.elements();
092            else
093                enumeration = set_.keys();
094            for(boolean flag = true; enumeration.hasMoreElements(); flag = false)
095            {
096                String s = enumeration.nextElement().toString();
097                if(!flag)
098                    stringbuffer.append(", ");
099                stringbuffer.append(s + "=" + set_.get(s).toString());
100            }
101    
102            if(where_ != null)
103                stringbuffer.append(" where " + where_.toString());
104            return stringbuffer.toString();
105        }
106    
107        String table_;
108        Hashtable set_;
109        ZExp where_;
110        Vector columns_;
111    }