You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by he...@apache.org on 2009/04/22 15:09:32 UTC
svn commit: r767507 - in /struts/struts2/trunk/plugins/jasperreports: pom.xml
src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java
Author: hermanns
Date: Wed Apr 22 13:09:32 2009
New Revision: 767507
URL: http://svn.apache.org/viewvc?rev=767507&view=rev
Log:
WWW-2884 Support for report JDBC connection
Modified:
struts/struts2/trunk/plugins/jasperreports/pom.xml
struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java
Modified: struts/struts2/trunk/plugins/jasperreports/pom.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/jasperreports/pom.xml?rev=767507&r1=767506&r2=767507&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/jasperreports/pom.xml (original)
+++ struts/struts2/trunk/plugins/jasperreports/pom.xml Wed Apr 22 13:09:32 2009
@@ -43,7 +43,7 @@
<dependency>
<groupId>jasperreports</groupId>
<artifactId>jasperreports</artifactId>
- <version>3.0.0</version>
+ <version>3.1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
Modified: struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java?rev=767507&r1=767506&r2=767507&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java (original)
+++ struts/struts2/trunk/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java Wed Apr 22 13:09:32 2009
@@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
+import java.sql.Connection;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -113,6 +114,11 @@
* encryption and set the user password to a string known to the report creator.
* </li>
* <p/>
+ * <li>
+ * <b>connection</b> - (2.1.7+) JDBC Connection which can be passed to the
+ * report instead of dataSource
+ * </li>
+ * <p/>
* </ul>
* <p/>
* <p>
@@ -154,6 +160,12 @@
protected String timeZone;
/**
+ * Connection which can be passed to the report
+ * instead od dataSource.
+ */
+ protected String connection;
+
+ /**
* Names a report parameters map stack value, allowing
* additional report parameters from the action.
*/
@@ -234,6 +246,14 @@
this.exportParameters = exportParameters;
}
+ public String getConnection() {
+ return connection;
+ }
+
+ public void setConnection(String connection) {
+ this.connection = connection;
+ }
+
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
// Will throw a runtime exception if no "datasource" property. TODO Best place for that is...?
initializeProperties(invocation);
@@ -263,7 +283,11 @@
// Construct the data source for the report.
ValueStack stack = invocation.getStack();
- ValueStackDataSource stackDataSource = new ValueStackDataSource(stack, dataSource);
+ ValueStackDataSource stackDataSource = null;
+
+ Connection conn = (Connection) stack.findValue(connection);
+ if (conn == null)
+ stackDataSource = new ValueStackDataSource(stack, dataSource);
// Determine the directory that the report file is in and set the reportDirectory parameter
// For WW 2.1.7:
@@ -298,7 +322,10 @@
// Fill the report and produce a print object
try {
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(systemId);
- jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, stackDataSource);
+ if (conn == null)
+ jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, stackDataSource);
+ else
+ jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
} catch (JRException e) {
LOG.error("Error building report for uri " + systemId, e);
throw new ServletException(e.getMessage(), e);
@@ -410,12 +437,13 @@
* @throws Exception on initialization error.
*/
private void initializeProperties(ActionInvocation invocation) throws Exception {
- if (dataSource == null) {
+ if (dataSource == null && connection == null) {
String message = "No dataSource specified...";
LOG.error(message);
throw new RuntimeException(message);
}
- dataSource = conditionalParse(dataSource, invocation);
+ if (dataSource != null)
+ dataSource = conditionalParse(dataSource, invocation);
format = conditionalParse(format, invocation);
if (StringUtils.isEmpty(format)) {