1 2 12 package com.versant.core.jdbc.sql; 13 14 import com.versant.core.jdbc.metadata.*; 15 import com.versant.core.jdbc.sql.conv.*; 16 import com.versant.core.jdbc.sql.exp.SqlExp; 17 import com.versant.core.jdbc.sql.exp.UnaryFunctionExp; 18 import com.versant.core.util.CharBuf; 19 20 import java.util.Date ; 21 import java.util.HashMap ; 22 import java.sql.*; 23 24 import com.versant.core.common.BindingSupportImpl; 25 26 29 public class DaffodilSqlDriver extends SqlDriver { 30 31 34 public String getName() { 35 return "daffodil"; 36 } 37 38 45 protected JdbcTypeMapping getTypeMapping(int jdbcType) { 46 switch (jdbcType) { 47 case Types.BIT: 48 return new JdbcTypeMapping("BOOLEAN", 0, 0, JdbcTypeMapping.TRUE, 49 JdbcTypeMapping.TRUE, null); 50 case Types.TINYINT: 51 return new JdbcTypeMapping("TINYINT", 52 0, 0, JdbcTypeMapping.TRUE, JdbcTypeMapping.TRUE, null); 53 case Types.BIGINT: 54 return new JdbcTypeMapping("BIGINT", 55 0, 0, JdbcTypeMapping.TRUE, JdbcTypeMapping.FALSE, null); 56 case Types.DOUBLE: 57 return new JdbcTypeMapping("DOUBLE PRECISION", 58 0, 0, JdbcTypeMapping.TRUE, JdbcTypeMapping.FALSE, null); 59 case Types.LONGVARCHAR: 60 return new JdbcTypeMapping("LONG VARCHAR", 61 0, 0, JdbcTypeMapping.TRUE, JdbcTypeMapping.FALSE, null); 62 case Types.CLOB: 63 return new JdbcTypeMapping("CLOB", 64 1024, 0, JdbcTypeMapping.TRUE, JdbcTypeMapping.FALSE, null); 65 case Types.VARBINARY: 66 case Types.BLOB: 67 case Types.LONGVARBINARY: 68 return new JdbcTypeMapping("BLOB", 69 1024, 0, JdbcTypeMapping.TRUE, JdbcTypeMapping.FALSE, 70 bytesConverterFactory); 71 } 72 return super.getTypeMapping(jdbcType); 73 } 74 75 79 public boolean isPreparedStatementPoolingOK() { 80 return false; 81 } 82 83 88 public HashMap getJavaTypeMappings() { 89 HashMap ans = super.getJavaTypeMappings(); 90 91 95 DateTimestampConverter.Factory dtcf = new DateTimestampConverter.Factory(); 96 ((JdbcJavaTypeMapping)ans.get(Date .class)).setConverterFactory(dtcf); 97 98 return ans; 99 } 100 101 104 public boolean isInsertBatchingSupported() { 105 return true; 106 } 107 108 111 public boolean isUpdateBatchingSupported() { 112 return true; 113 } 114 115 118 public boolean isScrollableResultSetSupported() { 119 return true; 120 } 121 122 126 public boolean isAnsiJoinSyntax() { 127 return true; 128 } 129 130 133 public boolean isNullForeignKeyOk() { 134 return true; 135 } 136 137 141 public JdbcNameGenerator createJdbcNameGenerator() { 142 DefaultJdbcNameGenerator n = createDefaultJdbcNameGenerator(); 143 n.setMaxColumnNameLength(128); 144 n.setMaxTableNameLength(128); 145 n.setMaxConstraintNameLength(128); 146 n.setMaxIndexNameLength(128); 147 return n; 148 } 149 150 151 155 public void dropTable(Connection con, String table, Statement stat) throws SQLException { 156 stat.execute("drop table " + table + " cascade"); 157 } 158 159 162 protected void appendPrimaryKeyConstraint(JdbcTable t, CharBuf s) { 163 s.append("constraint "); 164 s.append(t.pkConstraintName); 165 s.append(" primary key ("); 166 appendColumnNameList(t.pk, s); 167 s.append(')'); 168 } 169 170 173 protected void appendRefConstraint(final CharBuf s, final JdbcConstraint c) { 174 s.append("alter table "); 175 s.append(c.src.name); 176 s.append(" add constraint "); 177 s.append(c.name); 178 s.append(" foreign key ("); 179 appendColumnNameList(c.srcCols, s); 180 s.append(") references "); 181 s.append(c.dest.name); 182 s.append('('); 183 appendColumnNameList(c.dest.pk, s); 184 s.append(")"); 185 } 186 187 190 public void appendSqlFrom(JdbcTable table, String alias, 191 CharBuf s) { 192 s.append(table.name); 193 if (alias != null) { 194 s.append(" AS "); 195 s.append(alias); 196 } 197 } 198 199 203 public String getSqlUnaryFunctionName(int func) { 204 switch (func) { 205 case UnaryFunctionExp.FUNC_TO_LOWER_CASE: 206 return "lcase"; 207 } 208 throw BindingSupportImpl.getInstance().internal("Unknown func: " + func); 209 } 210 211 217 public void appendSqlFromJoin(JdbcTable table, String alias, SqlExp exp, 218 boolean outer, CharBuf s) { 219 if (outer) s.append(" LEFT JOIN "); 220 else s.append(" JOIN "); 221 s.append(table.name); 222 if (alias != null) { 223 s.append(" AS "); 224 s.append(alias); 225 } 226 if (exp != null) { 227 s.append(" ON ("); 228 exp.appendSQL(this, s, null); 229 s.append(')'); 230 } 231 } 232 233 234 238 public String getConnectionValidateSQL() { 239 return null; 240 } 241 242 245 public String getConnectionInitSQL() { 246 return null; 247 } 248 249 252 public boolean isCommentSupported() { 253 return false; 254 } 255 256 261 public boolean isUseIndexesForOrderCols() { 262 return true; 263 } 264 265 270 public char[] getSelectForUpdate() { 271 return null; 272 } 273 274 } 275 | Popular Tags |