KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > query > JRHibernateQueryExecuterFactory


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.query;
29
30 import java.util.Map JavaDoc;
31
32 import net.sf.jasperreports.engine.JRDataset;
33 import net.sf.jasperreports.engine.JRException;
34 import net.sf.jasperreports.engine.util.JRProperties;
35
36 import org.hibernate.Session;
37
38 /**
39  * Query executer factory for HQL queries that uses Hibernate 3.
40  * <p/>
41  * The factory creates {@link net.sf.jasperreports.engine.query.JRHibernateQueryExecuter JRHibernateQueryExecuter}
42  * query executers.
43  *
44  * @author Lucian Chirita (lucianc@users.sourceforge.net)
45  * @version $Id: JRHibernateQueryExecuterFactory.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
46  */

47 public class JRHibernateQueryExecuterFactory implements JRQueryExecuterFactory
48 {
49
50     /**
51      * HQL query language.
52      */

53     public static final String JavaDoc QUERY_LANGUAGE_HQL = "hql";
54     
55     /**
56      * Built-in parameter holding the value of the Hibernate session to be used for creating the query.
57      */

58     public final static String JavaDoc PARAMETER_HIBERNATE_SESSION = "HIBERNATE_SESSION";
59     
60     /**
61      * Built-in parameter used for collection filter queries.
62      * <p/>
63      * The value of this paramter will be used as the collection to filter using the query.
64      */

65     public final static String JavaDoc PARAMETER_HIBERNATE_FILTER_COLLECTION = "HIBERNATE_FILTER_COLLECTION";
66     
67     private final static Object JavaDoc[] HIBERNATE_BUILTIN_PARAMETERS = {
68         PARAMETER_HIBERNATE_SESSION, Session.class,
69         PARAMETER_HIBERNATE_FILTER_COLLECTION, Object JavaDoc.class,
70         };
71
72     /**
73      * Property specifying the query execution type.
74      * <p/>
75      * Possible values are:
76      * <ul>
77      * <li><em>list</em> (default) - the query will be run by calling <code>org.hibernate.Query.list()</code></li>
78      * <li><em>iterate</em> - the query will be run by calling <code>org.hibernate.Query.iterate()</code></li>
79      * <li><em>scroll</em> - the query will be run by calling <code>org.hibernate.Query.scroll()</code></li>
80      * </ul>
81      */

82     public static final String JavaDoc PROPERTY_HIBERNATE_QUERY_RUN_TYPE = JRProperties.PROPERTY_PREFIX + "hql.query.run.type";
83     
84     /**
85      * Property specifying the number of result rows to be retrieved at once when the execution type is <em>list</em>.
86      * <p/>
87      * Result pagination is implemented by <code>org.hibernate.Query.setFirstResult()</code> and <code>org.hibernate.Query.setMaxResults()</code>.
88      * <p/>
89      * By default, all the rows are retrieved (no result pagination is performed).
90      */

91     public static final String JavaDoc PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE = JRProperties.PROPERTY_PREFIX + "hql.query.list.page.size";
92     
93     /**
94      * Property specifying whether field descriptions should be used to determine the mapping between the fields
95      * and the query return values.
96      */

97     public static final String JavaDoc PROPERTY_HIBERNATE_FIELD_MAPPING_DESCRIPTIONS = JRProperties.PROPERTY_PREFIX + "hql.field.mapping.descriptions";
98     
99     /**
100      * Value of the {@link #PROPERTY_HIBERNATE_QUERY_RUN_TYPE PROPERTY_HIBERNATE_QUERY_RUN_TYPE} property
101      * corresponding to <em>list</em> execution type.
102      */

103     public static final String JavaDoc VALUE_HIBERNATE_QUERY_RUN_TYPE_LIST = "list";
104     
105     /**
106      * Value of the {@link #PROPERTY_HIBERNATE_QUERY_RUN_TYPE PROPERTY_HIBERNATE_QUERY_RUN_TYPE} property
107      * corresponding to <em>iterate</em> execution type.
108      */

109     public static final String JavaDoc VALUE_HIBERNATE_QUERY_RUN_TYPE_ITERATE = "iterate";
110     
111     /**
112      * Value of the {@link #PROPERTY_HIBERNATE_QUERY_RUN_TYPE PROPERTY_HIBERNATE_QUERY_RUN_TYPE} property
113      * corresponding to <em>scroll</em> execution type.
114      */

115     public static final String JavaDoc VALUE_HIBERNATE_QUERY_RUN_TYPE_SCROLL = "scroll";
116
117     
118     /**
119      * Returns an array containing the {@link #PARAMETER_HIBERNATE_SESSION PARAMETER_HIBERNATE_SESSION} and
120      * {@link #PARAMETER_HIBERNATE_FILTER_COLLECTION PARAMETER_HIBERNATE_FILTER_COLLECTION} paramters.
121      */

122     public Object JavaDoc[] getBuiltinParameters()
123     {
124         return HIBERNATE_BUILTIN_PARAMETERS;
125     }
126
127     public JRQueryExecuter createQueryExecuter(JRDataset dataset, Map JavaDoc parameters) throws JRException
128     {
129         return new JRHibernateQueryExecuter(dataset, parameters);
130     }
131
132     /**
133      * Returns <code>true</code> for all parameter types.
134      */

135     public boolean supportsQueryParameterType(String JavaDoc className)
136     {
137         return true;
138     }
139 }
140
Popular Tags