KickJava   Java API By Example, From Geeks To Geeks.

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


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 literal valus
25  */

26 public class Literal implements Value {
27
28     // Fields
29

30     private Object JavaDoc _value;
31
32
33     // Constructors
34

35     public Literal() {
36     }
37
38     public Literal(Object JavaDoc value) {
39         _value = value;
40     }
41
42
43     // Methods
44

45     public String JavaDoc genText() {
46         return _value.toString();
47     }
48
49     public String JavaDoc toString() {
50         return _value.toString();
51     }
52
53
54     // Accessors/Mutators
55

56     public Object JavaDoc getValue() {
57         return _value;
58     }
59
60     //REVIEW: this should probably go away, and change Literal to not be a QueryItem?
61
public void getReferencedColumns(Collection JavaDoc columns) {}
62     public void getQueryItems(Collection JavaDoc items) {}
63     public Expression findExpression(String JavaDoc table1, String JavaDoc column1, String JavaDoc table2, String JavaDoc column2) {
64         return null;
65     }
66
67     public boolean isParameterized() {
68         // Original version
69
// return _value.equals("?");
70

71         // Expand prev version, to try to catch literals like "id = ?" or "id IN (?,?,?).
72
// return (_value.toString().indexOf("?") != -1 );
73

74         // Prev version was also catching "id = '?'", which is a string, not a parameter. Exclude it.
75
// return (_value.toString().matches(".*[^']?[^']"));
76

77         // Prev regexp had problems because ? was not escaped
78
// Return true if (a) string contains ? (b) string does not contain '?'
79
// This still gets other cases wrong, like ? in the middle of a string.
80
return (((_value.toString().indexOf("?")) != -1) &&
81                 ((_value.toString().indexOf("'?'")) == -1));
82     }
83
84     public void renameTableSpec(String JavaDoc oldTableSpec, String JavaDoc corrName) {}
85
86 }
87
88
89
Popular Tags