I do some stuff that retrieve data from database and print it in form of pdf. Then when involved a lot of data in the same time I want tu use the . setFetchSize() for make the process be more smooth. So I need some help to use .setFetchSize() function in public Resolution viewPdfLog()at my Action.java file for fetch my data record where FecthSize = 100. How can I call and use .setFetchSize() from Index.java
Index.java code :
public class IndexGatewayRunnable implements Runnable {
...
private void doIndexGatewaySSHFramesForSession(
FullTextSession fullTextSession, AdamaProcessedSSHLogin login) {
fullTextSession.setFlushMode(FlushMode.MANUAL);
fullTextSession.setCacheMode(CacheMode.IGNORE);
// Scrollable results will avoid loading too many objects in memory
ScrollableResults results = fullTextSession
.createCriteria(AdamaProcessedSSHFrame.class)
.add(Restrictions.eq("adamaProcessedSSHLogin.id", login.getId()))
.setFetchSize(indexFrameBatch).scroll(ScrollMode.FORWARD_ONLY);
int index = 0;
while (results.next()) {
index++;
fullTextSession.index(results.get(0)); // index each element
if (index % indexFrameBatch == 0) {
fullTextSession.flush(); // Follow UNIX
fullTextSession.flushToIndexes(); // apply changes to indexes
fullTextSession.clear(); // free memory since the queue is
// processed
}
if (index % (indexFrameBatch * 100) == 0) {
log.info("flushing after index " + (indexFrameBatch * 100) + " frames");
}
}
results.close();
}
....
}
Action.java code :
public Resolution viewPdfLog() throws IOException {
if (getFileId() != null) {
Resolution stream = new StreamingResolution("application/pdf") {
public void stream(HttpServletResponse response)
throws Exception {
response.setContentType("application/pdf");
ArgumentBuilder args = new ArgumentBuilder();
args.addArg(getFileId());
DBResult result = DBOperator.getInstance().doOperation(FileOperation.class,
"getUnixLog", args.getTypeInfo());
Logs unixlog = (Logs) result.getValue("RETURN");
File file = new File(unixlog.getFileReference());
else
{
//new add function - get from log_frame content
args = new ArgumentBuilder();
args.addArg(getFileId());
DBResult result1 = DBOperator.getInstance().doOperation(FileOperation.class,
"listLogFramesByFileId", args.getTypeInfo());
@SuppressWarnings("unchecked")
ArrayList<LogFrame> logframes = (ArrayList<LogFrame>) result1.getValue("RETURN");
//File file2 = new File(logframes.get(GLOBAL).getContent());
OutputStream os = response.getOutputStream();
try {
Document document = new Document();
PdfWriter.getInstance(document, os);
document.open();
Paragraph paragraph = new Paragraph();
Font font = FontFactory.getFont("Times-Roman", 12);
BaseFont bf = BaseFont.createFont(
BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
Font contentFont = new Font(bf, 10);
Chunk chunk = new Chunk();
for(LogFrame frame : logframes)
{
Class fetchsize = IndexGatewayRunnable.class;
Object obj = fetchsize.newInstance();
Method method = fetchsize.getDeclaredMethod("doIndexGatewaySSHFramesForSession");
method.setAccessible(true);
method.invoke(frame);
log.info("logrames="+ frame.getContent());
paragraph.add(new Phrase("Content ID: ",font));
paragraph.add(new Phrase(frame.getId().toString(),font));
paragraph.add(Chunk.NEWLINE);
paragraph.add(new Phrase(frame.getFrameOrder()));
paragraph.add(Chunk.NEWLINE);
paragraph.add(new Phrase(frame.getContent(),contentFont));
paragraph.add(Chunk.NEWLINE);
paragraph.add(Chunk.NEWLINE);
}
document.add(paragraph);
document.close();
} catch (Exception e) {
e.getMessage();
}
}
}
};
// }.setFilename(generateTextFileName());
return stream;
}
return new RedirectResolution("/home/Folder.action?listLogFrames")
.addParameter("fileId", getFileId());
}