final ReportDefinition parentReport = parentState.getReport();
final SubReport dummyReport = new SubReport(functionStorageKey.getReportId());
this.report = new ReportDefinitionImpl(dummyReport, parentReport.getPageDefinition(), subreportFromMarker.getParentSection());
this.flowController = parentStateFlowController.derive();
this.advanceHandler = EndSubReportHandler.HANDLER;
this.layoutProcess = new SubLayoutProcess
(parentState.layoutProcess, computeStructureFunctions(initialSubReport.getStructureFunctions(),
flowController.getReportContext().getOutputProcessorMetaData()), this.report.getObjectID());
}
else
{
DataFactory dataFactory = dataFactoryManager.restore(functionStorageKey, isReportsShareConnections(initialSubReport));
final DefaultFlowController postPreProcessingFlowController;
final SubReport preDataSubReport;
if (dataFactory == null)
{
final SubReportProcessPreprocessor preprocessor = new SubReportProcessPreprocessor(parentStateFlowController);
preDataSubReport = preprocessor.invokePreDataProcessing(initialSubReport);
postPreProcessingFlowController = preprocessor.getFlowController();
final DataFactory subreportDf = lookupDataFactory(preDataSubReport);
final boolean dataCacheEnabled = isCacheEnabled(preDataSubReport);
if (subreportDf == null)
{
// subreport does not define a own factory, we reuse the parent's data-factory in the master-row.
dataFactory = new EmptyDataFactory();
}
else
{
// subreport comes with an own factory, so open the gates ..
final DataFactory sortingDataFactory = new SortingDataFactory(subreportDf, performanceMonitorContext);
final CachingDataFactory cdataFactory = new CachingDataFactory(sortingDataFactory, dataCacheEnabled);
final ProcessingContext context = postPreProcessingFlowController.getReportContext();
cdataFactory.initialize(new ProcessingDataFactoryContext(context, cdataFactory));
dataFactoryManager.store(functionStorageKey, cdataFactory, isReportsShareConnections(preDataSubReport));
dataFactory = cdataFactory;
}
}
else
{
preDataSubReport = initialSubReport;
postPreProcessingFlowController = parentStateFlowController;
}
// And now initialize the sub-report.
final ParameterMapping[] inputMappings = preDataSubReport.getInputMappings();
final ParameterMapping[] exportMappings = preDataSubReport.getExportMappings();
// eval query, query-limit and query-timeout
this.flowController = postPreProcessingFlowController.performInitSubreport
(dataFactory, inputMappings, resourceBundleFactory);
final Integer queryLimitDefault = IntegerCache.getInteger(preDataSubReport.getQueryLimit());
final Integer queryTimeoutDefault = IntegerCache.getInteger(preDataSubReport.getQueryTimeout());
final Object queryRaw = evaluateExpression(preDataSubReport.getAttributeExpression(AttributeNames.Internal.NAMESPACE,
AttributeNames.Internal.QUERY), preDataSubReport.getQuery());
final Object queryLimitRaw = evaluateExpression(preDataSubReport.getAttributeExpression(AttributeNames.Internal.NAMESPACE,
AttributeNames.Internal.QUERY_LIMIT), queryLimitDefault);
final Object queryTimeoutRaw = evaluateExpression(preDataSubReport.getAttributeExpression(AttributeNames.Internal.NAMESPACE,
AttributeNames.Internal.QUERY_TIMEOUT), queryTimeoutDefault);
final String queryDefined = designtime ? "design-time-query" : preDataSubReport.getQuery();
this.query = (String) ConverterRegistry.convert(queryRaw, String.class, queryDefined);
this.queryLimit = (Integer) ConverterRegistry.convert(queryLimitRaw, Integer.class, queryLimitDefault);
this.queryTimeout = (Integer) ConverterRegistry.convert(queryTimeoutRaw, Integer.class, queryTimeoutDefault);
final List<SortConstraint> sortOrder = lookupSortOrder(preDataSubReport);
DefaultFlowController postQueryFlowController = flowController.performSubReportQuery
(query, queryLimit.intValue(), queryTimeout.intValue(), exportMappings, sortOrder);
final ProxyDataSchemaDefinition schemaDefinition =
new ProxyDataSchemaDefinition(preDataSubReport.getDataSchemaDefinition(),
postQueryFlowController.getMasterRow().getDataSchemaDefinition());
postQueryFlowController = postQueryFlowController.updateDataSchema(schemaDefinition);
SubReport fullReport = preDataSubReport;
DefaultFlowController fullFlowController = postQueryFlowController;
if (needPreProcessing)
{
final SubReportProcessPreprocessor preprocessor = new SubReportProcessPreprocessor(postQueryFlowController);
fullReport = preprocessor.invokePreProcessing(preDataSubReport);
fullFlowController = preprocessor.getFlowController();
subReportStorage.store(functionStorageKey, fullReport);
}
this.report = new ReportDefinitionImpl(fullReport, fullReport.getPageDefinition(), subreportFromMarker.getParentSection());
final Expression[] structureFunctions = getStructureFunctionStorage().restore(functionStorageKey);
if (structureFunctions != null)
{
final StructureFunction[] functions = new StructureFunction[structureFunctions.length];
//noinspection SuspiciousSystemArraycopy
System.arraycopy(structureFunctions, 0, functions, 0, structureFunctions.length);
this.layoutProcess = new SubLayoutProcess(parentState.layoutProcess, functions, this.report.getObjectID());
}
else
{
final StructureFunction[] functions = computeStructureFunctions(fullReport.getStructureFunctions(),
fullFlowController.getReportContext().getOutputProcessorMetaData());
this.layoutProcess = new SubLayoutProcess(parentState.layoutProcess, functions, this.report.getObjectID());
}
boolean preserve = true;
Expression[] expressions = getFunctionStorage().restore(functionStorageKey);
if (expressions == null)