Browse Source

Pull request #52: 10.0.16-0526号版本插件代码合并

Merge in PG/plugin-report-doc-demo from release/10.0 to persist/10.0

* commit 'd51e4171edd2c1b536ad0149e34a2e41401eb6ab':
  无JIRA任务 本地编译发现这个文档插件里面的类编译不通过了,纠正下,这个类在文档里没有用到,无需测试
  REPORT-50982 保存模板至数据库后,读取带参数面板的报表会报错空指针,不带参数面板报表可以读取成功
  REPORT-50963 优化程序数据集上层设计(abstracttabledata)
  rt
  REPORT-50963 新demo里面获取连接的逻辑跟老demo一致
  补一下简单程序数据集demo
  REPORT-50963 优化程序数据集上层设计(abstracttabledata),提交新demo
persist/10.0
Icey.Zhang 4 years ago
parent
commit
c974449e23
  1. 23
      src/main/java/com/fr/data/ParamTableDataDemo.java
  2. 29
      src/main/java/com/fr/data/SimpleArrayTableDataDemo.java
  3. 100
      src/main/java/com/fr/data/SimpleParamTableDataDemo.java
  4. 70
      src/main/java/com/fr/demo/NewReadFrmFromDatabase.java
  5. 2
      src/main/java/com/fr/demo/ReadfrmFromDatabase.java
  6. 9
      src/main/java/com/fr/function/ReportCheck.java

23
src/main/java/com/fr/data/ParamTableDataDemo.java

@ -2,11 +2,14 @@ package com.fr.data;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.file.DatasourceManager; import com.fr.file.DatasourceManager;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
@ -92,10 +95,11 @@ public class ParamTableDataDemo extends AbstractTableData {
// 保存得到的结果集 // 保存得到的结果集
valueList = new ArrayList(); valueList = new ArrayList();
// 下面开始建立数据库连接,按照刚才的SQL语句进行查询 // 下面开始建立数据库连接,按照刚才的SQL语句进行查询
// 根据连接名获取FR数据连接定义的数据连接,如果没有定义,也可以参考getConnection方法自己创建连接
com.fr.data.impl.Connection conn = DatasourceManager.getInstance().getConnection("FRDemo"); com.fr.data.impl.Connection conn = DatasourceManager.getInstance().getConnection("FRDemo");
Connection con = null;
try { try {
Connection con = conn.createConnection(); con = conn.createConnection();
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql); ResultSet rs = stmt.executeQuery(sql);
// 获得记录的详细信息,然后获得总列数 // 获得记录的详细信息,然后获得总列数
@ -118,7 +122,15 @@ public class ParamTableDataDemo extends AbstractTableData {
// 打印一共取到的数据行数量 // 打印一共取到的数据行数量
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
} }
} }
@ -133,14 +145,13 @@ public class ParamTableDataDemo extends AbstractTableData {
String url = "jdbc:sqlite:////Applications//FineReport10_325//webapps//webroot//help//FRDemo.db"; String url = "jdbc:sqlite:////Applications//FineReport10_325//webapps//webroot//help//FRDemo.db";
String username = ""; String username = "";
String password = ""; String password = "";
Connection con; Connection con = null;
try { try {
Class.forName(driverName); Class.forName(driverName);
con = DriverManager.getConnection(url, username, password); con = DriverManager.getConnection(url, username, password);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); FineLoggerFactory.getLogger().error(e.getMessage(), e);
return null;
} }
return con; return con;
} }

29
src/main/java/com/fr/data/SimpleArrayTableDataDemo.java

@ -0,0 +1,29 @@
package com.fr.data;
import java.util.ArrayList;
import java.util.List;
public class SimpleArrayTableDataDemo extends SimpleTableData {
/**
* 初始化列头
* @return
*/
@Override
public String[] initColumnNames() {
return new String[]{"Name", "Score"};
}
/**
* 加载行列数据
* @return
*/
@Override
public List<Object[]> loadData() {
ArrayList<Object[]> valueList = new ArrayList();
valueList.add(new Object[]{"Alex", 15});
valueList.add(new Object[]{"Helly", 22});
valueList.add(new Object[]{"Bobby", 99});
return valueList;
}
}

