1 2 12 package com.versant.core.jdbc.sql.exp; 13 14 import com.versant.core.jdbc.metadata.JdbcColumn; 15 import com.versant.core.jdbc.metadata.JdbcField; 16 import com.versant.core.jdbc.sql.SqlDriver; 17 import com.versant.core.util.CharBuf; 18 import com.versant.core.metadata.ClassMetaData; 19 import com.versant.core.jdo.query.ParamNode; 20 import com.versant.core.common.Debug; 21 22 import java.util.Map ; 23 24 import com.versant.core.common.BindingSupportImpl; 25 26 import javax.jdo.JDOFatalInternalException; 27 28 31 public class ColumnExp extends LeafExp { 32 33 37 public JdbcColumn col; 38 41 public SelectExp selectExp; 42 45 public JdbcField jdbcField; 46 49 public ClassMetaData cmd; 50 51 private String asValue; 52 53 public ColumnExp(JdbcColumn col, SelectExp selectExp, JdbcField jdbcField) { 54 if (Debug.DEBUG) { 55 if (selectExp == null) { 56 throw BindingSupportImpl.getInstance().internal(""); 57 } 58 if (col.table != selectExp.table) { 59 throw BindingSupportImpl.getInstance().internal("The col for the table is not the same as the select exp"); 60 } 61 } 62 this.col = col; 63 this.selectExp = selectExp; 64 this.jdbcField = jdbcField; 65 } 66 67 public ColumnExp() { 68 } 69 70 public ColumnExp(String asValue) { 71 if (asValue != null && asValue.length() > 0) { 72 this.asValue = asValue; 73 } else { 74 this.asValue = null; 75 } 76 } 77 78 public SqlExp createInstance() { 79 return new ColumnExp(); 80 } 81 82 public SqlExp getClone(SqlExp columnExp, Map cloneMap) { 83 super.getClone(columnExp, cloneMap); 84 ColumnExp cst = (ColumnExp) columnExp; 85 86 cst.col = col; 87 cst.jdbcField = jdbcField; 88 cst.cmd = cmd; 89 if (selectExp != null) cst.selectExp = (SelectExp) createClone(selectExp, cloneMap); 90 91 return columnExp; 92 } 93 94 public ClassMetaData getCmd() { 95 return cmd; 96 } 97 98 public void setCmd(ClassMetaData cmd) { 99 this.cmd = cmd; 100 } 101 102 public String toString() { 103 return super.toString() + " " + col + " " + selectExp; 104 } 105 106 113 public void appendSQLImp(SqlDriver driver, CharBuf s, SqlExp leftSibling) { 114 if (isAliasedColumn() && jdbcField == null) { 115 s.append(" " + asValue + " "); 116 } else { 117 driver.appendSqlColumn(col, selectExp.alias, s); 118 if (isAliasedColumn()) { 119 s.append(driver.getAliasPrepend() + asValue); 120 } 121 } 122 } 123 124 127 public int getJdbcType() { 128 return col.jdbcType; 129 } 130 131 134 public int getJavaTypeCode() { 135 return col.javaTypeCode; 136 } 137 138 142 public int getClassIndex() { 143 if (cmd == null) 144 return -1; 145 else 146 return cmd.index; 147 } 148 149 153 public void replaceSelectExpRef(SelectExp old, SelectExp nw) { 154 if (nw == null) { 155 throw new JDOFatalInternalException(); 156 } 157 if (selectExp == old) { 158 selectExp = nw; 159 } else { 160 SelectExp other = nw.findTableRecursive(selectExp.table, 161 selectExp.jdbcField); 162 if (other != null) selectExp = other; 163 } 164 } 165 166 173 public SelectExp getSingleSelectExp(SelectExp exclude) { 174 return selectExp; 175 } 176 177 180 public int createAlias(int index) { 181 if ( selectExp == null ) 182 return 0; 183 else 184 return selectExp.createAlias(index); 185 } 186 187 public boolean isAliasedColumn() { 188 return asValue != null; 189 } 190 191 public String getAsValue() { 192 return asValue; 193 } 194 195 public void setColAlias(String columnAlias) { 196 if (columnAlias != null && columnAlias.length() > 0) { 197 this.asValue = columnAlias; 198 } else { 199 this.asValue = null; 200 } 201 } 202 } 203 | Popular Tags |