KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > visualeditor > querymodel > SetFunction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.db.sql.visualeditor.querymodel;
20
21 import java.util.Collection JavaDoc;
22
23 /**
24  * Represents a SQL Set function (AVG, COUNT, MAX, MIN, SUM)
25  * Example Form: SUM(Orders.Quantity), MAX(Employee.Salary), COUNT(Employee.Name)
26  */

27
28 public class SetFunction extends ColumnItem implements UnaryExpression {
29
30     public static final int NONE = 0;
31     public static final int AVG = 1;
32     public static final int COUNT = 2;
33     public static final int MAX = 3;
34     public static final int MIN = 4;
35     public static final int SUM = 5;
36
37     private int _type;
38     private ColumnNode _argument;
39     private Identifier _alias;
40
41     private SetFunction() { }
42
43     public SetFunction(int type, ColumnNode argument, Identifier alias) {
44         _type = type;
45         _argument = argument;
46         _alias = alias;
47     }
48
49     Column getReferencedColumn() {
50         return _argument;
51     }
52
53     public void getReferencedColumns(Collection JavaDoc columns) {
54         columns.add(_argument);
55     }
56     public void getQueryItems(Collection JavaDoc items) {
57         items.add(_argument);
58     }
59
60     public String JavaDoc genText() {
61         String JavaDoc funcType = null;
62         switch (_type) {
63             case AVG:
64                 funcType = "AVG(";
65                 break;
66             case COUNT:
67                 funcType = "COUNT(";
68                 break;
69             case MAX:
70                 funcType = "MAX(";
71                 break;
72             case MIN:
73                 funcType = "MIN(";
74                 break;
75             case SUM:
76                 funcType = "SUM(";
77                 break;
78             default:
79                 break;
80         }
81         funcType += _argument.genText();
82         funcType += ")";
83         if (_alias != null) {
84             funcType += " AS " + _alias.genText();
85         }
86         return funcType;
87     }
88
89     public Expression findExpression(String JavaDoc table1, String JavaDoc column1, String JavaDoc table2, String JavaDoc column2) {
90         return null;
91     }
92
93     /**
94      * Rename the table part of the column spec
95      */

96     public void renameTableSpec(String JavaDoc oldTableSpec, String JavaDoc corrName) {
97         _argument.renameTableSpec(oldTableSpec, corrName);
98     }
99
100     public boolean isParameterized() {
101         return false;
102     }
103
104     public Expression getOperand() {
105         return _argument;
106     }
107
108 }
109
Popular Tags