KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > QueryDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment;
25
26 import java.lang.reflect.Method JavaDoc;
27 import java.util.logging.*;
28 import com.sun.enterprise.deployment.util.LogDomains;
29
30 /**
31  * This class contains information about EJB-QL queries for
32  * finder/selector methods of EJB2.0 CMP EntityBeans.
33  * It represents the <query> XML element.
34  *
35  * @author Sanjeev Krishnan
36  */

37
38 public final class QueryDescriptor extends Descriptor {
39
40     // For EJB2.0: the query is either a string in EJB-QL or is empty.
41
// For EJB1.1: the query empty (only sql is available)
42
private String JavaDoc query;
43
44     // SQL query corresponding to EJB-QL or English
45
private String JavaDoc sql;
46
47     private MethodDescriptor methodDescriptor;
48     private Method JavaDoc method;
49
50     
51     // Deployment information used to specify whether ejbs
52
// returned by a select query should be materialized as
53
// EJBLocalObject or EJBObject. This property is optional
54
// and is only applicable for ejbSelect methods that
55
// select ejbs.
56

57     private static final int NO_RETURN_TYPE_MAPPING = 0;
58     private static final int RETURN_LOCAL_TYPES = 1;
59     private static final int RETURN_REMOTE_TYPES = 2;
60
61     private int returnTypeMapping;
62     
63     // Create logger object per Java SDK 1.4 to log messages
64
// introduced Santanu De, Sun Microsystems, March 2002
65

66     static Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER);
67     
68     public QueryDescriptor()
69     {
70         this.query = null;
71         this.sql = null;
72         this.returnTypeMapping = NO_RETURN_TYPE_MAPPING;
73     }
74
75     public QueryDescriptor(QueryDescriptor otherQuery, Method JavaDoc m) {
76         this.query = otherQuery.query;
77         this.sql = otherQuery.sql;
78         this.method = m;
79         this.returnTypeMapping = otherQuery.returnTypeMapping;
80     }
81
82 /**
83     public void setQueryMethod(MethodDescriptor md)
84     {
85     this.methodDescriptor = md;
86     }
87
88     public MethodDescriptor getQueryMethod()
89     {
90     return methodDescriptor;
91     }
92 **/

93
94     public void setQueryMethod(Method JavaDoc m)
95     {
96     this.method = m;
97     }
98
99     public Method JavaDoc getQueryMethod()
100     {
101     return method;
102     }
103     
104     public void setQueryMethodDescriptor(MethodDescriptor m) {
105         methodDescriptor = m;
106     }
107     
108     public MethodDescriptor getQueryMethodDescriptor() {
109         return methodDescriptor;
110     }
111
112     public boolean getIsEjbQl()
113     {
114         return (query != null);
115     }
116
117     /**
118      * Set the EJB-QL query (ejb-ql XML element). If query parameter
119      * is null, or has no content, getIsEjbQl will return false.
120      * Otherwise, getIsEjbQl will return true.
121      */

122     public void setQuery(String JavaDoc query)
123     {
124          _logger.log(Level.FINE,"input query = '" + query + "'");
125  
126         String JavaDoc newQuery = (query != null) ? query.trim() : null;
127         if( (newQuery != null) && newQuery.equals("") ) {
128             newQuery = null;
129         }
130         if( newQuery == null ) {
131             _logger.log(Level.FINE,"query has no content -- setting to NULL");
132         } else {
133             _logger.log(Level.FINE,"setting query to '" + newQuery + "'");
134         }
135         this.query = newQuery;
136     }
137
138     /**
139      * Get the EJB-QL query (ejb-ql XML element)
140      */

141     public String JavaDoc getQuery()
142     {
143     return query;
144     }
145
146     public boolean getHasSQL() {
147         return (this.sql != null);
148     }
149
150     public void setSQL(String JavaDoc sql)
151     {
152     this.sql = sql;
153     }
154
155     public String JavaDoc getSQL()
156     {
157     return sql;
158     }
159
160
161     // Returns true if no return type mapping has been specified
162
public boolean getHasNoReturnTypeMapping() {
163         return (returnTypeMapping == NO_RETURN_TYPE_MAPPING);
164     }
165
166     // Returns true only if a local return type has been specified.
167
public boolean getHasLocalReturnTypeMapping() {
168         return (returnTypeMapping == RETURN_LOCAL_TYPES);
169     }
170
171     // Returns true only if a remote return type has been specified.
172
public boolean getHasRemoteReturnTypeMapping() {
173         return (returnTypeMapping == RETURN_REMOTE_TYPES);
174     }
175
176     public void setHasNoReturnTypeMapping() {
177         returnTypeMapping = NO_RETURN_TYPE_MAPPING;
178     }
179
180     public void setHasLocalReturnTypeMapping() {
181         returnTypeMapping = RETURN_LOCAL_TYPES;
182     }
183
184     public void setHasRemoteReturnTypeMapping() {
185         returnTypeMapping = RETURN_REMOTE_TYPES;
186     }
187
188     public int getReturnTypeMapping() {
189         return returnTypeMapping;
190     }
191     
192     public void print(StringBuffer JavaDoc toStringBuffer) {
193         toStringBuffer.append("Query ");
194         if(getQueryMethodDescriptor() != null)
195             getQueryMethodDescriptor().print(toStringBuffer);
196         toStringBuffer.append("\n");
197         if (getHasSQL()) {
198             toStringBuffer.append("SQL : ").append(getSQL());
199             return;
200         }
201         if (getIsEjbQl()) {
202             toStringBuffer.append("EJB QL: ").append(query);
203             return;
204         }
205         toStringBuffer.append(" No query associated");
206     }
207
208 }
209
210
Popular Tags