Working with JasperReports where user can save report's parameter HashMap<String, Object> in DB so that it can be used later for auto scheduling and regenerate that report again.
Currently Report Parameters are being stored as string and then encoded into bytes as BLOB i.e. rs.setParameters(reportParams.toString().getBytes("UTF-8"));
This approach is expensive (when auto scheduling triggers) as an overhead to regenerate parameters again and also creates problem with complex parameter values.
I want to change the approach of saving HashMap, So what would that be ?
I can either keep the DB schema as it is and save reportParam by serialising it and deserialise when required again? like shown below, Or would it be better to add another table with 1..* multiplicity, to store parameters separately for each report?
Or is there is any better approach I'm missing ? Also concerned with performance when retrieving reportParams back. Thanks.
public static byte[] serialise(Object obj) {
byte[] bytearray = null;
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutStream;
try {
objectOutStream = new ObjectOutputStream(byteOutStream);
objectOutStream.writeObject(obj);
bytearray = byteOutStream.toByteArray();
objectOutStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return bytearray;
}
public static ReportParameters deSerialize(byte[] byteArray) throws IOException
{
ReportParameters reportParam = null;
ByteArrayInputStream byteInstream = new ByteArrayInputStream(byteArray);
ObjectInputStream objectInStream;
try {
objectInStream = new ObjectInputStream(byteInstream);
reportParam = (ReportParameters)objectInStream.readObject();
objectInStream.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return reportParam ;
}