1 28 29 package com.caucho.amber.query; 30 31 import com.caucho.amber.entity.AmberEntityHome; 32 import com.caucho.amber.entity.TableInvalidateCompletion; 33 import com.caucho.amber.expr.AmberExpr; 34 import com.caucho.amber.manager.AmberConnection; 35 import com.caucho.util.CharBuffer; 36 37 import java.sql.SQLException ; 38 39 40 43 public class DeleteQuery extends AbstractQuery { 44 private AmberExpr _where; 45 46 private String _sql; 47 48 DeleteQuery(String query) 49 { 50 super(query); 51 } 52 53 56 void setWhere(AmberExpr expr) 57 { 58 _where = expr; 59 } 60 61 64 public String getSQL() 65 { 66 return _sql; 67 } 68 69 72 void init() 73 { 74 CharBuffer cb = CharBuffer.allocate(); 75 76 cb.append("DELETE FROM "); 77 78 FromItem item = _fromList.get(0); 79 80 cb.append(item.getTable().getName()); 81 82 if (_where != null) { 83 cb.append(" WHERE "); 84 _where.generateUpdateWhere(cb); 85 } 86 87 _sql = cb.close(); 88 } 89 90 93 void registerUpdates(CachedQuery query) 94 { 95 for (int i = 0; i < _fromList.size(); i++) { 96 FromItem item = _fromList.get(i); 97 98 AmberEntityHome home = item.getEntityHome(); 99 100 CacheUpdate update = new TableCacheUpdate(query); 101 102 home.addUpdate(update); 103 } 104 } 105 106 109 public void prepare(UserQuery userQuery, AmberConnection aConn) 110 throws SQLException 111 { 112 aConn.flushNoChecks(); 113 } 114 115 118 public void complete(UserQuery userQuery, AmberConnection aConn) 119 throws SQLException 120 { 121 aConn.expire(); 122 123 FromItem item = _fromList.get(0); 124 125 aConn.addCompletion(new TableInvalidateCompletion(item.getEntityType().getTable().getName())); 126 } 127 128 131 public String toString() 132 { 133 return "DeleteQuery[" + getQueryString() + "]"; 134 } 135 } 136 | Popular Tags |