KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.db.sql.visualeditor.parser.SQLParser;
22 import org.netbeans.modules.db.sql.visualeditor.parser.ParseException;
23 import java.util.ArrayList JavaDoc;
24
25 public class SQLQueryFactory {
26
27     public static Query parse(String JavaDoc query) throws ParseException {
28         SQLParser parser = new SQLParser(new java.io.StringReader JavaDoc(query));
29         return (Query)parser.SQLQuery();
30     }
31
32     public static Where createWhere(Expression expr) {
33         return new WhereNode(expr);
34     }
35
36     public static Predicate createPredicate(Value val1, Value val2, String JavaDoc op) {
37         return new Predicate(val1, val2, op);
38     }
39
40     public static Predicate createPredicate(Value val1, Object JavaDoc literal, String JavaDoc op) {
41         Literal val2 = new Literal(literal);
42         return new Predicate(val1, val2, op);
43     }
44
45     public static Predicate createPredicate(String JavaDoc[] rel) {
46         return new Predicate(rel);
47     }
48
49     public static GroupBy createGroupBy(ArrayList JavaDoc columnList) {
50         return new GroupByNode(columnList);
51     }
52
53     public static OrderBy createOrderBy() {
54         return new OrderByNode();
55     }
56
57     public static Column createColumn(String JavaDoc tableSpec, String JavaDoc columnName) {
58         return new ColumnNode(tableSpec, columnName);
59     }
60
61     public static Literal createLiteral(Object JavaDoc value) {
62         return new Literal(value);
63     }
64
65     public static Table createTable(String JavaDoc tableName, String JavaDoc corrName, String JavaDoc schemaName) {
66         return new TableNode(tableName, corrName, schemaName);
67     }
68
69     public static JoinTable createJoinTable(Table table) {
70         return new JoinTableNode((TableNode)table);
71     }
72
73     public static And createAnd(Expression expr1, Expression expr2) {
74         ArrayList JavaDoc items = new ArrayList JavaDoc();
75         items.add(expr1);
76         items.add(expr2);
77         return new AndNode(items);
78     }
79
80     public static Or createOr(Expression expr1, Expression expr2) {
81         ArrayList JavaDoc items = new ArrayList JavaDoc();
82         items.add(expr1);
83         items.add(expr2);
84         return new OrNode(items);
85     }
86 }
87
Popular Tags