1 64 65 package com.jcorporate.expresso.core.misc; 66 67 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 68 69 70 75 public class SQLFastStringBuffer { 76 79 FastStringBuffer sb; 80 83 private boolean begin = true; 84 85 88 public SQLFastStringBuffer() { 89 sb = new FastStringBuffer(); 90 } 91 92 97 public SQLFastStringBuffer(String s) { 98 sb = new FastStringBuffer(s); 99 } 100 101 106 public SQLFastStringBuffer(int length) { 107 sb = new FastStringBuffer(length); 108 } 109 110 115 public SQLFastStringBuffer addListSeparator() { 116 if (begin) { 117 begin = false; 118 } else { 119 sb.append(","); 120 } 121 return this; 122 } 123 124 130 public SQLFastStringBuffer append(double v) { 131 sb.append(v); 132 return this; 133 } 134 135 141 public SQLFastStringBuffer append(int v) { 142 sb.append(v); 143 return this; 144 } 145 146 152 public SQLFastStringBuffer append(String v) { 153 sb.append(v); 154 return this; 155 } 156 157 163 public SQLFastStringBuffer appendSQLItem(String i) { 164 addListSeparator(); 165 sb.append(i); 166 return this; 167 } 168 169 175 public SQLFastStringBuffer appendSQLNestedValue(double v) { 176 addListSeparator(); 177 sb.append(v); 178 return this; 179 } 180 181 187 public SQLFastStringBuffer appendSQLNestedValue(int v) { 188 addListSeparator(); 189 sb.append(v); 190 return this; 191 } 192 193 199 public SQLFastStringBuffer appendSQLNestedValue(String v) { 200 addListSeparator(); 201 return appendSQLValue(v); 202 } 203 204 210 public SQLFastStringBuffer appendSQLValue(double v) { 211 sb.append(v); 212 return this; 213 } 214 215 221 public SQLFastStringBuffer appendSQLValue(int v) { 222 sb.append(v); 223 return this; 224 } 225 226 232 public SQLFastStringBuffer appendSQLValue(String v) { 233 int i = 0; 234 if (v != null) { 235 while ((i = v.indexOf("'", i)) >= 0) { 236 v = v.substring(0, i) + "'" + v.substring(i); 237 i += 2; 238 } 239 sb.append("'"); 240 } 241 sb.append(v); 242 if (v != null) { 243 sb.append("'"); 244 } 245 return this; 246 } 247 248 254 public SQLFastStringBuffer appendSQLPadValue(String str) { 255 sb.append(" " + str + " "); 256 return this; 257 } 258 259 264 public SQLFastStringBuffer startList() { 265 begin = true; 266 return this; 267 } 268 269 272 public String toString() { 273 return sb.toString(); 274 } 275 } 276 | Popular Tags |