KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > queryframework > EJBQLPlaceHolderQuery


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.queryframework;
23
24
25 import oracle.toplink.essentials.exceptions.DatabaseException;
26 import oracle.toplink.essentials.exceptions.OptimisticLockException;
27 import java.util.HashMap JavaDoc;
28 import oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl;
29 import oracle.toplink.essentials.sessions.Session;
30
31
32 /**
33  * <b>Purpose</b>:
34  * A EJB3 placeholder Query object to store EJBQL strings so that processing the string is delayed
35  * until Login<p>
36  *
37  * @author Chris Delahunt
38  * @since TopLink Java Essentials
39  */

40
41 public class EJBQLPlaceHolderQuery extends DatabaseQuery {
42
43     private String JavaDoc ejbQLString;
44     private Boolean JavaDoc flushOnExecute;
45     private HashMap JavaDoc hints;
46     
47     public EJBQLPlaceHolderQuery() {
48     }
49     public EJBQLPlaceHolderQuery(String JavaDoc ejbQLString) {
50         this.ejbQLString=ejbQLString;
51     }
52     //buildEJBQLDatabaseQuery(queryString, session, hints, m_loader)
53
public EJBQLPlaceHolderQuery(String JavaDoc name, String JavaDoc ejbql, HashMap JavaDoc hints) {
54         this.name=name;
55         this.ejbQLString=ejbql;
56         this.flushOnExecute=null;
57         this.hints=hints;
58     }
59     
60     public EJBQLPlaceHolderQuery(String JavaDoc name, String JavaDoc ejbql, Boolean JavaDoc flushOnExecute, HashMap JavaDoc hints) {
61         this.name=name;
62         this.ejbQLString=ejbql;
63         this.flushOnExecute=flushOnExecute;
64         this.hints=hints;
65     }
66
67     /**
68      * INTERNAL:
69      * Add the expression value to be included in the result.
70      * EXAMPLE: reportQuery.addItem("name", expBuilder.get("firstName").toUpperCase());
71      * The resultType can be specified to support EJBQL that adheres to the
72      * EJB 3.0 spec.
73      */

74     public String JavaDoc getEJBQLString(){
75         return ejbQLString;
76     }
77     public void setEJBQLString(String JavaDoc ejbQLString){
78         this.ejbQLString = ejbQLString;
79     }
80     
81     /**
82      * INTERNAL:
83      * Accessor methods for hints that would be added to the EJBQuery class and
84      * applied to the TopLink query.
85      */

86     public HashMap JavaDoc getHints(){
87         return hints;
88     }
89     public void setHints(HashMap JavaDoc hints){
90         this.hints = hints;
91     }
92     
93     
94     public DatabaseQuery processEjbQLQuery(Session session){
95         ClassLoader JavaDoc classloader = session.getDatasourcePlatform().getConversionManager().getLoader();
96         DatabaseQuery ejbquery = EJBQueryImpl.buildEJBQLDatabaseQuery(ejbQLString, flushOnExecute, session, hints, classloader);
97         ejbquery.setName(this.getName());
98         return ejbquery;
99     }
100     
101     
102     
103     /**
104      * INTERNAL:
105      * This should never be called and is only here because it is needed as an extension
106      * to DatabaseQuery. An exception should be thrown to warn users, but for now
107      * it will process the EJBQL and execute the resulting query instead.
108      *
109      * @exception DatabaseException - an error has occurred on the database.
110      * @exception OptimisticLockException - an error has occurred using the optimistic lock feature.
111      * @return - the result of executing the query.
112      */

113     public Object JavaDoc executeDatabaseQuery() throws DatabaseException, OptimisticLockException{
114         DatabaseQuery ejbquery = processEjbQLQuery(this.getSession());
115         return ejbquery.executeDatabaseQuery();
116     }
117 }
118
Popular Tags