Created
December 5, 2016 22:18
-
-
Save khaosans/0ee0e49b9b6ee2b5ae2e0b7aee861f3a to your computer and use it in GitHub Desktop.
birtwork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jamasoftware.contour.report.service.impl.helper; | |
import com.jamasoftware.contour.api.exception.ContourRuntimeException; | |
import com.jamasoftware.contour.view.birt.BirtViewConstants; | |
import org.apache.log4j.Logger; | |
import org.hibernate.jdbc.Work; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import java.io.OutputStream; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
import java.util.Map; | |
public class BirtWork { | |
@Autowired | |
private JamaBirtRenderTask jamaBirtRenderTask; | |
private static Logger logger = Logger.getLogger(BirtTransactionCallback.class); | |
public Work getWork(Map<String, Object> reportParameterModel, OutputStream outputStream) { | |
return new Work() { | |
@Override | |
public void execute(Connection connection) throws SQLException { | |
logger.debug("A BIRT Transaction has started"); | |
long start = System.currentTimeMillis(); | |
String driver = "com.mysql.jdbc.Driver"; | |
String url="jdbc:mysql://localhost/jama_test2352?useUnicode=true&characterEncoding=UTF8"; | |
//String url = "jdbc\\:mysql\\://localhost/jama1111?useUnicode\\=true&characterEncoding\\=UTF8"; | |
String username = "root"; | |
String password = ""; | |
try { | |
Class.forName(driver); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
} | |
Connection conn = DriverManager.getConnection(url, username, password); | |
JamaBirtDatabaseConnection jamaConnection = new JamaBirtDatabaseConnection(conn); | |
reportParameterModel.put(BirtViewConstants.BIRT_CONNECTION, jamaConnection); | |
reportParameterModel.put(BirtViewConstants.BIRT_CONNECTION_CLOSE_AFTER_USE, Boolean.FALSE); | |
try { | |
jamaBirtRenderTask.renderToStream(reportParameterModel, outputStream); | |
} catch (Exception e) { | |
throw new ContourRuntimeException("An error occurred while attempting to render a BIRT report in HTML", e); | |
} | |
String transactionTime = String.valueOf((System.currentTimeMillis() - start) / 1000 / 60); | |
logger.debug("A BIRT report transaction has completed in [" + transactionTime + " min]"); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment