1 2 12 package com.versant.core.jdbc.sql.exp; 13 14 import com.versant.core.jdbc.sql.SqlDriver; 15 import com.versant.core.util.CharBuf; 16 import com.versant.core.jdo.query.MultiplyNode; 17 18 import java.util.Map ; 19 20 23 public class MultiplyExp extends SqlExp { 24 25 public static final int OP_TIMES = MultiplyNode.OP_TIMES; 26 public static final int OP_DIVIDE = MultiplyNode.OP_DIVIDE; 27 28 32 private int[] ops; 33 34 public MultiplyExp(SqlExp children, int[] ops) { 35 super(children); 36 this.ops = ops; 37 } 38 39 public MultiplyExp() { 40 } 41 42 public SqlExp createInstance() { 43 return new MultiplyExp(); 44 } 45 46 public SqlExp getClone(SqlExp clone, Map cloneMap) { 47 super.getClone(clone, cloneMap); 48 49 if (ops != null) { 50 int n = ops.length; 51 int[] cOps = ((MultiplyExp) clone).ops = new int[ops.length]; 52 for (int i = 0; i < n; i++) { 53 cOps[i] = ops[i]; 54 } 55 } 56 57 return clone; 58 } 59 60 67 public void appendSQLImp(SqlDriver driver, CharBuf s, SqlExp leftSibling) { 68 int i = 0; 69 appendSQL(childList, driver, s, null); 70 SqlExp prev = childList; 71 for (SqlExp e = childList.next; e != null; prev = e, e = e.next) { 72 s.append(' '); 73 switch (ops[i++]) { 74 case OP_TIMES: 75 s.append('*'); 76 break; 77 case OP_DIVIDE: 78 s.append('/'); 79 break; 80 } 81 s.append(' '); 82 appendSQL(e, driver, s, prev); 83 } 84 } 85 86 private void appendSQL(SqlExp e, SqlDriver driver, CharBuf s, 87 SqlExp leftSibling) { 88 boolean p = e.requiresParensInMultiply(); 89 if (p) s.append('('); 90 e.appendSQL(driver, s, leftSibling); 91 if (p) s.append(')'); 92 } 93 } 94 | Popular Tags |