IF Condition inside queryString Tag

By: swami - shakai2k
IF Condition inside queryString Tag
2002-10-02 16:42
Hi All

I want to do a IF Condition inside the queryString tag based upon the Parameters that I receive, to deceide upon which query must be sent across for building the final PDF report.

Thanks

Swami


By: Teodor Danciu - teodord
RE: IF Condition inside queryString Tag
2002-10-04 02:00

Hi,

You can only make that IF in your parent application,
outside JasperReports.

You decide what you query is before sending
it as a parameter.

That's seems to be the only way,
at least for the moment.

Thank you,
Teodor



By: Mike - fallofrome
RE: IF Condition inside queryString Tag
2002-10-04 17:41
I just did a quick and dirty implementation of query switching withing an XML -- note: this requires changing the DTD to accept multiple queryString elements that now have a name attribute.
<p>
Basically you can now have multiple queryString elements, each with a name=X or name=Y value. When you call JasperReport, you can pass a parameter called 'QUERY_KEY' with the value as 'X' or 'Y' and have it use the right query. This is obviously helpful as you can reuse the same template for multiple queries that may have different where clauses or parameterizations, but return the same structured ResultSet.
<p>
There may be errors (I cheesed out and just commented out the code in the Verifier), but here's a very dirty dump of the changes I made...
<p>

JRXmlLoader

CHANGED:

digester.addSetNext("jasperReport/queryString", "setQuery", "dori.jasper.engine.JRQuery");
TO:

digester.addSetNext("jasperReport/queryString", "addQuery", "dori.jasper.engine.JRQuery");


JRQueryFactory

ADDED:
JRXmlLoader xmlLoader = (JRXmlLoader)digester.peek(digester.getCount() - 1);

if (atts.getValue("name") == null || atts.getValue("name").trim().equals(""))
{
xmlLoader.addError(new Exception("Query name missing."));
}

query.setName(atts.getValue("name"));
ABOVE:

return query;


JRBaseQuery

ADDED:

protected String name = null;

public void setName( String name )
{
this.name = name;
}

public String getName()
{
return this.name;
}


BELOW:

protected JRBaseQuery()
{
}



JasperDesign

CHANGED:


public void setQuery(JRQuery query)
{
this.query = query;
}

TO:

public void addQuery(JRQuery query)
{
this.queryMap.put( query.getName(), query );
}


JRBaseReport:

CHANGED:

protected JRQuery query = null;

TO:

protected Map queryMap = new HashMap();


CHANGED:

query = JRBaseObjectFactory.getQuery(report.getQuery(), baseObjectsMap);
TO:

Map jrqueryMap = report.getQueryMap();
if (jrqueryMap != null && jrqueryMap.size() > 0)
{
queryMap = new HashMap();
for (Iterator i=jrqueryMap.entrySet().iterator(); i.hasNext(); )
{
Map.Entry e = (Map.Entry) i.next();
JRQuery query = (JRQuery) e.getValue();
query = JRBaseObjectFactory.getQuery(query, baseObjectsMap);
queryMap.put( query.getName(), query );
}
}



CHANGED:

public JRQuery getQuery()
{
return this.query;
}

TO:

public Map getQueryMap()
{
return this.queryMap;
}



JRQuery

ADDED:

public String getName();



JRReport

CHANGED:

public JRQuery getQuery();

TO:

public java.util.Map getQueryMap();


JRBaseFiller

CHANGED:

protected JRQuery query = null;

TO:

protected Map queryMap = new HashMap();

CHANGED:

this.query = jasperReport.getQuery();

TO:

this.queryMap = jasperReport.getQueryMap();



ADDED:

JRQuery query = null;
String queryKey = (String) parameters.get( "QUERY_KEY" );
if (queryKey != null)
query = (JRQuery) queryMap.get( queryKey );
else
query = (JRQuery) queryMap.values().iterator().next();



BELOW:
parameters.put("REPORT_CONNECTION", conn);



JRVerifier

COMMENT OUT INTERNALS FOR:

private void verifyQuery() throws JRException


JRXmlWriter

CHANGE:

if(report.getQuery() != null)
{
this.writeQuery(report.getQuery());
}

TO:

if(report.getQueryMap() != null)
{
this.writeQueryMap(report.getQueryMap());
}

CHANGE:

/**
*
*/
private void writeQuery(JRQuery query)
{
this.sbuffer.append("\t<queryString><![CDATA[");

this.sbuffer.append(query.getText());

this.sbuffer.append("]]></queryString>\n");
}

TO:

private void writeQueryMap(Map queryMap)
{
for (Iterator i=queryMap.entrySet().iterator(); i.hasNext(); ) {
Map.Entry e = (Map.Entry) i.next();
JRQuery q = (JRQuery) e.getValue();
this.sbuffer.append("\t<queryString name=\"" + (String) e.getKey() + "\"><![CDATA[");
this.sbuffer.append(q.getText());
this.sbuffer.append("]]></queryString>\n");
}
}
2001 JI Open Discussion's picture
Joined: Aug 10 2006 - 3:26am
Last seen: 17 years 1 month ago

0 Answers:

No answers yet
Feedback
randomness