001 package railo.runtime.sql.exp; 002 003 import railo.runtime.exp.PageException; 004 import railo.runtime.type.Query; 005 import railo.runtime.type.QueryColumn; 006 007 008 public class ColumnExpression extends ExpressionSupport implements Column { 009 010 private String table; 011 private String column; 012 private boolean hasBracked; 013 private int columnIndex; 014 private QueryColumn col; 015 016 public ColumnExpression(String value, int columnIndex) { 017 this.column=value; 018 this.columnIndex=columnIndex; 019 } 020 021 public void setSub(String sub) { 022 if(table==null) { 023 table=column; 024 column=sub; 025 } 026 else column=(column+"."+sub); 027 } 028 029 public String toString(boolean noAlias) { 030 if(hasAlias() && !noAlias) return getFullName()+" as "+getAlias(); 031 return getFullName(); 032 } 033 034 /** 035 * 036 * @see sql.exp.Column#getFullName() 037 */ 038 public String getFullName() { 039 if(table==null) return column; 040 return table+"."+column; 041 } 042 043 /** 044 * 045 * @see railo.runtime.sql.exp.ExpressionSupport#getAlias() 046 */ 047 public String getAlias() { 048 if(!hasAlias()) return getColumn(); 049 return super.getAlias(); 050 } 051 052 public String getColumn() { 053 return column; 054 } 055 056 public String getTable() { 057 return table; 058 } 059 060 public boolean hasBracked() { 061 return hasBracked; 062 } 063 064 public void hasBracked(boolean b) { 065 this.hasBracked=b; 066 } 067 068 /** 069 * @return the columnIndex 070 */ 071 public int getColumnIndex() { 072 return columnIndex; 073 } 074 075 public Object getValue(Query qr, int row) throws PageException { 076 if(col==null)col = qr.getColumn(getColumn()); 077 return col.get(row); 078 } 079 080 public Object getValue(Query qr, int row, Object defaultValue) { 081 if(col==null){ 082 col = qr.getColumn(getColumn(),null); 083 if(col==null) return defaultValue; 084 } 085 return col.get(row,defaultValue); 086 } 087 088 }