/** * */ public JRJpaQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parameters ) { super(jasperReportsContext, dataset, parameters); em = (EntityManager)getParameterValue(JRJpaQueryExecuterFactory.PARAMETER_JPA_ENTITY_MANAGER); reportMaxCount = (Integer)getParameterValue(JRParameter.REPORT_MAX_COUNT); if (em == null) { log.warn("The supplied javax.persistence.EntityManager object is null."); } parseQuery(); }
/** * */ public JaxenXPathQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); document = (Document) getParameterValue(JaxenXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT); documentBuilderFactory = (DocumentBuilderFactory) getParameterValue( JaxenXPathQueryExecuterFactory.PARAMETER_DOCUMENT_BUILDER_FACTORY, true); namespacesMap = (Map<String, String>) getParameterValue( JaxenXPathQueryExecuterFactory.PARAMETER_XML_NAMESPACE_MAP, true); if (document == null) { log.warn("The supplied org.w3c.dom.Document object is null."); } parseQuery(); }
/** * */ public XalanXPathQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); document = (Document) getParameterValue(XalanXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT); documentBuilderFactory = (DocumentBuilderFactory) getParameterValue( XalanXPathQueryExecuterFactory.PARAMETER_DOCUMENT_BUILDER_FACTORY, true); namespacesMap = (Map<String, String>) getParameterValue( XalanXPathQueryExecuterFactory.PARAMETER_XML_NAMESPACE_MAP, true); if (document == null) { log.warn("The supplied org.w3c.dom.Document object is null."); } parseQuery(); }
/** * */ public JRHibernateQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parameters ) { super(jasperReportsContext, dataset, parameters); session = (Session) getParameterValue(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_SESSION); reportMaxCount = (Integer) getParameterValue(JRParameter.REPORT_MAX_COUNT); isClearCache = getPropertiesUtil().getBooleanProperty(dataset, JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_CLEAR_CACHE, false); if (session == null) { log.warn("The supplied org.hibernate.Session object is null."); } parseQuery(); }
/** * Binds values for all the query parameters. */ protected void setParameters() { List<String> parameterNames = getCollectedParameterNames(); if (!parameterNames.isEmpty()) { Set<String> namesSet = new HashSet<String>(); for (Iterator<String> iter = parameterNames.iterator(); iter.hasNext();) { String parameterName = iter.next(); if (namesSet.add(parameterName)) { JRValueParameter parameter = getValueParameter(parameterName); setParameter(parameter); } } } }
@Override protected ClauseFunctionParameterHandler createParameterHandler(JRQueryClauseContext queryContext, String clauseId, String parameterName, boolean left) { JRValueParameter valueParameter = queryContext.getValueParameter(parameterName); Object value = valueParameter.getValue(); if (Date.class.isAssignableFrom(valueParameter.getValueClass()) || value instanceof Date) { // treat as regular parameter return new DefaultClauseFunctionParameterHandler(queryContext, parameterName, value); } if (value != null && !(value instanceof DateRange)) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_UNSUPPORTED_PARAMETER_TYPE, new Object[]{parameterName, clauseId, value.getClass().getName()}); } boolean useRangeStart = left ? isLeftClosed(clauseId) : !isRightClosed(clauseId); return new DateRangeParameterHandler(queryContext, parameterName, (DateRange) value, useRangeStart); }
/** * */ public JRMondrianQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); connection = (Connection) getParameterValue(JRMondrianQueryExecuterFactory.PARAMETER_MONDRIAN_CONNECTION); if (connection == null) { log.warn("The supplied mondrian.olap.Connection object is null."); } parseQuery(); }
@Override public List<JRDesignField> getFields(DataAdapterService con, JasperReportsConfiguration jConfig, JRDataset jDataset) throws JRException, UnsupportedOperationException { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("REPORT_PARAMETERS_MAP", new HashMap<String, Object>()); try { //Here there is the password of the connection con.contributeParameters(parameters); } catch (JRException e) { e.printStackTrace(); } ParameterUtil.setParameters(jConfig, jDataset, parameters); parameters.put(JRParameter.REPORT_MAX_COUNT, 2); Map<String,? extends JRValueParameter> tmpMap = ParameterUtil.convertMap(parameters, jDataset); JRXmlaQueryExecuter qe = new JRXmlaQueryExecuter(jConfig, jDataset, tmpMap); JROlapResult result = qe.getResult(); return OlapFieldsProviderSupport.getFieldsFromResult(result); }
@Override public List<JRDesignField> getFields(DataAdapterService con, JasperReportsConfiguration jConfig, JRDataset jDataset) throws JRException, UnsupportedOperationException { Map<String, Object> parameters = new HashMap<String, Object>(); con.contributeParameters(parameters); ParameterUtil.setParameters(jConfig, jDataset, parameters); parameters.put(JRParameter.REPORT_MAX_COUNT, 0); // JasperReports query executer instances require // REPORT_PARAMETERS_MAP parameter to be defined and not null Map<String, JRValueParameter> tmpMap = ParameterUtil.convertMap(parameters, jDataset); tmpMap.put(JRParameter.REPORT_PARAMETERS_MAP, new SimpleValueParameter(new HashMap<String, JRValueParameter>())); JRMondrianQueryExecuter qe = new JRMondrianQueryExecuter(jConfig, jDataset, tmpMap); qe.createDatasource(); JRMondrianResult result = new JRMondrianResult(qe.getResult()); return OlapFieldsProviderSupport.getFieldsFromResult(result); }
public static Map<String, JRValueParameter> convertMap(JRDataset dataset, Map<String, ?> inmap) { Map<String, JRValueParameter> outmap = new HashMap<String, JRValueParameter>(); for (String key : inmap.keySet()) { SimpleValueParameter svp = new SimpleValueParameter(inmap.get(key)); // Let's set the correct class name for this parameter... for (JRParameter p : dataset.getParameters() ) { if (p.getName() != null && p.getName().equals(key)) { svp.setValueClassName( p.getValueClassName()); break; } } outmap.put(key, svp); } return outmap; }
protected Class<?> determineParameterType(JRClauseTokens clauseTokens, JRQueryClauseContext queryContext, int parameterPosition) { String parameterName = clauseTokens.getToken(parameterPosition); if (parameterName == null) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_QUERY_PARAMETER_TYPE_SELECTOR_CLAUSE_IMPLEMENTATION_NOT_FOUND, new Object[]{parameterPosition, clauseTokens.getClauseId()}); } // the method throws an exception if it doesn't find the parameter, // so we don't have to handle that case here JRValueParameter parameter = queryContext.getValueParameter(parameterName); Class<?> parameterType; Object parameterValue = parameter.getValue(); if (parameterValue == null) { // if we don't have a value, use the declared type parameterType = parameter.getValueClass(); } else { // use the actual value parameterType = parameterValue.getClass(); } if (log.isDebugEnabled()) { log.debug("query clause parameter " + parameterName + " at position " + parameterPosition + " has type " + parameterType.getName()); } return parameterType; }
/** * */ public JsonQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parameters ) throws JRException { return new JRXlsxQueryExecuter(jasperReportsContext, dataset, parameters); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parameters ) throws JRException { return new JRXPathQueryExecuter(jasperReportsContext, dataset, parameters); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parameters ) throws JRException { return new JRJpaQueryExecuter(jasperReportsContext, dataset, parameters); }
/** * */ protected JRAbstractQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parametersMap ) { this.jasperReportsContext = jasperReportsContext; this.propertiesUtil = JRPropertiesUtil.getInstance(jasperReportsContext); this.dataset = dataset; this.parametersMap = parametersMap; queryString = ""; queryParameters = new ArrayList<QueryParameterEntry>(); }
/** * */ protected boolean parameterHasValue(String parameter) { JRValueParameter reportParametersMap = getValueParameter(JRParameter.REPORT_PARAMETERS_MAP, false); @SuppressWarnings("unchecked") Map<String,Object> parametersMap = (Map<String,Object>)reportParametersMap.getValue(); return parametersMap.containsKey(parameter); }
/** * Return a value parameter from the parameters map. * * @param parameterName the parameter name * @param ignoreMissing if <code>true</code>, the method will return null for non existing parameters; * otherwise, an exception will be thrown if the parameter does not exist * @return the parameter */ protected JRValueParameter getValueParameter(String parameterName, boolean ignoreMissing) { JRValueParameter parameter = parametersMap.get(parameterName); if (parameter == null && !ignoreMissing) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_PARAMETER_NOT_FOUND, new Object[]{parameterName}); } return parameter; }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parameters ) throws JRException { return new JsonQueryExecuter(jasperReportsContext, dataset, parameters); }
/** * */ public JRXPathQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); parseQuery(); }
/** * */ protected ExcelQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parameters ) throws JRException { return createQueryExecuter(dataset, parameters); }
protected void setStatementParameter(int parameterIndex, String parameterName) throws SQLException { JRValueParameter parameter = getValueParameter(parameterName); Class<?> clazz = parameter.getValueClass(); Object parameterValue = parameter.getValue(); if (log.isDebugEnabled()) { log.debug("Parameter #" + parameterIndex + " (" + parameterName + " of type " + clazz.getName() + "): " + parameterValue); } setStatementParameter(parameterIndex, clazz, parameterValue, parameter); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parameters ) throws JRException { return new JRCsvQueryExecuter(jasperReportsContext, dataset, parameters); }
/** * */ protected XlsQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parameters ) throws JRException { return new JaxenXPathQueryExecuter(jasperReportsContext, dataset, parameters); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parameters ) throws JRException { return new JsonQLQueryExecuter(jasperReportsContext, dataset, parameters); }
/** * @deprecated Replaced by {@link #createQueryExecuter(JasperReportsContext, JRDataset, Map)}. */ @Override public final JRQueryExecuter createQueryExecuter( JRDataset dataset, Map<String, ? extends JRValueParameter> parameters ) throws JRException { return createQueryExecuter(DefaultJasperReportsContext.getInstance(), dataset, parameters); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parameters ) throws JRException { return new ExcelQueryExecuter(jasperReportsContext, dataset, parameters); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parameters ) throws JRException { return new JRHibernateQueryExecuter(jasperReportsContext, dataset, parameters); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parameters ) throws JRException { return new JRJdbcQueryExecuter(jasperReportsContext, dataset, parameters); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parameters ) throws JRException { return new XalanXPathQueryExecuter(jasperReportsContext, dataset, parameters); }
/** * */ protected JRCsvQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); }
/** * */ public AbstractJsonQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); parseQuery(); }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parameters ) throws JRException { return new XlsQueryExecuter(jasperReportsContext, dataset, parameters); }
/** * */ protected JRXlsxQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); }
/** * */ protected AbstractXlsQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); }
/** * */ public JsonQLQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parametersMap ) { super(jasperReportsContext, dataset, parametersMap); }
/** * Binds a parameter value to a query parameter. * * @param parameter the report parameter */ protected void setParameter(JRValueParameter parameter) { String hqlParamName = getHqlParameterName(parameter.getName()); Class<?> clazz = parameter.getValueClass(); Object parameterValue = parameter.getValue(); if (log.isDebugEnabled()) { log.debug("Parameter " + hqlParamName + " of type " + clazz.getName() + ": " + parameterValue); } Type type = hibernateTypeMap.get(clazz); if (type != null) { query.setParameter(hqlParamName, parameterValue, type); } else if (Collection.class.isAssignableFrom(clazz)) { query.setParameterList(hqlParamName, (Collection<?>) parameterValue); } else { if (session.getSessionFactory().getClassMetadata(clazz) != null) //param type is a hibernate mapped entity { query.setEntity(hqlParamName, parameterValue); } else //let hibernate try to guess the type { query.setParameter(hqlParamName, parameterValue); } } }
@Override public JRQueryExecuter createQueryExecuter( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String, ? extends JRValueParameter> parameters ) throws JRException { return factory.createQueryExecuter(dataset, parameters); }