1 2 12 package com.versant.core.jdbc.sql; 13 14 import com.versant.core.jdbc.metadata.*; 15 import com.versant.core.jdbc.sql.exp.SqlExp; 16 import com.versant.core.util.CharBuf; 17 18 import java.io.PrintWriter ; 19 import java.util.HashMap ; 20 import java.sql.Types ; 21 22 import com.versant.core.util.CharBuf; 23 24 27 public class MckoiSqlDriver extends SqlDriver { 28 29 32 public String getName() { 33 return "mckoi"; 34 } 35 36 43 protected JdbcTypeMapping getTypeMapping(int jdbcType) { 44 switch (jdbcType) { 45 case Types.LONGVARCHAR: 46 case Types.CLOB: 47 return new JdbcTypeMapping("LONGVARCHAR", 48 0, 0, JdbcTypeMapping.TRUE, JdbcTypeMapping.FALSE, 49 null); 50 case Types.LONGVARBINARY: 51 case Types.BLOB: 52 return new JdbcTypeMapping("LONGVARBINARY", 53 0, 0, JdbcTypeMapping.TRUE, JdbcTypeMapping.FALSE, 54 bytesConverterFactory); 55 } 56 return super.getTypeMapping(jdbcType); 57 } 58 59 64 public HashMap getJavaTypeMappings() { 65 HashMap ans = super.getJavaTypeMappings(); 66 return ans; 67 } 68 69 72 public boolean isInsertBatchingSupported() { 73 return false; 74 } 75 76 79 public boolean isUpdateBatchingSupported() { 80 return false; 81 } 82 83 87 public boolean isAnsiJoinSyntax() { 88 return true; 89 } 90 91 94 public boolean isNullForeignKeyOk() { 95 return true; 96 } 97 98 102 public boolean isConvertExistsToDistinctJoin() { 103 return true; 104 } 105 106 110 public JdbcNameGenerator createJdbcNameGenerator() { 111 DefaultJdbcNameGenerator n = createDefaultJdbcNameGenerator(); 112 n.setMaxColumnNameLength(31); 113 n.setMaxTableNameLength(31); 114 n.setMaxConstraintNameLength(31); 115 n.setMaxTableNameLength(31); 116 return n; 117 } 118 119 123 protected void appendCreateColumnNulls(JdbcTable t, JdbcColumn c, 124 CharBuf s) { 125 if (!c.nulls) s.append(" not null"); 126 } 127 128 131 protected void appendPrimaryKeyConstraint(JdbcTable t, CharBuf s) { 132 s.append("constraint "); 133 s.append(t.pkConstraintName); 134 s.append(" primary key ("); 135 appendColumnNameList(t.pk, s); 136 s.append(')'); 137 } 138 139 142 protected void appendRefConstraint(CharBuf s, JdbcConstraint c) { 143 s.append("alter table "); 144 s.append(c.src.name); 145 s.append(" add constraint "); 146 s.append(c.name); 147 s.append(" foreign key ("); 148 appendColumnNameList(c.srcCols, s); 149 s.append(") references "); 150 s.append(c.dest.name); 151 s.append('('); 152 appendColumnNameList(c.dest.pk, s); 153 s.append(')'); 154 } 155 156 159 protected void print(PrintWriter out, String sql) { 160 out.print(sql); 161 out.println(";"); 162 out.println(); 163 } 164 165 168 public void appendSqlFrom(JdbcTable table, String alias, 169 CharBuf s) { 170 s.append(table.name); 171 if (alias != null) { 172 s.append(" AS "); 173 s.append(alias); 174 } 175 } 176 177 183 public void appendSqlFromJoin(JdbcTable table, String alias, SqlExp exp, 184 boolean outer, CharBuf s) { 185 if (outer) s.append(" LEFT JOIN "); 186 else s.append(" JOIN "); 187 s.append(table.name); 188 if (alias != null) { 189 s.append(" AS "); 190 s.append(alias); 191 } 192 if (exp != null) { 193 s.append(" ON ("); 194 exp.appendSQL(this, s, null); 195 s.append(')'); 196 } 197 } 198 199 } 200 | Popular Tags |