1 2 12 package com.versant.core.jdbc.sql.exp; 13 14 import com.versant.core.util.CharBuf; 15 import com.versant.core.jdbc.sql.SqlDriver; 16 import com.versant.core.jdbc.sql.conv.DummyPreparedStmt; 17 import com.versant.core.metadata.MDStatics; 18 19 import java.sql.Types ; 20 import java.sql.SQLException ; 21 import java.util.Map ; 22 23 26 public class LiteralExp extends LeafExp { 27 28 public static final int TYPE_STRING = 1; 29 public static final int TYPE_OTHER = 2; 30 public static final int TYPE_NULL = 3; 31 public static final int TYPE_BOOLEAN = 4; 32 33 public int type; 34 public String value; 35 36 public LiteralExp(int type, String value) { 37 this.type = type; 38 this.value = value; 39 } 40 41 public LiteralExp() { 42 } 43 44 public SqlExp createInstance() { 45 return new LiteralExp(); 46 } 47 48 public SqlExp getClone(SqlExp clone, Map cloneMap) { 49 super.getClone(clone, cloneMap); 50 51 ((LiteralExp) clone).type = type; 52 ((LiteralExp) clone).value = value; 53 54 return clone; 55 } 56 57 public LiteralExp(int value) { 58 this(TYPE_OTHER, Integer.toString(value)); 59 } 60 61 public String toString() { 62 StringBuffer s = new StringBuffer (); 63 s.append(super.toString()); 64 s.append(' '); 65 if (type == TYPE_STRING) s.append('\''); 66 s.append(value); 67 if (type == TYPE_STRING) s.append('\''); 68 return s.toString(); 69 } 70 71 78 public void appendSQLImp(SqlDriver driver, CharBuf s, SqlExp leftSibling) { 79 if (type == TYPE_BOOLEAN && leftSibling instanceof ColumnExp) { 80 ColumnExp cExp = (ColumnExp)leftSibling; 84 if (cExp.col.converter != null) { 85 DummyPreparedStmt pstmt = new DummyPreparedStmt(); 86 try { 87 cExp.col.converter.set(pstmt, 0, cExp.col, 88 new Boolean (value)); 89 } catch (SQLException e) { 90 } 92 value = pstmt.value; 93 if (pstmt.toQuote) { 94 type = LiteralExp.TYPE_STRING; 95 } else { 96 type = LiteralExp.TYPE_OTHER; 97 } 98 } 99 } 100 driver.appendSqlLiteral(type, value, s); 101 } 102 103 106 public int getJdbcType() { 107 if (type == TYPE_STRING) return Types.VARCHAR; 108 return 0; 109 } 110 111 114 public int getJavaTypeCode() { 115 if (type == TYPE_STRING) return MDStatics.STRING; 116 return 0; 117 } 118 } 119 | Popular Tags |