001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2005 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.query;
029:
030: import java.util.Map;
031:
032: import javax.persistence.EntityManager;
033:
034: import net.sf.jasperreports.engine.JRDataset;
035: import net.sf.jasperreports.engine.JRException;
036: import net.sf.jasperreports.engine.util.JRProperties;
037:
038: /**
039: * Java Persistence API query executer factory for EJBQL queries.
040: * <p/>
041: * The factory creates {@link net.sf.jasperreports.engine.query.JRJpaQueryExecuter JRJpaQueryExecuter}
042: * query executers.
043: *
044: * @author Marcel Overdijk (marceloverdijk@hotmail.com)
045: * @version $Id: JRJpaQueryExecuterFactory.java 1251 2006-05-08 11:15:01Z lucianc $
046: */
047: public class JRJpaQueryExecuterFactory implements
048: JRQueryExecuterFactory {
049:
050: /**
051: * EJBQL query language.
052: */
053: public static final String QUERY_LANGUAGE_EJBQL = "ejbql";
054:
055: /**
056: * Built-in parameter holding the value of the <code>javax.persistence.EntityManager</code> to be used for creating the query.
057: */
058: public static final String PARAMETER_JPA_ENTITY_MANAGER = "JPA_ENTITY_MANAGER";
059:
060: /**
061: * Built-in parameter (optional) holding the value of the query hints map.
062: * Each named/value pair will be set as query hint against the query.
063: */
064: public static final String PARAMETER_JPA_QUERY_HINTS_MAP = "JPA_QUERY_HINTS_MAP";
065:
066: private static final Object[] JPA_BUILTIN_PARAMETERS = {
067: PARAMETER_JPA_ENTITY_MANAGER, EntityManager.class,
068: PARAMETER_JPA_QUERY_HINTS_MAP, Map.class };
069:
070: public Object[] getBuiltinParameters() {
071: return JPA_BUILTIN_PARAMETERS;
072: }
073:
074: /**
075: * Property specifying the number of result rows to be retrieved at once.
076: * <p/>
077: * Result pagination is implemented by <code>javax.persistence.Query.setFirstResult()</code> and <code>javax.persistence.Query.setMaxResults()</code>.
078: * <p/>
079: * By default, all the rows are retrieved (no result pagination is performed).
080: */
081: public static final String PROPERTY_JPA_QUERY_PAGE_SIZE = JRProperties.PROPERTY_PREFIX
082: + "ejbql.query.page.size";
083:
084: /**
085: * Property specifying the prefix for EJBQL query hints.
086: */
087: public static final String PROPERTY_JPA_QUERY_HINT_PREFIX = JRProperties.PROPERTY_PREFIX
088: + "ejbql.query.hint.";
089:
090: public JRQueryExecuter createQueryExecuter(JRDataset dataset,
091: Map parameters) throws JRException {
092: return new JRJpaQueryExecuter(dataset, parameters);
093: }
094:
095: /**
096: * Returns <code>true</code> for all parameter types.
097: */
098: public boolean supportsQueryParameterType(String className) {
099: return true;
100: }
101: }
|