/** * */ protected JRBaseQuery getQuery(JRQuery query) { JRBaseQuery baseQuery = null; if (query != null) { baseQuery = (JRBaseQuery)get(query); if (baseQuery == null) { baseQuery = new JRBaseQuery(query, this); } } return baseQuery; }
/** * */ protected JRBaseQuery(JRQuery query, JRBaseObjectFactory factory) { factory.put(query, this); /* */ JRQueryChunk[] jrChunks = query.getChunks(); if (jrChunks != null && jrChunks.length > 0) { chunks = new JRQueryChunk[jrChunks.length]; for(int i = 0; i < chunks.length; i++) { chunks[i] = factory.getQueryChunk(jrChunks[i]); } } language = query.getLanguage(); }
/** * Parses the query and replaces the parameter clauses by the parameter values and * the parameters by the return value of {@link #getParameterReplacement(String) getParameterReplacement}. * */ protected void parseQuery() { parameterClauseStack = new HashSet<String>(); JRQuery query = dataset.getQuery(); if (query != null) { JRQueryChunk[] chunks = query.getChunks(); if (chunks != null && chunks.length > 0) { StringBuffer sbuffer = new StringBuffer(); for(int i = 0; i < chunks.length; i++) { JRQueryChunk chunk = chunks[i]; appendQueryChunk(sbuffer, chunk); } queryString = sbuffer.toString(); } } }
protected void copyConnectionParameter(Map<String,Object> parameterValues) { JRQuery query = dataset.getQuery(); if (query != null) { String language = query.getLanguage(); if (connectionExpression == null && (language.equals("sql") || language.equals("SQL")) && !parameterValues.containsKey(JRParameter.REPORT_CONNECTION)) { JRFillParameter connParam = expressionEvaluator.getFillDataset().getParametersMap().get(JRParameter.REPORT_CONNECTION); Connection connection = (Connection) connParam.getValue(); parameterValues.put(JRParameter.REPORT_CONNECTION, connection); } } }
protected void copyConnectionParameter(Map<String, Object> parameterValues) { // copy the main report's connection parameter to the table subreport // this is done for consistency with subdataset runs if (!parameterValues.containsKey(JRParameter.REPORT_CONNECTION) && getConnectionExpression() == null) { JRQuery query = tableReport.getQuery(); if (query != null) { String language = query.getLanguage(); if (language.equals("sql") || language.equals("SQL")) { Connection connection = (Connection) filler.getParameterValuesMap().get( JRParameter.REPORT_CONNECTION); if (connection != null) { parameterValues.put(JRParameter.REPORT_CONNECTION, connection); } } } } }
public JRQuery getQuery() { JRQuery query = new JRBaseQuery() { /** * */ private static final long serialVersionUID = 1L; public JRQueryChunk[] getChunks() { return null; } public String getLanguage() { return "resourceQuery"; } public String getText() { return getQueryText(); } }; return query; }
/** * */ private void writeQuery(JRQuery query) throws IOException { writer.startElement(JRXmlConstants.ELEMENT_queryString); writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_language, query.getLanguage(), JRJdbcQueryExecuterFactory.QUERY_LANGUAGE_SQL); writer.writeCDATA(query.getText()); writer.closeElement(); }
/** * */ private void writeQuery( JRQuery query, String queryName) { if(query != null) { write( "JRDesignQuery " + queryName + " = new JRDesignQuery();\n"); write( queryName + ".setLanguage(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(query.getLanguage()), JRJdbcQueryExecuterFactory.QUERY_LANGUAGE_SQL); write( queryName + ".setText(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(query.getText())); flush(); } }
/** * */ protected JRQueryExecuter( JRQuery query, Map parameters, Map values ) { this.query = query; this.parametersMap = parameters; this.parameterValues = values; this.parseQuery(); }
/** * */ public static PreparedStatement getStatement( JRQuery query, Map parameters, Map values, Connection conn ) throws JRException { PreparedStatement pstmt = null; if( conn != null ) { JRQueryExecuter queryExecuter = new JRQueryExecuter( query, parameters, values ); pstmt = queryExecuter.getStatement( conn ); } return pstmt; }
public Object getPropertyValue(Object id) { JRDesignDataset jrDataset = (JRDesignDataset) getValue(); if (jrDataset == null) return null; if (id.equals(JRDesignDataset.PROPERTY_NAME)) return jrDataset.getName(); if (id.equals(JRDesignDataset.PROPERTY_QUERY)) { if (mQuery == null) { JRQuery jdq = jrDataset.getQuery(); mQuery = new MQuery(jdq, this); mQuery.setJasperConfiguration(getJasperConfiguration()); setChildListener(mQuery); } return mQuery; } if (id.equals(JRDesignDataset.PROPERTY_FILTER_EXPRESSION)) { return ExprUtil.getExpression(jrDataset.getFilterExpression()); } if (id.equals(JRDesignDataset.PROPERTY_SCRIPTLET_CLASS)) return jrDataset.getScriptletClass(); if (id.equals(PROPERTY_MAP)) { // to avoid duplication I remove it first JRPropertiesMap pmap = jrDataset.getPropertiesMap(); return pmap; } if (id.equals(JRDesignDataset.PROPERTY_WHEN_RESOURCE_MISSING_TYPE)) return whenResMissTypeD.getEnumValue(jrDataset.getWhenResourceMissingTypeValue()); if (id.equals(JRDesignDataset.PROPERTY_RESOURCE_BUNDLE)) return jrDataset.getResourceBundle(); return null; }
public Object getPropertyValue(Object id) { JRQuery jrQuery = (JRQuery) getValue(); if (jrQuery != null) { if (id.equals(JRDesignQuery.PROPERTY_TEXT)) return jrQuery.getText(); if (id.equals(JRDesignQuery.PROPERTY_LANGUAGE)) return jrQuery.getLanguage(); } return null; }
@Override public JRQuery getQuery() { return mainDataset.getQuery(); }
@Override public JRQuery getQuery() { return query; }
/** * */ private void verifyQuery(JRDesignDataset dataset) { JRQuery query = dataset.getQuery(); if (query != null) { String language = query.getLanguage(); QueryExecuterFactory queryExecuterFactory = null; if (language == null || language.length() == 0) { addBrokenRule("Query language not set.", query); } else { try { queryExecuterFactory = JRQueryExecuterUtils.getInstance(jasperReportsContext).getExecuterFactory(query.getLanguage()); } catch (JRException e1) { addBrokenRule("Query executer factory for " + language + " cannot be created.", query); } } JRQueryChunk[] chunks = query.getChunks(); if (chunks != null && chunks.length > 0) { Map<String, JRParameter> parametersMap = dataset.getParametersMap(); for(int j = 0; j < chunks.length; j++) { JRQueryChunk queryChunk = chunks[j]; switch (queryChunk.getType()) { case JRQueryChunk.TYPE_PARAMETER : { JRParameter parameter = parametersMap.get(queryChunk.getText()); if ( parameter == null ) { addBrokenRule("Query parameter not found : " + queryChunk.getText(), query); } else if (queryExecuterFactory != null) { String parameterType = null; try { parameterType = parameter.getValueClassName(); } catch (JRRuntimeException e) { // ignore, already added when the parameter got verified } if (parameterType != null && !queryExecuterFactory.supportsQueryParameterType(parameterType)) { addBrokenRule("Parameter type not supported in query : " + queryChunk.getText() + " class " + parameterType, query); } } break; } case JRQueryChunk.TYPE_PARAMETER_CLAUSE : { if (!parametersMap.containsKey(queryChunk.getText())) { addBrokenRule("Query parameter not found : " + queryChunk.getText(), query); } break; } case JRQueryChunk.TYPE_TEXT : default : { } } } } } }
@Override public JRQuery getQuery() { return tableSubdataset.getQuery(); }
public MQuery(JRQuery jrQuery, MDataset mdataset) { super(); this.mdataset = mdataset; setValue(jrQuery); }