Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Re: Serving files dynamically

Frantz Lamothe

2003-08-06



Hi,

I assume that the information is kept in a table.

1) Execute sql statements to retrieve the data

2)Do your calculation and put the data in a vector.

3)Save each element of the Vector to a different table (Archive_Table) in your database.  If you have different reports specify a report ID.  This step can be accomplished by creating a process.

3)Create a bean that holds the vector.  This bean will be used in your jsp to generate a report that is sent as response to the user.

4)Add a method to the bean toString() that takes the vector and creates a String .  

/**
 * Insert the method's description here.
 * Creation date: (12/4/2002 9:05:43 AM)
 * @return java.lang.String
 * @param delimiter java.lang.String
 */
public String toString(String delimiter,boolean useQuotes) {

        String retVal="";
       
        try{

                String lineSeparator="\r\n";
               
                String strQuotes="";
                if(useQuotes){

                        strQuotes="\"";

                }
               
                StringBuffer dataBuf=new StringBuffer("");
                for (int i=0;i<this.size();i++){
               
                        Vector rowData=(Vector)this.elementAt(i);
                        StringBuffer rowBuf=new StringBuffer("");
                        for (int j=0;j<rowData.size();j++){

                                rowBuf.append(strQuotes);
                                rowBuf.append((String)rowData.elementAt(j));
                                rowBuf.append(strQuotes);
                                if (j<rowData.size()-1){

                                        rowBuf.append(delimiter);
                               
                                }
                               
                        }

                        rowBuf.append(lineSeparator);
                        dataBuf.append(rowBuf.toString());
                       
                }
       
                retVal=dataBuf.toString();
       
        }catch(Exception ex){}
       
        return retVal;
       
}

If you use tab delimiter you can output the resulting string to an excel file using an OutputStream.  The boolean should be set to true if the delimiter used is also a character of and element in the vector.

Create a servlet. Based on a parameter passed with the servlet you extracted the data from the archive table and put the result in a Vector or extract the data from the original table.  Follow above steps.


James Hicks <jrhicks@TXUCOM.NET>
Sent by: "A mailing list for Java(tm) 2 Platform, Enterprise Edition" <J2EE-INTEREST@JAVA.SUN.COM>

08/05/2003 09:57 PM
Please respond to "A mailing list for Java(tm) 2 Platform, Enterprise Edition"

       
        To:        J2EE-INTEREST@JAVA.SUN.COM
        cc:        
        Subject:        Re: Serving files dynamically


Are you looking for a long term (crash resistent) cache of the reports
or are you just wanting them to be cached in memory?

I wrote a similar app for my employer except the reports were dynamic
using real time data and auto rotated.  I used a local memory cache
(LRU) to cache the reports.  This works if the reports are not very
large and there are not many people on the same site.

But, from what you describe, you need a long term caching solution.
Here is what I would do: on first request of the report, generate it
(async), then save it to persistent storage (DB or file system).  On
subsequent requests, load the completed report instead of regenerating
it.  There are several 3rd party caching solutions (Cameron Purdy has
one- Coherence 2.2) that can persist to file system.

James Hicks

-----Original Message-----
From: A mailing list for Java(tm) 2 Platform, Enterprise Edition
[mailto:J2EE-INTEREST@JAVA.SUN.COM] On Behalf Of Justin Wesbrooks
Sent: Monday, August 04, 2003 9:59 AM
To: J2EE-INTEREST@JAVA.SUN.COM
Subject: Serving files dynamically


I currently have a site that allows customers to come view reports for
some information we keep.  The requirement is to keep a 2 year history
on these reports.  Currently, the reports are generated dynamically
every time (even for the 1 year old reports).  I want to make a
modification to the site to archive the reports (excel spreadsheets)
that are X weeks old and serve the customer the archived report rather
than generate it.  The report is generated on large amounts of data and
takes a while to generate.  Has anyone done this or is there a best
practice for something like this? Also, the report will be different for
each customer that comes to the page, with the maximum number of
customers being around 30.

========================================================================
===
To unsubscribe, send email to listserv@java.sun.com and include in the
body of the message "signoff J2EE-INTEREST".  For general help, send
email to listserv@java.sun.com and include in the body of the message
"help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff J2EE-INTEREST".  For general help, send email to
listserv@java.sun.com and include in the body of the message "help".


=========================================================================== To unsubscribe, send email to listserv@java.sun.com and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@java.sun.com and include in the body of the message "help".

©2008 junlu.com - Jax Systems, LLC, U.S.A.