com.github.exerrk.engine.query.JRHibernateQueryExecuterFactory Maven / Gradle / Ivy
The newest version!
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2016 TIBCO Software Inc. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JasperReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JasperReports. If not, see .
*/
package com.github.exerrk.engine.query;
import java.util.Map;
import com.github.exerrk.annotations.properties.Property;
import com.github.exerrk.annotations.properties.PropertyScope;
import com.github.exerrk.engine.JRDataset;
import com.github.exerrk.engine.JRException;
import com.github.exerrk.engine.JRPropertiesUtil;
import com.github.exerrk.engine.JRValueParameter;
import com.github.exerrk.engine.JasperReportsContext;
import com.github.exerrk.engine.util.Designated;
import com.github.exerrk.properties.PropertyConstants;
/**
* Query executer factory for HQL queries that uses Hibernate 3.
*
* The factory creates {@link com.github.exerrk.engine.query.JRHibernateQueryExecuter JRHibernateQueryExecuter}
* query executers.
*
* @author Lucian Chirita ([email protected])
*/
public class JRHibernateQueryExecuterFactory extends AbstractQueryExecuterFactory implements Designated
{
public static final String QUERY_EXECUTER_NAME = "com.github.exerrk.query.executer:HQL";
/**
* HQL query language.
*/
public static final String QUERY_LANGUAGE_HQL = "hql";
/**
* Built-in parameter holding the value of the Hibernate session to be used for creating the query.
*/
public final static String PARAMETER_HIBERNATE_SESSION = "HIBERNATE_SESSION";
/**
* Built-in parameter used for collection filter queries.
*
* The value of this parameter will be used as the collection to filter using the query.
*/
public final static String PARAMETER_HIBERNATE_FILTER_COLLECTION = "HIBERNATE_FILTER_COLLECTION";
private final static Object[] HIBERNATE_BUILTIN_PARAMETERS = {
//passing the parameter type as class name and not class in order to
//avoid a dependency on Hibernate classes so that reports that have
//HQL queries would load even when Hibernate is not present
PARAMETER_HIBERNATE_SESSION, "org.hibernate.Session",
PARAMETER_HIBERNATE_FILTER_COLLECTION, "java.lang.Object",
};
/**
* Property specifying the query execution type.
*
* Possible values are:
*
* - list (default) - the query will be run by calling
org.hibernate.Query.list()
* - iterate - the query will be run by calling
org.hibernate.Query.iterate()
* - scroll - the query will be run by calling
org.hibernate.Query.scroll()
*
*/
@Property(
category = PropertyConstants.CATEGORY_DATA_SOURCE,
defaultValue = "list",
scopes = {PropertyScope.CONTEXT, PropertyScope.DATASET},
scopeQualifications = {JRHibernateQueryExecuterFactory.QUERY_EXECUTER_NAME},
sinceVersion = PropertyConstants.VERSION_1_2_0
)
public static final String PROPERTY_HIBERNATE_QUERY_RUN_TYPE = JRPropertiesUtil.PROPERTY_PREFIX + "hql.query.run.type";
/**
* Property specifying the number of result rows to be retrieved at once when the execution type is list.
*
* Result pagination is implemented by org.hibernate.Query.setFirstResult()
and org.hibernate.Query.setMaxResults()
.
*
* By default, all the rows are retrieved (no result pagination is performed).
*/
@Property(
category = PropertyConstants.CATEGORY_DATA_SOURCE,
defaultValue = "0",
scopes = {PropertyScope.CONTEXT, PropertyScope.DATASET},
scopeQualifications = {JRHibernateQueryExecuterFactory.QUERY_EXECUTER_NAME},
sinceVersion = PropertyConstants.VERSION_1_2_0,
valueType = Integer.class
)
public static final String PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE = JRPropertiesUtil.PROPERTY_PREFIX + "hql.query.list.page.size";
/**
* Property specifying whether hibernate session cache should be cleared between two consecutive fetches when using pagination.
*
* By default, the cache cleanup is not performed.
*
* @see com.github.exerrk.engine.query.JRHibernateQueryExecuterFactory#PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE
*/
@Property(
category = PropertyConstants.CATEGORY_DATA_SOURCE,
defaultValue = PropertyConstants.BOOLEAN_FALSE,
scopes = {PropertyScope.CONTEXT, PropertyScope.DATASET},
scopeQualifications = {JRHibernateQueryExecuterFactory.QUERY_EXECUTER_NAME},
sinceVersion = PropertyConstants.VERSION_1_3_1,
valueType = Boolean.class
)
public static final String PROPERTY_HIBERNATE_CLEAR_CACHE = JRPropertiesUtil.PROPERTY_PREFIX + "hql.clear.cache";
/**
* Property specifying whether field descriptions should be used to determine the mapping between the fields
* and the query return values.
*/
@Property(
category = PropertyConstants.CATEGORY_DATA_SOURCE,
defaultValue = PropertyConstants.BOOLEAN_TRUE,
scopes = {PropertyScope.CONTEXT, PropertyScope.DATASET},
scopeQualifications = {JRHibernateQueryExecuterFactory.QUERY_EXECUTER_NAME},
sinceVersion = PropertyConstants.VERSION_1_2_0,
valueType = Boolean.class
)
public static final String PROPERTY_HIBERNATE_FIELD_MAPPING_DESCRIPTIONS = JRPropertiesUtil.PROPERTY_PREFIX + "hql.field.mapping.descriptions";
/**
* Value of the {@link #PROPERTY_HIBERNATE_QUERY_RUN_TYPE PROPERTY_HIBERNATE_QUERY_RUN_TYPE} property
* corresponding to list execution type.
*/
public static final String VALUE_HIBERNATE_QUERY_RUN_TYPE_LIST = "list";
/**
* Value of the {@link #PROPERTY_HIBERNATE_QUERY_RUN_TYPE PROPERTY_HIBERNATE_QUERY_RUN_TYPE} property
* corresponding to iterate execution type.
*/
public static final String VALUE_HIBERNATE_QUERY_RUN_TYPE_ITERATE = "iterate";
/**
* Value of the {@link #PROPERTY_HIBERNATE_QUERY_RUN_TYPE PROPERTY_HIBERNATE_QUERY_RUN_TYPE} property
* corresponding to scroll execution type.
*/
public static final String VALUE_HIBERNATE_QUERY_RUN_TYPE_SCROLL = "scroll";
/**
* Returns an array containing the {@link #PARAMETER_HIBERNATE_SESSION PARAMETER_HIBERNATE_SESSION} and
* {@link #PARAMETER_HIBERNATE_FILTER_COLLECTION PARAMETER_HIBERNATE_FILTER_COLLECTION} parameters.
*/
@Override
public Object[] getBuiltinParameters()
{
return HIBERNATE_BUILTIN_PARAMETERS;
}
@Override
public JRQueryExecuter createQueryExecuter(
JasperReportsContext jasperReportsContext,
JRDataset dataset,
Map parameters
) throws JRException
{
return new JRHibernateQueryExecuter(jasperReportsContext, dataset, parameters);
}
/**
* Returns true
for all parameter types.
*/
@Override
public boolean supportsQueryParameterType(String className)
{
return true;
}
@Override
public String getDesignation()
{
return QUERY_EXECUTER_NAME;
}
}