Skip to content

Commit

Permalink
Merge branch 'gh-156'
Browse files Browse the repository at this point in the history
  • Loading branch information
dadza committed May 11, 2021
2 parents 0f4471a + d0d882e commit 6c19a04
Show file tree
Hide file tree
Showing 19 changed files with 5,888 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void updatePage(JRVirtualPrintPage page)
this.page = page;

JRVirtualizationContext newContext = page.getVirtualizationContext();
context.inheritListeners(newContext);
context.updateParent(newContext);
}

private void lockContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.awt.Color;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -155,4 +156,15 @@ public void readVirtualized(VirtualizationInput in) throws IOException
}
}
}

private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException
{
in.defaultReadObject();
if (elements instanceof VirtualizableElementList)
{
VirtualizableElementList virtualizableList = ((VirtualizableElementList) elements);
JRVirtualizationContext virtualizationContext = virtualizableList.getVirtualizationContext();
virtualizationContext.cacheVirtualizableList(PrintElementId.forElement(this), virtualizableList);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.ReentrantLock;
Expand Down Expand Up @@ -79,15 +80,19 @@ public class JRVirtualizationContext implements Serializable, VirtualizationList
ReferenceMap.ReferenceStrength.WEAK, ReferenceMap.ReferenceStrength.WEAK
);

private UUID id;
private boolean root;
private transient JRVirtualizationContext parentContext;
private transient JRVirtualizer virtualizer;
private transient JasperReportsContext jasperReportsContext;

private Map<String,Renderable> cachedRenderers;
private Map<String,JRTemplateElement> cachedTemplates;

private Set<JRVirtualizationContext> frameContexts;
private Map<PrintElementId,VirtualizableElementList> virtualizableLists;
private Map<UUID, JRVirtualizationContext> subContexts;

private transient Set<JRVirtualizationContext> frameContexts;
private transient Map<PrintElementId,VirtualizableElementList> virtualizableLists;

private volatile boolean readOnly;
private volatile boolean disposed;
Expand All @@ -105,24 +110,31 @@ public class JRVirtualizationContext implements Serializable, VirtualizationList
*/
public JRVirtualizationContext(JasperReportsContext jasperReportsContext)
{
this.id = UUID.randomUUID();
this.root = true;
this.jasperReportsContext = jasperReportsContext;

cachedRenderers = new ConcurrentHashMap<String,Renderable>(16, 0.75f, 1);
cachedTemplates = new ConcurrentHashMap<String,JRTemplateElement>(16, 0.75f, 1);
virtualizableLists = new ConcurrentHashMap<>(16, 0.75f, 1);

subContexts = new ConcurrentHashMap<>(16, 0.75f, 1);
subContexts.put(this.id, this);

pageElementSize = JRPropertiesUtil.getInstance(jasperReportsContext).getIntegerProperty(JRVirtualPrintPage.PROPERTY_VIRTUAL_PAGE_ELEMENT_SIZE, 0);

initLock();

if (log.isDebugEnabled())
{
log.debug("created " + this);
log.debug("created " + id);
}
}

protected JRVirtualizationContext(JRVirtualizationContext parentContext)
{
this.id = UUID.randomUUID();
this.root = false;
this.parentContext = parentContext;
this.virtualizer = parentContext.virtualizer;
this.jasperReportsContext = parentContext.jasperReportsContext;
Expand All @@ -131,6 +143,9 @@ protected JRVirtualizationContext(JRVirtualizationContext parentContext)
this.cachedRenderers = parentContext.cachedRenderers;
this.cachedTemplates = parentContext.cachedTemplates;
this.virtualizableLists = parentContext.virtualizableLists;

this.subContexts = new ConcurrentHashMap<>(16, 0.75f, 1);
this.subContexts.put(this.id, this);

this.pageElementSize = parentContext.pageElementSize;

Expand All @@ -139,7 +154,7 @@ protected JRVirtualizationContext(JRVirtualizationContext parentContext)

if (log.isDebugEnabled())
{
log.debug("created sub context " + this + ", parent " + parentContext);
log.debug("created sub context " + id + ", parent " + parentContext.id);
}
}

Expand Down Expand Up @@ -413,9 +428,10 @@ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassN
setThreadJasperReportsContext();

GetField fields = in.readFields();
root = fields.get("root", false);
cachedRenderers = (Map<String, Renderable>) fields.get("cachedRenderers", null);
cachedTemplates = (Map<String, JRTemplateElement>) fields.get("cachedTemplates", null);
virtualizableLists = (Map<PrintElementId, VirtualizableElementList>) fields.get("virtualizableLists", null);
subContexts = (Map<UUID, JRVirtualizationContext>) fields.get("subContexts", null);
readOnly = fields.get("readOnly", false);
// use configured default if serialized by old version
pageElementSize = fields.get("pageElementSize", JRPropertiesUtil.getInstance(jasperReportsContext).getIntegerProperty(
Expand All @@ -424,6 +440,12 @@ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassN
setThreadVirtualizer();

initLock();

if (root)
{
virtualizableLists = new ConcurrentHashMap<>(16, 0.75f, 1);
subContexts.values().stream().forEach(context -> {context.virtualizableLists = virtualizableLists;});
}
}

private void setThreadVirtualizer()
Expand Down Expand Up @@ -523,6 +545,18 @@ else if (obj instanceof Renderable)
replace = new JRVirtualPrintPage.JRIdHolderRenderer(renderer);
}
}
else if (obj instanceof JRVirtualizationContext)
{
JRVirtualizationContext context = (JRVirtualizationContext) obj;
if (subContexts.containsKey(context.id))
{
replace = new VirtualizationContextIdHolder(context.id);
}
else if (log.isDebugEnabled())
{
log.debug("Context " + context.id + " not found under " + id);
}
}
return replace;
}

