1 17 package org.apache.ws.jaxme.sqls.impl; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.apache.ws.jaxme.sqls.Case; 24 import org.apache.ws.jaxme.sqls.ColumnReference; 25 import org.apache.ws.jaxme.sqls.Expression; 26 import org.apache.ws.jaxme.sqls.Function; 27 import org.apache.ws.jaxme.sqls.Parts; 28 import org.apache.ws.jaxme.sqls.SelectStatement; 29 import org.apache.ws.jaxme.sqls.Statement; 30 import org.apache.ws.jaxme.sqls.Value; 31 32 35 public abstract class PartsImpl implements Parts { 36 private final Statement statement; 37 private final List parts = new ArrayList (); 38 39 protected PartsImpl(Statement pStatement) { 40 statement = pStatement; 41 } 42 43 protected void add(Object o) { 44 parts.add(o); 45 } 46 47 49 public Statement getStatement() { 50 return statement; 51 } 52 53 public void addPart(Value pValue) { 54 if (pValue == null) { 55 throw new NullPointerException ("A constant value must not be null."); 56 } 57 parts.add(pValue); 58 } 59 60 public void addPart(ColumnReference pColumn) { 61 if (pColumn == null) { 62 throw new NullPointerException ("Referenced column must not be null."); 63 } 64 add(pColumn); 65 } 66 67 public void addPart(ColumnReference[] pColumns) { 68 if (pColumns == null) { 69 throw new NullPointerException ("The array of referenced columns must not be null."); 70 } 71 for (int i = 0; i < pColumns.length; i++) { 72 if (pColumns[i] == null) { 73 throw new NullPointerException ("The referenced column with number " + i + " must not be null."); 74 } 75 } 76 add(pColumns); 77 } 78 79 public void addPart(SelectStatement pStatement) { 80 if (pStatement == null) { 81 throw new NullPointerException ("The subselect statement must not be null."); 82 } 83 add(pStatement); 84 } 85 86 public void addPart(String pString) { 87 add(new ValueImpl(Value.Type.STRING, pString)); 88 } 89 90 public void addPart() { 91 add(new ValueImpl(Value.Type.NULL, null)); 92 } 93 94 public void addPart(byte pByte) { 95 add(new ValueImpl(Value.Type.BYTE, new Byte (pByte))); 96 } 97 98 public void addPart(int pInt) { 99 add(new ValueImpl(Value.Type.INT, new Integer (pInt))); 100 } 101 102 public void addPart(long pLong) { 103 add(new ValueImpl(Value.Type.LONG, new Long (pLong))); 104 } 105 106 public void addPart(short pShort) { 107 add(new ValueImpl(Value.Type.SHORT, new Short (pShort))); 108 } 109 110 public void addPart(float pFloat) { 111 add(new ValueImpl(Value.Type.FLOAT, new Float (pFloat))); 112 } 113 114 public void addPart(double pDouble) { 115 add(new ValueImpl(Value.Type.DOUBLE, new Double (pDouble))); 116 } 117 118 public void addPart(boolean pBoolean) { 119 add(new ValueImpl(Value.Type.BOOLEAN, pBoolean ? Boolean.TRUE : Boolean.FALSE)); 120 } 121 122 public void addPart(Function pFunction) { 123 add(pFunction); 124 } 125 126 public void addPart(Expression pExpression) { 127 add(pExpression); 128 } 129 130 public void addPlaceholder() { 131 add(new ValueImpl(Value.Type.PLACEHOLDER, null)); 132 } 133 134 136 public void addRawSQLPart(String pRawSQL) { 137 add(getStatement().getSQLFactory().getObjectFactory().newRawSQL(pRawSQL)); 138 } 139 140 public int getNumParts() { 141 return parts.size(); 142 } 143 144 public Iterator getParts() { 145 return parts.iterator(); 146 } 147 148 public void addPart(Case pCase) { 149 add(pCase); 150 } 151 152 private Expression newExpression(Expression.Type pType) { 153 Statement st = getStatement(); 154 Expression result = st.getSQLFactory().getObjectFactory().createExpression(st, pType); 155 addPart(result); 156 return result; 157 } 158 159 public Expression createSUM() { return newExpression(Expression.SUM); } 160 public Expression createPRODUCT() { return newExpression(Expression.PRODUCT); } 161 public Expression createDIFFERENCE() { return newExpression(Expression.DIFFERENCE); } 162 public Expression createQUOTIENT() { return newExpression(Expression.QUOTIENT); } 163 } 164 | Popular Tags |