1 19 20 package org.netbeans.lib.ddl.impl; 21 22 import java.text.MessageFormat ; 23 import java.util.Enumeration ; 24 import java.util.Map ; 25 import java.util.Vector ; 26 27 import org.openide.util.NbBundle; 28 import org.netbeans.lib.ddl.CreateTriggerCommand; 29 import org.netbeans.lib.ddl.DDLException; 30 31 36 37 public class CreateTrigger extends AbstractCommand implements CreateTriggerCommand { 38 public static final int BEFORE = 1; 39 public static final int AFTER = 2; 40 41 42 private Vector events; 43 44 45 boolean eachrow; 46 47 48 private String cond; 49 50 51 private String table; 52 53 54 int timing; 55 56 57 private String body; 58 59 public static String getTimingName(int code) 60 { 61 switch (code) { 62 case BEFORE: return "BEFORE"; case AFTER: return "AFTER"; } 65 66 return null; 67 } 68 69 static final long serialVersionUID =-2217362040968396712L; 70 public CreateTrigger() 71 { 72 events = new Vector (); 73 } 74 75 public String getTableName() 76 { 77 return table; 78 } 79 80 public void setTableName(String tab) 81 { 82 table = tab; 83 } 84 85 public boolean getForEachRow() 86 { 87 return eachrow; 88 } 89 90 public void setForEachRow(boolean flag) 91 { 92 eachrow = flag; 93 } 94 95 96 97 public String getText() 98 { 99 return body; 100 } 101 102 103 public void setText(String text) 104 { 105 body = text; 106 } 107 108 public String getCondition() 109 { 110 return cond; 111 } 112 113 public void setCondition(String con) 114 { 115 cond = con; 116 } 117 118 public int getTiming() 119 { 120 return timing; 121 } 122 123 public void setTiming(int time) 124 { 125 timing = time; 126 } 127 128 129 public Vector getEvents() 130 { 131 return events; 132 } 133 134 public TriggerEvent getEvent(int index) 135 { 136 return (TriggerEvent)events.get(index); 137 } 138 139 140 public void setEvents(Vector argarr) 141 { 142 events = argarr; 143 } 144 145 public void setEvent(int index, TriggerEvent arg) 146 { 147 events.set(index, arg); 148 } 149 150 public TriggerEvent createTriggerEvent(int when, String columnname) 151 throws DDLException 152 { 153 try { 154 Map gprops = (Map )getSpecification().getProperties(); 155 Map props = (Map )getSpecification().getCommandProperties(Specification.CREATE_TRIGGER); 156 Map bindmap = (Map )props.get("Binding"); String tname = (String )bindmap.get("EVENT"); if (tname != null) { 159 Map typemap = (Map )gprops.get(tname); 160 if (typemap == null) throw new InstantiationException ( 161 MessageFormat.format( 162 NbBundle.getBundle("org.netbeans.lib.ddl.resources.Bundle").getString("EXC_UnableLocateObject"), new String [] {tname})); 164 Class typeclass = Class.forName((String )typemap.get("Class")); String format = (String )typemap.get("Format"); TriggerEvent evt = (TriggerEvent)typeclass.newInstance(); 167 Map temap = (Map )props.get("TriggerEventMap"); evt.setName(TriggerEvent.getName(when)); 169 evt.setColumn(columnname); 170 evt.setFormat(format); 171 return (TriggerEvent)evt; 172 } else throw new InstantiationException ( 173 MessageFormat.format( 174 NbBundle.getBundle("org.netbeans.lib.ddl.resources.Bundle").getString("EXC_UnableLocateType"), new String [] {"EVENT", bindmap.toString() })); } catch (Exception e) { 177 throw new DDLException(e.getMessage()); 178 } 179 } 180 181 public void addTriggerEvent(int when) 182 throws DDLException 183 { 184 addTriggerEvent(when, null); 185 } 186 187 public void addTriggerEvent(int when, String columnname) 188 throws DDLException 189 { 190 TriggerEvent te = createTriggerEvent(when, columnname); 191 if (te != null) events.add(te); 192 } 193 194 public Map getCommandProperties() throws DDLException { 195 Map props = (Map )getSpecification().getProperties(); 196 String evs = "", argdelim = (String )props.get("TriggerEventListDelimiter"); Map cmdprops = super.getCommandProperties(); 198 199 Enumeration col_e = events.elements(); 200 while (col_e.hasMoreElements()) { 201 TriggerEvent evt = (TriggerEvent)col_e.nextElement(); 202 boolean inscomma = col_e.hasMoreElements(); 203 evs = evs + evt.getCommand(this)+(inscomma ? argdelim : ""); 204 } 205 206 cmdprops.put("trigger.events", evs); cmdprops.put("trigger.condition", cond); cmdprops.put("trigger.timing", getTimingName(timing)); cmdprops.put("table.name", quote(table)); cmdprops.put("trigger.body", body); if (eachrow) 212 cmdprops.put("each.row", ""); 214 return cmdprops; 215 } 216 } 217 | Popular Tags |