Преглед изворни кода

解决因为缓存问题报表无法及时更新的BUG

master
jacky6024 пре 7 година
родитељ
комит
3bcf6242ef
  1. 13
      ureport2-console/src/main/java/com/bstek/ureport/console/designer/DesignerServletAction.java
  2. 1
      ureport2-console/src/main/resources/ureport-console-context.xml
  3. 18
      ureport2-core/src/main/java/com/bstek/ureport/cache/CacheUtils.java
  4. 3
      ureport2-core/src/main/java/com/bstek/ureport/cache/DefaultMemoryReportDefinitionCache.java
  5. 1
      ureport2-core/src/main/java/com/bstek/ureport/export/ExportManagerImpl.java
  6. 14
      ureport2-core/src/main/java/com/bstek/ureport/export/ReportRender.java

13
ureport2-console/src/main/java/com/bstek/ureport/console/designer/DesignerServletAction.java

@ -37,8 +37,7 @@ import org.apache.velocity.VelocityContext;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import com.bstek.ureport.cache.DefaultMemoryReportDefinitionCache;
import com.bstek.ureport.cache.ReportDefinitionCache;
import com.bstek.ureport.cache.CacheUtils;
import com.bstek.ureport.console.RenderPageServletAction;
import com.bstek.ureport.console.exception.ReportDesignException;
import com.bstek.ureport.definition.ReportDefinition;
@ -58,7 +57,6 @@ import com.bstek.ureport.provider.report.ReportProvider;
public class DesignerServletAction extends RenderPageServletAction {
private ReportRender reportRender;
private ReportParser reportParser;
private ReportDefinitionCache reportDefinitionCache;
private List<ReportProvider> reportProviders=new ArrayList<ReportProvider>();
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
@ -181,7 +179,8 @@ public class DesignerServletAction extends RenderPageServletAction {
targetReportProvider.saveReport(file, content);
InputStream inputStream=IOUtils.toInputStream(content,"utf-8");
ReportDefinition reportDef=reportParser.parse(inputStream, file);
reportDefinitionCache.cacheReportDefinition(file, reportDef);
reportRender.rebuildReportDefinition(reportDef);
CacheUtils.cacheReportDefinition(file, reportDef);
IOUtils.closeQuietly(inputStream);
}
@ -207,12 +206,6 @@ public class DesignerServletAction extends RenderPageServletAction {
}
reportProviders.add(provider);
}
Collection<ReportDefinitionCache> reportCaches=applicationContext.getBeansOfType(ReportDefinitionCache.class).values();
if(reportCaches.size()==0){
reportDefinitionCache=new DefaultMemoryReportDefinitionCache();
}else{
reportDefinitionCache=reportCaches.iterator().next();
}
}
@Override

1
ureport2-console/src/main/resources/ureport-console-context.xml

@ -17,6 +17,7 @@
<bean id="ureport.htmlPreviewServletAction" class="com.bstek.ureport.console.html.HtmlPreviewServletAction">
<property name="exportManager" ref="ureport.exportManager"></property>
<property name="reportBuilder" ref="ureport.reportBuilder"></property>
<property name="reportRender" ref="ureport.reportRender"></property>
</bean>
<bean id="ureport.exportWordServletAction" class="com.bstek.ureport.console.word.ExportWordServletAction">
<property name="exportManager" ref="ureport.exportManager"></property>

18
ureport2-core/src/main/java/com/bstek/ureport/cache/CacheUtils.java