Expand Down Expand Up @@ -555,6 +589,16 @@ else if (obj instanceof JRVirtualPrintPage.JRIdHolderRenderer)
}
resolve = cachedRenderer;
}
else if (obj instanceof VirtualizationContextIdHolder)
{
UUID id = ((VirtualizationContextIdHolder) obj).getId();
JRVirtualizationContext context = subContexts.get(id);
if (context == null)
{
throw new JRRuntimeException("Context with ID " + id + " not found");
}
resolve = context;
}
return resolve;
}

Expand Down Expand Up @@ -645,6 +689,9 @@ public JRVirtualizationContext getFramesContext()
if (frameContexts.isEmpty())
{
frameContext = new JRVirtualizationContext(this);
frameContext.subContexts = subContexts;
subContexts.put(frameContext.id, frameContext);

if (listeners != null)
{
for (VirtualizationListener<VirtualElementsData> listener : listeners)
Expand All @@ -655,7 +702,7 @@ public JRVirtualizationContext getFramesContext()

if (log.isDebugEnabled())
{
log.debug(this + " created frames context " + frameContext);
log.debug(id + " created frames context " + frameContext.id);
}

frameContexts.add(frameContext);
Expand All @@ -682,11 +729,13 @@ public VirtualizableElementList getVirtualizableList(PrintElementId id)
return virtualizableLists.get(id);
}

public void inheritListeners(JRVirtualizationContext sourceContext)
public void updateParent(JRVirtualizationContext destinationContext)
{
if (sourceContext.listeners != null)
destinationContext.subContexts.put(id, this);

if (destinationContext.listeners != null)
{
for (VirtualizationListener<VirtualElementsData> listener : sourceContext.listeners)
for (VirtualizationListener<VirtualElementsData> listener : destinationContext.listeners)
{
if (listeners == null || !listeners.contains(listener))//TODO keep a set?
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JasperReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
*/
package net.sf.jasperreports.engine.fill;

import java.io.Serializable;
import java.util.UUID;

import net.sf.jasperreports.engine.JRConstants;

/**
*
* @author Lucian Chirita (lucianc@users.sourceforge.net)
*/
public class VirtualizationContextIdHolder implements Serializable {

private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;

private UUID id;

public VirtualizationContextIdHolder() {
}

public VirtualizationContextIdHolder(UUID id) {
this.id = id;
}

public UUID getId() {
return id;
}

public void setId(UUID id) {
this.id = id;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JasperReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
*/
package net.sf.jasperreports;

import net.sf.jasperreports.engine.JRVirtualizer;

/**
* @author Lucian Chirita (lucianc@users.sourceforge.net)
*/
public class NoVirtualizerContainer implements VirtualizerContainer
{

@Override
public JRVirtualizer getVirtualizer()
{
return null;
}

@Override
public void setReadOnly()
{
//NOOP
}

@Override
public void dispose()
{
//NOOP
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JasperReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
*/
package net.sf.jasperreports;

import net.sf.jasperreports.engine.JRVirtualizer;
import net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer;

/**
* @author Lucian Chirita (lucianc@users.sourceforge.net)
*/
public class OwnVirtualizerContainer implements VirtualizerContainer
{

private final JRAbstractLRUVirtualizer virtualizer;

public OwnVirtualizerContainer(JRAbstractLRUVirtualizer virtualizer)
{
this.virtualizer = virtualizer;
}

@Override
public JRVirtualizer getVirtualizer()
{
return virtualizer;
}

@Override
public void setReadOnly()
{
virtualizer.setReadOnly(true);
}

@Override
public void dispose()
{
virtualizer.cleanup();
}

}
Loading

0 comments on commit 6c19a04

Please sign in to comment.