KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > sqls > impl > PartsImpl


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.sqls.impl;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
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 /**
33  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
34  */

35 public abstract class PartsImpl implements Parts {
36   private final Statement statement;
37   private final List JavaDoc parts = new ArrayList JavaDoc();
38
39   protected PartsImpl(Statement pStatement) {
40     statement = pStatement;
41   }
42
43   protected void add(Object JavaDoc o) {
44     parts.add(o);
45   }
46
47   /** Returns the statement, to which the part belongs.
48    */

49   public Statement getStatement() {
50     return statement;
51   }
52
53   public void addPart(Value pValue) {
54     if (pValue == null) {
55       throw new NullPointerException JavaDoc("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 JavaDoc("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 JavaDoc("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 JavaDoc("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 JavaDoc("The subselect statement must not be null.");
82     }
83     add(pStatement);
84   }
85
86   public void addPart(String JavaDoc 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 JavaDoc(pByte)));
96   }
97
98   public void addPart(int pInt) {
99     add(new ValueImpl(Value.Type.INT, new Integer JavaDoc(pInt)));
100   }
101
102   public void addPart(long pLong) {
103     add(new ValueImpl(Value.Type.LONG, new Long JavaDoc(pLong)));
104   }
105
106   public void addPart(short pShort) {
107     add(new ValueImpl(Value.Type.SHORT, new Short JavaDoc(pShort)));
108   }
109
110   public void addPart(float pFloat) {
111     add(new ValueImpl(Value.Type.FLOAT, new Float JavaDoc(pFloat)));
112   }
113
114   public void addPart(double pDouble) {
115     add(new ValueImpl(Value.Type.DOUBLE, new Double JavaDoc(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   /** <p>Inserts raw SQL code.</p>
135    */

136   public void addRawSQLPart(String JavaDoc pRawSQL) {
137     add(getStatement().getSQLFactory().getObjectFactory().newRawSQL(pRawSQL));
138   }
139
140   public int getNumParts() {
141     return parts.size();
142   }
143
144   public Iterator JavaDoc 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