1 /******************************************************************************** 2 * ****************************************************************************** 3 * Copyright (c) 2005 Chris Rose and AIMedia All rights reserved. SQLColumnSet 4 * and the accompanying materials are made available under the terms of the 5 * Common Public License v1.0 which accompanies this distribution, and is 6 * available at http://www.eclipse.org/legal/cpl-v10.html Contributors: Chris 7 * Rose 8 ******************************************************************************/ 9 package ca.spaz.sql; 10 11 import java.util.*; 12 13 /*** 14 * TODO describe 15 * 16 * @author Chris Rose 17 */ 18 public class SQLColumnSet { 19 20 private List terms; 21 22 private List names; 23 24 /*** 25 * 26 */ 27 public SQLColumnSet() { 28 super(); 29 names = new ArrayList(); 30 terms = new ArrayList(); 31 } 32 33 public void add(String name, String str) { 34 names.add(name); 35 terms.add(str); 36 } 37 38 public void add(String name, Object o) { 39 names.add(name); 40 terms.add(SQLStatement.fixClass(o)); 41 } 42 43 public void add(String name, int i) { 44 names.add(name); 45 terms.add(new Integer(i)); 46 } 47 48 public void add(String name, boolean b) { 49 names.add(name); 50 terms.add(new Boolean(b)); 51 } 52 53 public void add(String name, double d) { 54 names.add(name); 55 terms.add(new Double(d)); 56 } 57 58 public void add(String name, float f) { 59 names.add(name); 60 terms.add(new Double(f)); 61 } 62 63 public void add(String name, char c) { 64 names.add(name); 65 terms.add(new Character(c)); 66 } 67 68 public String getNameString() { 69 StringBuffer sb = new StringBuffer(); 70 sb.append(" ( "); 71 for (int i = 0; i < names.size(); i++) { 72 Object name = names.get(i); 73 sb.append(name.toString()); 74 if (i < names.size() - 1) { 75 sb.append(", "); 76 } 77 } 78 sb.append(" ) "); 79 return sb.toString(); 80 } 81 82 public String getValueString() { 83 StringBuffer sb = new StringBuffer(); 84 sb.append(" ("); 85 for (int i = 0; i < terms.size(); i++) { 86 Object term = terms.get(i); 87 if (term != null) { 88 sb.append(" '"); 89 sb.append(SQLStatement.escape(term.toString())); 90 sb.append("' "); 91 } else { 92 sb.append(" NULL"); 93 } 94 if (i < terms.size() - 1) { 95 sb.append(", "); 96 } 97 } 98 sb.append(") "); 99 return sb.toString(); 100 } 101 102 public List getNames() { 103 return Collections.unmodifiableList(names); 104 } 105 106 public List getValues() { 107 return Collections.unmodifiableList(terms); 108 } 109 110 }