@ -21,6 +21,7 @@ import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import com.bstek.ureport.definition.ReportDefinition;
import com.bstek.ureport.model.Report;
/**
@ -29,6 +30,7 @@ import com.bstek.ureport.model.Report;
*/
public class CacheUtils implements ApplicationContextAware{
private static ReportCache reportCache;
private static ReportDefinitionCache reportDefinitionCache;
public static Report getReport(String file){
if(reportCache!=null){
@ -42,12 +44,24 @@ public class CacheUtils implements ApplicationContextAware{
}
}
public static ReportDefinition getReportDefinition(String file){
return reportDefinitionCache.getReportDefinition(file);
}
public static void cacheReportDefinition(String file,ReportDefinition reportDefinition){
reportDefinitionCache.cacheReportDefinition(file, reportDefinition);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Collection<ReportCache> coll=applicationContext.getBeansOfType(ReportCache.class).values();
if(coll.size()>0){
reportCache=coll.iterator().next();
}
Collection<ReportDefinitionCache> reportCaches=applicationContext.getBeansOfType(ReportDefinitionCache.class).values();
if(reportCaches.size()==0){
reportDefinitionCache=new DefaultMemoryReportDefinitionCache();
}else{
reportDefinitionCache=reportCaches.iterator().next();
}
}
}

3
ureport2-core/src/main/java/com/bstek/ureport/cache/DefaultMemoryReportDefinitionCache.java

@ -32,6 +32,9 @@ public class DefaultMemoryReportDefinitionCache implements ReportDefinitionCache
}
@Override
public void cacheReportDefinition(String file,ReportDefinition reportDefinition) {
if(reportMap.containsKey(file)){
reportMap.remove(file);
}
reportMap.put(file, reportDefinition);
}
}

1
ureport2-core/src/main/java/com/bstek/ureport/export/ExportManagerImpl.java

@ -42,6 +42,7 @@ public class ExportManagerImpl implements ExportManager {
public HtmlReport exportHtml(String file,String contextPath,Map<String, Object> parameters) {
ReportDefinition reportDefinition=reportRender.getReportDefinition(file);
Report report=reportRender.render(reportDefinition, parameters);
CacheUtils.storeReport(file, report);
HtmlReport htmlReport=new HtmlReport();
String content=htmlProducer.produce(report);
htmlReport.setContent(content);

14
ureport2-core/src/main/java/com/bstek/ureport/export/ReportRender.java

@ -26,8 +26,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import com.bstek.ureport.build.ReportBuilder;
import com.bstek.ureport.cache.DefaultMemoryReportDefinitionCache;
import com.bstek.ureport.cache.ReportDefinitionCache;
import com.bstek.ureport.cache.CacheUtils;
import com.bstek.ureport.definition.CellDefinition;
import com.bstek.ureport.definition.Expand;
import com.bstek.ureport.definition.ReportDefinition;
@ -45,7 +44,6 @@ import com.bstek.ureport.provider.report.ReportProvider;
*/
public class ReportRender implements ApplicationContextAware{
private ReportParser reportParser;
private ReportDefinitionCache reportDefinitionCache;
private ReportBuilder reportBuilder;
private Collection<ReportProvider> reportProviders;
private DownCellbuilder downCellParentbuilder=new DownCellbuilder();
@ -60,11 +58,11 @@ public class ReportRender implements ApplicationContextAware{
}
public ReportDefinition getReportDefinition(String file){
ReportDefinition reportDefinition=reportDefinitionCache.getReportDefinition(file);
ReportDefinition reportDefinition=CacheUtils.getReportDefinition(file);
if(reportDefinition==null){
reportDefinition=parseReport(file);
rebuildReportDefinition(reportDefinition);
reportDefinitionCache.cacheReportDefinition(file, reportDefinition);
CacheUtils.cacheReportDefinition(file, reportDefinition);
}
return reportDefinition;
}
@ -143,11 +141,5 @@ public class ReportRender implements ApplicationContextAware{
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
reportProviders=applicationContext.getBeansOfType(ReportProvider.class).values();
Collection<ReportDefinitionCache> reportCaches=applicationContext.getBeansOfType(ReportDefinitionCache.class).values();
if(reportCaches.size()==0){
reportDefinitionCache=new DefaultMemoryReportDefinitionCache();
}else{
reportDefinitionCache=reportCaches.iterator().next();
}
}
}

Loading…
Откажи
Сачувај