\n ...\n\u003C/Persons>\n","xml",[101,102,103,111,116,122,128],"code",{"__ignoreMap":11},[104,105,108],"span",{"class":106,"line":107},"line",1,[104,109,110],{},"\u003C?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",[104,112,113],{"class":106,"line":12},[104,114,115],{},"\u003CPersons>\n",[104,117,119],{"class":106,"line":118},3,[104,120,121],{}," \u003CPerson firstname=\"First\" lastname=\"Last\" mail=\"first.last@test.test\" title=\"nice guy\" age=\"47\" status=\"married\"/>\n",[104,123,125],{"class":106,"line":124},4,[104,126,127],{}," ...\n",[104,129,131],{"class":106,"line":130},5,[104,132,133],{},"\u003C/Persons>\n",[87,135,137],{"id":136},"the-custom-data-source","The custom data source",[39,139,140,141,144],{},"The custom data source extends the ",[46,142,143],{},"JRAbstractTextDataSource"," and therefore the sample implementation has to override\nthe methods",[146,147,148,155],"ul",{},[61,149,150,154],{},[151,152,153],"em",{},"boolean next():"," Determines whether or not there is another row to display",[61,156,157,160],{},[151,158,159],{},"Object getFieldValue(JRField field)",": Requests the value for the given field/cell",[39,162,163],{},"It simply implements the Iterator pattern in order to render all columns of the report.",[39,165,166],{},[46,167,168],{},"Initialization",[39,170,171,172,175],{},"The constructor of the class expects an Inputstream that represents the XML source. Based on that stream the class\ninitializes a ",[46,173,174],{},"XMLStreamReader"," which is basically an iterator over the XML tags.",[39,177,178],{},[46,179,180],{},"boolean next()",[39,182,183,184,187],{},"The implementation of the ",[151,185,186],{},"next()"," method initially iterates over the XML tags till it reaches the first Person tag and\nstops at this point. Unfortunately this means that the custom implementation contains knowledge about how the XML is\nstructured and makes it very hard to reuse.",[39,189,190,191,193],{},"Every subsequent call to the ",[151,192,186],{}," method sets the current pointer to the next Person element and returns true, until\nthe Persons tag has been reached or the end of the document appeared.",[95,195,199],{"className":196,"code":197,"language":198,"meta":11,"style":11},"language-java shiki shiki-themes github-light github-dark"," int eventType = xmlStreamReader.getEventType();\n String tagName = null;\n boolean isStart = false;\n while (xmlStreamReader.hasNext()) {\n eventType = xmlStreamReader.next();\n switch (eventType) {\n case XMLEvent.START_ELEMENT:\n isStart = true;\n case XMLEvent.END_ELEMENT:\n tagName = xmlStreamReader.getLocalName();\n // check if there is still a person element left\n if (isStart && PERSON_TAG_NAME.equals(tagName)) {\n return true;\n } else if (!isStart && PERSONS_TAG_NAME.equals(tagName)) {\n // end tag of persons, nothing else to handle\n return false;\n }\n break;\n case XMLEvent.END_DOCUMENT:\n return false;\n }\n isStart = false;\n }\n","java",[101,200,201,206,211,216,221,226,232,238,244,250,256,262,268,274,280,286,292,298,304,310,316,322,328],{"__ignoreMap":11},[104,202,203],{"class":106,"line":107},[104,204,205],{}," int eventType = xmlStreamReader.getEventType();\n",[104,207,208],{"class":106,"line":12},[104,209,210],{}," String tagName = null;\n",[104,212,213],{"class":106,"line":118},[104,214,215],{}," boolean isStart = false;\n",[104,217,218],{"class":106,"line":124},[104,219,220],{}," while (xmlStreamReader.hasNext()) {\n",[104,222,223],{"class":106,"line":130},[104,224,225],{}," eventType = xmlStreamReader.next();\n",[104,227,229],{"class":106,"line":228},6,[104,230,231],{}," switch (eventType) {\n",[104,233,235],{"class":106,"line":234},7,[104,236,237],{}," case XMLEvent.START_ELEMENT:\n",[104,239,241],{"class":106,"line":240},8,[104,242,243],{}," isStart = true;\n",[104,245,247],{"class":106,"line":246},9,[104,248,249],{}," case XMLEvent.END_ELEMENT:\n",[104,251,253],{"class":106,"line":252},10,[104,254,255],{}," tagName = xmlStreamReader.getLocalName();\n",[104,257,259],{"class":106,"line":258},11,[104,260,261],{}," // check if there is still a person element left\n",[104,263,265],{"class":106,"line":264},12,[104,266,267],{}," if (isStart && PERSON_TAG_NAME.equals(tagName)) {\n",[104,269,271],{"class":106,"line":270},13,[104,272,273],{}," return true;\n",[104,275,277],{"class":106,"line":276},14,[104,278,279],{}," } else if (!isStart && PERSONS_TAG_NAME.equals(tagName)) {\n",[104,281,283],{"class":106,"line":282},15,[104,284,285],{}," // end tag of persons, nothing else to handle\n",[104,287,289],{"class":106,"line":288},16,[104,290,291],{}," return false;\n",[104,293,295],{"class":106,"line":294},17,[104,296,297],{}," }\n",[104,299,301],{"class":106,"line":300},18,[104,302,303],{}," break;\n",[104,305,307],{"class":106,"line":306},19,[104,308,309],{}," case XMLEvent.END_DOCUMENT:\n",[104,311,313],{"class":106,"line":312},20,[104,314,315],{}," return false;\n",[104,317,319],{"class":106,"line":318},21,[104,320,321],{}," }\n",[104,323,325],{"class":106,"line":324},22,[104,326,327],{}," isStart = false;\n",[104,329,331],{"class":106,"line":330},23,[104,332,333],{}," }\n",[39,335,336],{},[46,337,159],{},[39,339,340,341,344],{},"The implementation of",[151,342,343],{},"getFieldValue(JRField field)"," is very simple, because the attribute name is exactly the name that\nis assigned in the Jasper Report document.",[95,346,348],{"className":196,"code":347,"language":198,"meta":11,"style":11},"return xmlStreamReader.getAttributeValue(null, field.getName());\n",[101,349,350],{"__ignoreMap":11},[104,351,352],{"class":106,"line":107},[104,353,347],{},[71,355,357],{"id":356},"brining-all-together","Brining all together",[39,359,360],{},"We have now a XML file that contains our test persons and a custom data source that iterates one by one over each\nperson. It is time to see how this improved the report generation time and bringing all pieces together.",[39,362,77,363,366],{},[46,364,365],{},"ReportGenerator"," class accepts the XML source and the template as stream and via an additional flag it is\npossible to switch between the default and the custom data source. A simple Junit test is using this class to run 4\nreport generations and measures the amount of time it needed. Here the result of the Junit test on my local machine:",[39,368,369],{},"`Running com.jasperreports.ReportGeneratorTest",[39,371,372],{},"INFO ReportGenerator - Created report with default XML data source in 4.136 seconds.",[39,374,375],{},"INFO ReportGenerator - Created report with custom datasource in 0.684 seconds.",[39,377,378],{},"INFO ReportGenerator - Created report with default XML data source in 21.463 seconds.",[39,380,381],{},"INFO ReportGenerator - Created report with custom datasource in 3.495 seconds.",[39,383,384],{},"Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 30.267 sec`",[39,386,387],{},"The first two results are using a XML source with 100 Persons, the following two are processing 5000 Persons. The custom\ndata source implementation is about 6 times faster than the default implementation and this sample “only” uses only a\nfraction of what we had to process in our project. In fact our worst case scenario mentioned in the beginning is using\n50000 records on multiple tabs and therefore this improvement pays of very fast.",[389,390,391],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":11,"searchDepth":12,"depth":12,"links":393},[394,395],{"id":73,"depth":118,"text":74},{"id":356,"depth":118,"text":357},[397],"open-source-blog","2012-08-29T02:40:26","While working on one of my projects we were faced with the problem of creating a report with a big amount of data to\\nshow on multiple Excel tabs (about 50000 entries grouped by different criteria’s). We had a couple of requirements that\\nlead us to choose Jasper Reports as our report generation engine. Other requirements lead us to use XML as data source –\\ne.g. to generate the report on the fly without wasting hard disk space for different languages.","https://synyx.de/blog/big-jasper-reports-with-custom-xml-datasource/",{},"/blog/big-jasper-reports-with-custom-xml-datasource",{"title":30,"description":41},"blog/big-jasper-reports-with-custom-xml-datasource",[406,407,408],"custom-datasource","jasper-reports","saxpullparser","While working on one of my projects we were faced with the problem of creating a report with a big amount of data to show on multiple Excel tabs (about…","SYnjblwoql00btIP3Bhd2-4MQoGLcsdaZYWx_o08uoA",["Reactive",412],{"$scookieConsent":413,"$ssite-config":415},{"functional":414,"analytics":414},false,{"_priority":416,"env":420,"name":421,"url":422},{"name":417,"env":418,"url":419},-10,-15,0,"production","nuxt-app","https://synyx.de",["Set"],["ShallowReactive",425],{"author-steinegger":-1,"roughlyFilteredArticles":-1},"/blog/author/steinegger"]