1 2 12 package com.versant.core.jdbc.metadata; 13 14 import com.versant.core.jdbc.sql.JdbcNameGenerator; 15 import com.versant.core.jdbc.sql.SqlDriver; 16 import com.versant.core.jdbc.sql.exp.ColumnExp; 17 import com.versant.core.jdbc.sql.exp.SelectExp; 18 import com.versant.core.jdbc.JdbcUtils; 19 import com.versant.core.jdbc.JdbcConverter; 20 import com.versant.core.util.CharBuf; 21 import com.versant.core.common.State; 22 23 import java.util.ArrayList ; 24 import java.sql.PreparedStatement ; 25 import java.sql.SQLException ; 26 27 import com.versant.core.common.BindingSupportImpl; 28 29 33 public class JdbcSimpleField extends JdbcField { 34 35 38 public JdbcColumn col; 39 40 private boolean oracleStyleLOB; 41 private String oracleStyleLOBNotNullString; 42 43 46 public void setMainTable(JdbcTable table) { 47 super.setMainTable(table); 48 col.setTable(table); 49 } 50 51 54 public void nameColumns(String tableName, JdbcNameGenerator nameGen) { 55 if (col.name == null) { 56 col.name = nameGen.generateFieldColumnName(tableName, fmd.name, false); 57 } else if (!nameGen.isColumnInTable(tableName, col.name)) { 58 try { 59 nameGen.addColumnName(tableName, col.name); 60 } catch (IllegalArgumentException e) { 61 throw BindingSupportImpl.getInstance().runtime( 62 "Invalid jdbc-column-name for field " + fmd.name + ": " + 63 e.getMessage() + "\n" + getContext()); 64 } 65 } 66 } 67 68 71 public void initMainTableCols() { 72 mainTableCols = new JdbcColumn[]{col}; 73 JdbcConverter converter = col.converter; 74 if (converter != null) { 75 oracleStyleLOB = converter.isOracleStyleLOB(); 76 oracleStyleLOBNotNullString = converter.getOracleStyleLOBNotNullString(); 77 } else { 78 oracleStyleLOB = false; 79 } 80 super.initMainTableCols(); 81 } 82 83 86 public void addMainTableCols(ArrayList a) { 87 a.add(col); 88 } 89 90 93 public boolean appendUpdate(CharBuf s, State state) { 94 s.append(col.name); 95 s.append('='); 96 if (oracleStyleLOB) { 97 if (state.isNull(stateFieldNo)) { 98 s.append("null"); 99 } else { 100 s.append(oracleStyleLOBNotNullString); 101 } 102 return true; 103 } else { 104 s.append('?'); 105 return false; 106 } 107 } 108 109 113 public void appendWhere(CharBuf s, SqlDriver sqlDriver) { 114 s.append(col.name); 115 s.append("="); 116 sqlDriver.appendWhereParam(s, col); 117 } 118 119 124 public void appendWhereIsNull(CharBuf s, SqlDriver sqlDriver) { 125 s.append(col.name); 126 s.append(" is null"); 127 } 128 129 132 public void appendInsertColumnList(CharBuf s) { 133 s.append(col.name); 134 } 135 136 141 public boolean appendInsertValueList(CharBuf s, State state) { 142 if (oracleStyleLOB) { 143 if (state.isNull(stateFieldNo)) s.append("null"); 144 else s.append(oracleStyleLOBNotNullString); 145 return true; 146 } else { 147 s.append('?'); 148 return false; 149 } 150 } 151 152 156 public ColumnExp toColumnExp(SelectExp se, boolean joinToSuper) { 157 if (joinToSuper) return new ColumnExp(col, SelectExp.createJoinToSuperTable(se, this), this); 158 else return new ColumnExp(col, se, this); 159 } 160 161 public ColumnExp createOwningTableColumnExpList(SelectExp se) { 162 return new ColumnExp(col, se, this); 163 } 164 165 170 public int setQueryParam(PreparedStatement ps, int firstParam, Object value) 171 throws SQLException { 172 if (col.converter != null) { 173 col.converter.set(ps, firstParam++, col, value); 174 } else { 175 JdbcUtils.set(ps, firstParam++, value, col.javaTypeCode, col.jdbcType); 176 } 177 return firstParam; 178 } 179 180 183 public boolean isOracleStyleLOB() { 184 return oracleStyleLOB; 185 } 186 187 } 188 189 190 | Popular Tags |