KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 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 org.apache.ws.jaxme.sqls.Column;
20 import org.apache.ws.jaxme.sqls.ColumnReference;
21 import org.apache.ws.jaxme.sqls.Function;
22 import org.apache.ws.jaxme.sqls.SelectStatement;
23 import org.apache.ws.jaxme.sqls.Table;
24 import org.apache.ws.jaxme.sqls.TableReference;
25
26
27 /** <p>A virtual column is a named item that can be added
28  * to the result set. For example:</p>
29  * <pre>
30  * SELECT name, vorname, MAX(a) AS max FROM ...
31  * </pre>
32  * <p>The example uses a virtual column max. The value of
33  * max is calculated from other values.</p>
34  *
35  * @author <a HREF="mailto:jwi@softwareag.com">Jochen Wiedmann</a>
36  */

37 public class VirtualColumn extends AbstractColumn implements ColumnReference {
38     private Column.Name alias;
39     private Object JavaDoc value;
40     
41     public VirtualColumn(Column.Name pName, Column.Type pType) {
42         super(pName, pType);
43     }
44     
45     public VirtualColumn(String JavaDoc pName, Column.Type pType) {
46         super(new ColumnImpl.NameImpl(pName), pType);
47     }
48     
49     public Table getTable() { return null; }
50     public String JavaDoc getQName() { return getName().toString(); }
51     public boolean isPrimaryKeyPart() { return false; }
52     public TableReference getTableReference() { return null; }
53     public Column getColumn() { return this; }
54     public boolean isVirtual() { return true; }
55     
56     public void setAlias(String JavaDoc pName) {
57         setAlias(new ColumnImpl.NameImpl(pName));
58     }
59     
60     public void setAlias(Name pName) {
61         alias = pName;
62     }
63     
64     public Name getAlias() {
65         return alias;
66     }
67     
68     public void setValue(String JavaDoc pValue) {
69         value = pValue;
70     }
71     
72     public void setValue(SelectStatement pValue) {
73         value = pValue;
74     }
75     
76     public void setValue(Function pValue) {
77         value = pValue;
78     }
79     
80     public Object JavaDoc getValue() {
81         return value;
82     }
83 }
84
Popular Tags