本文整理汇总了Java中net.sf.jasperreports.engine.JRDataSource类的典型用法代码示例。如果您正苦于以下问题:Java JRDataSource类的具体用法?Java JRDataSource怎么用?Java JRDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JRDataSource类属于net.sf.jasperreports.engine包,在下文中一共展示了JRDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertReportData
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
/**
* Convert the given report data value to a {@code JRDataSource}.
* <p>In the default implementation, a {@code JRDataSource},
* {@code java.util.Collection} or object array is detected.
* The latter are converted to {@code JRBeanCollectionDataSource}
* or {@code JRBeanArrayDataSource}, respectively.
* @param value the report data value to convert
* @return the JRDataSource (never {@code null})
* @throws IllegalArgumentException if the value could not be converted
* @see net.sf.jasperreports.engine.JRDataSource
* @see net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
* @see net.sf.jasperreports.engine.data.JRBeanArrayDataSource
*/
public static JRDataSource convertReportData(Object value) throws IllegalArgumentException {
if (value instanceof JRDataSource) {
return (JRDataSource) value;
}
else if (value instanceof Collection) {
return new JRBeanCollectionDataSource((Collection<?>) value);
}
else if (value instanceof Object[]) {
return new JRBeanArrayDataSource((Object[]) value);
}
else {
throw new IllegalArgumentException("Value [" + value + "] cannot be converted to a JRDataSource");
}
}
示例2: fillReport
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
private static JasperPrint fillReport(JRFileVirtualizer virtualizer) throws JRException
{
long start = System.currentTimeMillis();
// Virtualization works only with in memory JasperPrint objects.
// All the operations will first fill the report and then export
// the filled object.
// creating the data source
JRDataSource dataSource = new JREmptyDataSource(1000);
// Preparing parameters
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
// filling the report
JasperPrint jasperPrint = JasperFillManager.fillReport("build/reports/VirtualizerReport.jasper", parameters, dataSource);
virtualizer.setReadOnly(true);
System.err.println("Filling time : " + (System.currentTimeMillis() - start));
return jasperPrint;
}
示例3: openReport
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
/**
* Abre um relatório usando um datasource genérico.
*
* @param titulo Título usado na janela do relatório.
* @param inputStream InputStream que contém o relatório.
* @param parametros Parâmetros utilizados pelo relatório.
* @param dataSource Datasource a ser utilizado pelo relatório.
* @throws JRException Caso ocorra algum problema na execução do relatório
*/
public static void openReport(
String titulo,
InputStream inputStream,
Map parametros,
JRDataSource dataSource ) throws JRException {
/*
* Cria um JasperPrint, que é a versão preenchida do relatório,
* usando um datasource genérico.
*/
JasperPrint print = JasperFillManager.fillReport(
inputStream, parametros, dataSource );
// abre o JasperPrint em um JFrame
viewReportFrame( titulo, print );
}
示例4: fromVariants
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
@NotNull
public static JRDataSource fromVariants(@NotNull final List<VariantReport> variantReports,
@NotNull final HmfReporterData reporterData) {
final DRDataSource variantDataSource =
new DRDataSource(GENE_FIELD.getName(), POSITION_FIELD.getName(), VARIANT_FIELD.getName(), DEPTH_VAF_FIELD.getName(),
COSMIC_FIELD.getName(), COSMIC_NR_FIELD.getName(), HGVS_CODING_FIELD.getName(), HGVS_PROTEIN_FIELD.getName(),
CONSEQUENCE_FIELD.getName(), PLOIDY_TAF_FIELD.getName());
for (final VariantReport variantReport : variantReports) {
final String displayGene = reporterData.drupFilter().test(variantReport) ? variantReport.gene() + " *" : variantReport.gene();
variantDataSource.add(displayGene, variantReport.variant().chromosomePosition(), variantReport.variantField(),
variantReport.depthVafField(), variantReport.cosmicID(), stripCosmicIdentifier(variantReport.cosmicID()),
variantReport.hgvsCoding(), variantReport.hgvsProtein(), variantReport.consequence(), variantReport.ploidyTafField());
}
return variantDataSource;
}
示例5: createResultDatasource
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
/**
* Creates a data source out of the query result.
*
* @return the data source
*/
protected JRDataSource createResultDatasource() {
JRDataSource resDatasource;
try {
int pageSize = getPropertiesUtil().getIntegerProperty(dataset,
JRJpaQueryExecuterFactory.PROPERTY_JPA_QUERY_PAGE_SIZE,
0);
resDatasource = new JRJpaDataSource(this, pageSize);
}
catch (NumberFormatException e) {
throw
new JRRuntimeException(
EXCEPTION_MESSAGE_KEY_NUMERIC_TYPE_REQUIRED,
new Object[]{JRJpaQueryExecuterFactory.PROPERTY_JPA_QUERY_PAGE_SIZE},
e);
}
return resDatasource;
}
示例6: createDatasource
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
/**
* Creates an instance of {@link JRHibernateListDataSource JRHibernateListDataSource},
* {@link JRHibernateIterateDataSource JRHibernateIterateDataSource} or
* {@link JRHibernateScrollDataSource JRHibernateScrollDataSource}, depending on the
*/
@Override
public JRDataSource createDatasource() throws JRException
{
JRDataSource datasource = null;
String queryString = getQueryString();
if (session != null && queryString != null && queryString.trim().length() > 0)
{
createQuery(queryString);
datasource = createResultDatasource();
}
return datasource;
}
示例7: create
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
@Override
public JRDataSource create(JasperReport report) throws JRException
{
JRCsvDataSource ds;
if (reader != null)
{
ds = new JRCsvDataSource(reader);
}
else
{
throw
new JRException(
EXCEPTION_MESSAGE_KEY_CANNOT_FIND_SOURCE,
(Object[])null);
}
ds.setDateFormat(dateFormat);
ds.setNumberFormat(numberFormat);
ds.setFieldDelimiter(fieldDelimiter);
ds.setRecordDelimiter(recordDelimiter);
ds.setColumnNames(columnNames);
return ds;
}
示例8: createQueryDatasource
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
/**
* Creates the data source from a connection.
*
* @return the data source to be used
* @throws JRException
*/
private JRDataSource createQueryDatasource() throws JRException
{
if (query == null)
{
return null;
}
try
{
if (log.isDebugEnabled())
{
log.debug("Fill " + filler.fillerId + ": Creating " + query.getLanguage() + " query executer");
}
QueryExecuterFactory queryExecuterFactory = JRQueryExecuterUtils.getInstance(getJasperReportsContext()).getExecuterFactory(query.getLanguage());
queryExecuter = queryExecuterFactory.createQueryExecuter(getJasperReportsContext(), this, parametersMap);
filler.fillContext.setRunningQueryExecuter(queryExecuter);
return queryExecuter.createDatasource();
}
finally
{
filler.fillContext.clearRunningQueryExecuter();
}
}
示例9: BaseFillHandle
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
protected BaseFillHandle (
JasperReportsContext jasperReportsContext,
JasperReport jasperReport,
Map<String,Object> parameters,
JRDataSource dataSource,
Connection conn
) throws JRException
{
this.jasperReportsContext = jasperReportsContext;
this.jasperReport = jasperReport;
this.parameters = parameters;
this.dataSource = dataSource;
this.conn = conn;
this.filler = JRFiller.createReportFiller(jasperReportsContext, jasperReport);
this.listeners = new ArrayList<AsynchronousFilllListener>();
lock = this;
}
示例10: createDatasource
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
@Override
public JRDataSource createDatasource() throws JRException
{
JRDataSource dataSource = null;
String queryStr = getQueryString();
if (connection != null && queryStr != null)
{
if (log.isDebugEnabled())
{
log.debug("MDX query: " + queryStr);
}
Query query = connection.parseQuery(queryStr);
result = connection.execute(query);
logResult();
dataSource = new JRMondrianDataSource(dataset, result);
}
return dataSource;
}
示例11: gerarDanfe
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
private static void gerarDanfe(String url, List<String> emit, List<String> dest, List<String> nota, JRDataSource itens, String qrcode){
try {
// Teste
//String compilado = System.getProperty("user.dir") + "/danfe_nfce_80.jasper";;
String output = "danfe.pdf";
map.put("emit", emit);
map.put("dest", dest);
map.put("nota", nota);
map.put("qrcode", qrcode);
// Relatório compilado
JasperReport report = (JasperReport) JRLoader.loadObjectFromFile(url);
//InputStream jasperStream = getClass().getResourceAsStream("/Foo.jasper");
//JasperReport report = (JasperReport) JRLoader.loadObject(jasperStream);
// Relatório nao compilado
//JasperReport report = JasperCompileManager.compileReport(jrxml);
JasperPrint print = JasperFillManager.fillReport(report, map, itens);
JasperExportManager.exportReportToPdfFile(print, output);
} catch (JRException e) {
System.out.println("erro: "+e.getMessage());
}
}
示例12: gerarDanfeNFe
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
private static void gerarDanfeNFe(String url, List<String> emit, List<String> dest, List<String> nota, JRDataSource itens) {
try {
// Teste
//String compilado = System.getProperty("user.dir") + "/danfe_nfce_80.jasper";;
String output = "danfe.pdf";
map.put("emit", emit);
map.put("dest", dest);
map.put("nota", nota);
// Relatório compilado
JasperReport report = (JasperReport) JRLoader.loadObjectFromFile(url);
JasperPrint print = JasperFillManager.fillReport(report, map, itens);
JasperExportManager.exportReportToPdfFile(print, output);
} catch (JRException e) {
System.out.println("erro: "+e.getMessage());
}
}
示例13: gerarDanfeNfse
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
private static void gerarDanfeNfse(String url, List<String> emit, List<String> dest, List<String> ser, List<String> nota, String xml, String logo) {
try {
// Teste
//String compilado = System.getProperty("user.dir") + "/danfe_nfce_80.jasper";;
String output = "danfe.pdf";
map.put("emit", emit);
map.put("dest", dest);
map.put("ser", ser);
map.put("nota", nota);
map.put("logo", logo);
// brasao
String brasao = Paths.get(System.getProperty("user.dir"), "danfe","brasao.png").toAbsolutePath().toString();
map.put("brasao", brasao);
// JrDataSource
JRDataSource jr = new JRXmlDataSource(xml);
// Relatório compilado
JasperReport report = (JasperReport) JRLoader.loadObjectFromFile(url);
JasperPrint print = JasperFillManager.fillReport(report, map, jr);
JasperExportManager.exportReportToPdfFile(print, output);
} catch (JRException e) {
System.out.println("erro: "+e.getMessage());
}
}
示例14: getDataSourceMapping
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
/**
* Obtin data source-ul pentru tabelul de gene
* @param sourceResult
* @return
*/
public static JRDataSource getDataSourceMapping(FinalResultItem sourceResult) {
int imageWidth = DrawingConstants.REPORT_WIDTH;
int imageHeight = sourceResult.getImageHeight(new JLabel());
//Obtin canvasul pe care se va desena
BufferedImage mappedImage = new BufferedImage(imageWidth, imageHeight,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) mappedImage.getGraphics();
//~~~~~~~~~Desenez resultatul final~~~~~~~~~~~~~~
sourceResult.paintImage(g2d, imageWidth, imageHeight, Color.WHITE, Color.BLACK);
//Convertesc vectorul de imagni intr-o singura imagine
ImageVector splitedImages = ImageManipulation.splitImage(mappedImage,
DrawingConstants.REPORT_MAPPING_CELL_HEIGHT);
//Fac un data source
return new JRDataSourceImageVector(splitedImages);
}
示例15: getDataSourceGenes
import net.sf.jasperreports.engine.JRDataSource; //导入依赖的package包/类
/**
* Obtin data source-ul pentru tabelul de gene
* @param sourceResult
* @return
*/
public static JRDataSource getDataSourceGenes(FinalResultItem sourceResult) {
//Calculez dimensiuniile componentelor
LinkedHashSet<GeneItem> geneItemSanitizer = new LinkedHashSet<GeneItem>();
IntervalMappingSet intervalMappingSet = sourceResult.getIntervalMappingSet();
Iterator <IntervalMappingItem> iteratorMapping = intervalMappingSet.iterator();
while (iteratorMapping.hasNext()) {
IntervalMappingItem mappingItem = iteratorMapping.next();
GeneItemWrapper geneItemWrapper = mappingItem.getGeneItemWrapper();
//Pastrez genele pentru desenare ulterioara
geneItemSanitizer.addAll(geneItemWrapper.getFullGeneVector());
}
//Vectorul de gene
GeneVector geneVector = new GeneVector();
geneVector.addAll(geneItemSanitizer);
Collections.sort(geneVector);
//Fac un data source
return new JRDataSourceSubGenes(geneVector);
}