100
src/main/java/com/fr/data/SimpleParamTableDataDemo.java

@ -0,0 +1,100 @@
package com.fr.data;
import com.fr.file.ConnectionConfig;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ParameterProvider;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
/**
* 带参数的程序数据集Demo 跟ParamTableDataDemo功能一样但实现更简单
*
* @author fanruan
*/
public class SimpleParamTableDataDemo extends SimpleTableData {
@Override
public String[] initColumnNames() {
String[] columnNames = new String[10];
for (int i = 0; i < 10; i++) {
columnNames[i] = "column#" + i;
}
return columnNames;
}
@Override
public List<Object[]> loadData() {
// 保存得到的数据库表名
String tableName = ((ParameterProvider) (parameters.get().toArray())[0]).getValue().toString();
// 构造SQL语句,并打印出来
String sql = "select * from " + tableName;
FineLoggerFactory.getLogger().info("Query SQL of ParamTableDataDemo: \n" + sql);
// 保存得到的结果集
ArrayList<Object[]> valueList = new ArrayList();
// 下面开始建立数据库连接,按照刚才的SQL语句进行查询
// 根据连接名获取FR数据连接定义的数据连接,如果没有定义,也可以参考getConnection方法自己创建连接
com.fr.data.impl.Connection conn = ConnectionConfig.getInstance().getConnection("FRDemo");
Connection con = null;
try {
con = conn.createConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
// 获得记录的详细信息,然后获得总列数
ResultSetMetaData rsmd = rs.getMetaData();
int colNum = rsmd.getColumnCount();
// 用对象保存数据
Object[] objArray = null;
while (rs.next()) {
objArray = new Object[colNum];
for (int i = 0; i < colNum; i++) {
objArray[i] = rs.getObject(i + 1);
}
// 在valueList中加入这一行数据
valueList.add(objArray);
}
// 释放数据库资源
rs.close();
stmt.close();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
try {
if (con != null) {
con.close();
}
} catch (SQLException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
return valueList;
}
/**
* 获取数据库连接 driverName和 url 可以换成您需要的
*
* @return Connection
*/
private Connection getConnection() {
String driverName = "org.sqlite.JDBC";
String url = "jdbc:sqlite:////Applications//FineReport10_325//webapps//webroot//help//FRDemo.db";
String username = "";
String password = "";
Connection con = null;
try {
Class.forName(driverName);
con = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return con;
}
}

70
src/main/java/com/fr/demo/NewReadFrmFromDatabase.java

@ -0,0 +1,70 @@
package com.fr.demo;
import com.fr.data.core.db.DBUtils;
import com.fr.web.weblet.DBFormlet;
import com.fr.form.main.Form;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import com.fr.log.FineLoggerFactory;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Map;
public class NewReadFrmFromDatabase extends DBFormlet {
@Override
public Form createForm(HttpServletRequest reportletRequest) {
String name = reportletRequest.getParameter("reportname");
return createForm(name);
}
@Override
public Form createForm(String reportName) {
Form form = new Form();
Connection connection = null;
try {
connection = getConnection();
// 从数据库中读模板
String sql = "select frm from report where frmname = '" + reportName
+ "'";
Statement smt = connection.createStatement();
ResultSet rs = smt.executeQuery(sql);
while (rs.next()) {
Blob blob = rs.getBlob(1);
FineLoggerFactory.getLogger().info(blob.toString());
InputStream ins = blob.getBinaryStream();
form.readStream(ins);
return form;
}
} catch (Exception e) {
e.printStackTrace();
}finally {
DBUtils.closeConnection(connection);
}
return null;
}
private static Connection getConnection() throws ClassNotFoundException, SQLException {
// 定义数据连接(根据你实际数据库信息进行修改)
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String pass = "123456";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, pass);
return conn;
}
@Override
public void setParameterMap(Map<String, Object> arg0) {
// TODO Auto-generated method stub
}
}

2
src/main/java/com/fr/demo/ReadfrmFromDatabase.java

@ -31,7 +31,7 @@ public class ReadfrmFromDatabase extends Formlet {
Class.forName(driver); Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, pass); Connection conn = DriverManager.getConnection(url, user, pass);
// 从数据库中读模板 // 从数据库中读模板
String sql = "select B from report where A = '" + name String sql = "select frm from report where frmname = '" + name
+ "'"; + "'";
Statement smt = conn.createStatement(); Statement smt = conn.createStatement();
ResultSet rs = smt.executeQuery(sql); ResultSet rs = smt.executeQuery(sql);

9
src/main/java/com/fr/function/ReportCheck.java

@ -1,13 +1,11 @@
// 自定义函数实现表间校验 // 自定义函数实现表间校验
package com.fr.function; package com.fr.function;
import java.util.HashMap;
import com.fr.base.ResultFormula; import com.fr.base.ResultFormula;
import com.fr.base.operator.common.CommonOperator; import com.fr.base.operator.common.CommonOperator;
import com.fr.chart.activator.ChartBaseActivator; import com.fr.chart.activator.ChartBaseActivator;
import com.fr.config.activator.BaseDBActivator; import com.fr.config.activator.BaseDBActivator;
import com.fr.config.activator.ConfigurationActivator; import com.fr.config.activator.ConfigurationActivator;
import com.fr.data.impl.config.activator.RestrictionActivator;
import com.fr.env.operator.CommonOperatorImpl; import com.fr.env.operator.CommonOperatorImpl;
import com.fr.io.TemplateWorkBookIO; import com.fr.io.TemplateWorkBookIO;
import com.fr.json.JSONArray; import com.fr.json.JSONArray;
@ -17,15 +15,18 @@ import com.fr.main.workbook.ResultWorkBook;
import com.fr.module.Module; import com.fr.module.Module;
import com.fr.module.tool.ActivatorToolBox; import com.fr.module.tool.ActivatorToolBox;
import com.fr.report.ReportActivator; import com.fr.report.ReportActivator;
import com.fr.report.RestrictionActivator;
import com.fr.report.cell.CellElement; import com.fr.report.cell.CellElement;
import com.fr.report.module.ReportBaseActivator; import com.fr.report.module.ReportBaseActivator;
import com.fr.report.report.ResultReport; import com.fr.report.report.ResultReport;
import com.fr.script.AbstractFunction; import com.fr.script.AbstractFunction;
import com.fr.stable.WriteActor; import com.fr.stable.WriteActor;
import com.fr.store.StateServerActivator; import com.fr.store.StateServiceActivator;
import com.fr.workspace.simple.SimpleWork; import com.fr.workspace.simple.SimpleWork;
import com.fr.write.cal.WB; import com.fr.write.cal.WB;
import java.util.HashMap;
public class ReportCheck extends AbstractFunction { public class ReportCheck extends AbstractFunction {
private static HashMap wMap = new HashMap(); private static HashMap wMap = new HashMap();
@ -39,7 +40,7 @@ public class ReportCheck extends AbstractFunction {
// 定义报表运行环境,用于执行报表 // 定义报表运行环境,用于执行报表
Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(), Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(),
new ConfigurationActivator(), new ConfigurationActivator(),
new StateServerActivator(), new StateServiceActivator(),
new ReportBaseActivator(), new ReportBaseActivator(),
new RestrictionActivator(), new RestrictionActivator(),
new ReportActivator(), new ReportActivator(),

Loading…
Cancel
Save