Overview
Application Scenarios
You may need to use custom types of data sources for data analysis and dashboard display.
Functions
You can establish a remote connection between FineBI and FineReport to use customized data sources, like program dataset, which allows the FineBI engine to read the defined data sources for data analysis and dashboard creation.

Example
This document takes the built-in template execution log of FineBI as an example.
Defining Data Source
Click to download the template execution log file: ExecuteLog.zip
Click to download the platform management log file: OperateLog.zip
1. Copy the ExecuteLog.class file under the path %FineBI%/webapps/webroot/WEB-INF/classes/com/fr/log, and the program data source is defined successfully.
The codes of the template execution log file can be compiled into a class file.
package com.fr.log;
import com.fr.data.AbstractTableData;
import com.fr.decision.log.ExecuteMessage;
import com.fr.general.data.TableDataException;
import com.fr.intelli.record.MetricRegistry;
import com.fr.stable.query.QueryFactory;
import com.fr.third.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @author Munin
* @version 5.1.3
* Created by Munin on 2020/4/27
*/
public class ExecuteLog extends AbstractTableData {
private static final long serialVersionUID = -3233073054624031382L;
private String[] columnNames = {
"tname",
"type",
"userrole",
"param",
"ip",
"username",
"consume",
"sql",
"browser",
"memory",
"time",
"reportId"
};
private List<List<Object>> cacheData = new ArrayList<>();
public ExecuteLog() {
}
/**
* Lazy loading, solving the performance issue on unnecessarily fetching details
*/
private List<List<Object>> getExecuteData() {
if (CollectionUtils.isEmpty(cacheData)) {
init();
}
return cacheData;
}
private void init() {
try {
List<ExecuteMessage> messages = MetricRegistry.getMetric().find(ExecuteMessage.class, QueryFactory.create()).getList();
if (messages != null && !messages.isEmpty()) {
for (ExecuteMessage message : messages) {
List<Object> objects = new ArrayList<Object>();
objects.add(message.getTemplate());
objects.add(message.getType());
objects.add(message.getUserrole());
objects.add(message.getParameters());
objects.add(message.getIp());
objects.add(message.getUsername());
objects.add(message.getConsume());
objects.add(message.getSql());
objects.add(message.getBrowser());
objects.add(message.getMemory());
objects.add(message.getTime());
objects.add(message.getReportId());
cacheData.add(objects);
}
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
@Override
public int getColumnCount() throws TableDataException {
return columnNames.length;
}
@Override
public String getColumnName(int i) throws TableDataException {
return columnNames[i];
}
@Override
public int getRowCount() throws TableDataException {
return getExecuteData().size();
}
@Override
public Object getValueAt(int i, int i1) {
List<List<Object>> data = getExecuteData();
if (i < data.size()) {
List<Object> message = data.get(i);
if (i1 < message.size()) {
return message.get(i1);
}
}
return null;
}
Establishing a Remote Connection
You need to remotely connect the designer to the FineBI server. For details, see FineReport Designer Connected to FineBI Project Remotely.
1. Open the designer and choose Server > Server Dataset.
2. Go to the server dataset interface and choose + > Class.
3. Click Select, select the added ExecuteLog.class file, and click OK to save.
4. You can see the added program dataset Class1 in Server Dataset.


Adding a Program Data Table in FineBI
1. Log in to FineBI as the admin, click Public Data, select any folder, and choose Add Dataset > Database Table.
2. In Server Dataset, you can see the Class1 dataset added in the designer. Select the Class1 dataset and click OK to add it to the business package for use.