001package gudusoft.gsqlparser.nodes; 002 003import gudusoft.gsqlparser.ESqlClause; 004import gudusoft.gsqlparser.TCustomSqlStatement; 005 006/** 007* The FOR UPDATE clause lets you lock the selected rows so that other users cannot lock 008 * or update the rows until you end your transaction. 009 * This clause only in a top-level SELECT statement, not in subqueries. 010*/ 011public class TForUpdate extends TParseTreeNode { 012 013 public void setWaitNoWait(TDummy dummy){ 014 if (dummy == null) return; 015 if (dummy.st1.toString().equalsIgnoreCase("wait")){ 016 wait = true; 017 waitValue = dummy.st2.toString(); 018 }else if (dummy.st1.toString().equalsIgnoreCase("nowait")){ 019 nowait = true; 020 } 021 022 } 023 private boolean wait = false; 024 private boolean nowait = false; 025 private String waitValue; 026 027 public void setWait(boolean wait) { 028 this.wait = wait; 029 } 030 031 public void setNowait(boolean nowait) { 032 this.nowait = nowait; 033 } 034 035 public void setWaitValue(String waitValue) { 036 this.waitValue = waitValue; 037 } 038 039 public boolean isWait() { 040 return wait; 041 } 042 043 public boolean isNowait() { 044 return nowait; 045 } 046 047 public String getWaitValue() { 048 return waitValue; 049 } 050 051 public enum EForUpdateType {forUpdate,forUpdateOf,forReadOnly}; 052 053 private EForUpdateType forUpdateType = EForUpdateType.forUpdate; 054 055 public void setForUpdateType(EForUpdateType forUpdateType) { 056 this.forUpdateType = forUpdateType; 057 } 058 059 public EForUpdateType getForUpdateType() { 060 061 return forUpdateType; 062 } 063 064 /** 065 * Use the OF ... column clause to lock the select rows only for a particular table or view 066 * in a join. The columns in the OF clause only indicate which table or view rows are 067 * locked. The specific columns that you specify are not significant. However, you must 068 * specify an actual column name, not a column alias. If you omit this clause, then the 069 * database locks the selected rows from all the tables in the query. 070 * @return 071 */ 072 public TObjectNameList getColumnRefs() { 073 return columnRefs; 074 } 075 076 private TObjectNameList columnRefs; 077 078 public void init(Object arg1) 079 { 080 if (arg1 instanceof TDummy){ 081 //mysql 082 TDummy dummy = (TDummy)arg1; 083 if (dummy.st1.toString().equalsIgnoreCase("nowait")){ 084 this.nowait = true; 085 }else if (dummy.st1.toString().equalsIgnoreCase("wait")){ 086 this.wait = true; 087 } 088 }else if (arg1 instanceof TObjectNameList){ 089 columnRefs = (TObjectNameList)arg1; 090 } 091 092 } 093 094 public void doParse(TCustomSqlStatement psql, ESqlClause plocation){ 095 if (columnRefs != null){ 096 columnRefs.doParse(psql,plocation); 097 } 098 } 099 100 public void accept(TParseTreeVisitor v){ 101 v.preVisit(this); 102 v.postVisit(this); 103 } 104 105 public void acceptChildren(TParseTreeVisitor v){ 106 v.preVisit(this); 107 v.postVisit(this); 108 } 109 110 public void setColumnRefs(TObjectNameList columnRefs) { 111 this.columnRefs = columnRefs; 112 } 113}