used cached resultset for reporting in places (wip)
This commit is contained in:
+11
-24
@@ -5,16 +5,12 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import javax.sql.rowset.CachedRowSet;
|
import javax.sql.rowset.CachedRowSet;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.StreamingOutput;
|
import javax.ws.rs.core.StreamingOutput;
|
||||||
@@ -25,7 +21,6 @@ import org.mifosng.platform.api.data.ResultsetColumnHeader;
|
|||||||
import org.mifosng.platform.api.data.ResultsetDataRow;
|
import org.mifosng.platform.api.data.ResultsetDataRow;
|
||||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||||
import org.mifosng.platform.exceptions.ReportNotFoundException;
|
import org.mifosng.platform.exceptions.ReportNotFoundException;
|
||||||
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
|
||||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||||
import org.mifosng.platform.user.domain.AppUser;
|
import org.mifosng.platform.user.domain.AppUser;
|
||||||
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
|
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
|
||||||
@@ -54,18 +49,15 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
|||||||
private final static Logger logger = LoggerFactory
|
private final static Logger logger = LoggerFactory
|
||||||
.getLogger(ReadReportingServiceImpl.class);
|
.getLogger(ReadReportingServiceImpl.class);
|
||||||
|
|
||||||
private final DataSource dataSource;
|
|
||||||
private Boolean noPentaho = false;
|
private Boolean noPentaho = false;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ReadReportingServiceImpl(final PlatformSecurityContext context,
|
public ReadReportingServiceImpl(final PlatformSecurityContext context) {
|
||||||
final TenantAwareRoutingDataSource dataSource) {
|
|
||||||
// kick off pentaho reports server
|
// kick off pentaho reports server
|
||||||
ClassicEngineBoot.getInstance().start();
|
ClassicEngineBoot.getInstance().start();
|
||||||
noPentaho = false;
|
noPentaho = false;
|
||||||
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.dataSource = dataSource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -261,30 +253,25 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
|||||||
public String getReportType(String reportName) {
|
public String getReportType(String reportName) {
|
||||||
String sql = "SELECT ifnull(report_type,'') as report_type FROM `stretchy_report` where report_name = '"
|
String sql = "SELECT ifnull(report_type,'') as report_type FROM `stretchy_report` where report_name = '"
|
||||||
+ reportName + "'";
|
+ reportName + "'";
|
||||||
String reportType = "";
|
|
||||||
|
|
||||||
Connection db_connection = null;
|
sql = wrapSQL(sql);
|
||||||
Statement db_statement = null;
|
|
||||||
ResultSet rs = null;
|
String sqlErrorMsg = "Report Name: " + reportName + " Sql: " + sql;
|
||||||
|
CachedRowSet rs = genericDataService.getCachedResultSet(sql,
|
||||||
|
sqlErrorMsg);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db_connection = dataSource.getConnection();
|
|
||||||
db_statement = db_connection.createStatement();
|
|
||||||
rs = db_statement.executeQuery(sql);
|
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
reportType = rs.getString("report_type");
|
return rs.getString("report_type");
|
||||||
} else {
|
|
||||||
throw new ReportNotFoundException(sql);
|
|
||||||
}
|
}
|
||||||
|
throw new ReportNotFoundException(sql);
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PlatformDataIntegrityException("error.msg.sql.error",
|
throw new PlatformDataIntegrityException("error.msg.sql.error",
|
||||||
e.getMessage(), "Report Name: " + reportName + " Sql: "
|
e.getMessage(), sqlErrorMsg);
|
||||||
+ sql);
|
|
||||||
} finally {
|
|
||||||
genericDataService.dbClose(db_statement, db_connection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return reportType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user