Nikolaos Giannopoulos <nikol...@...> writes:

> 
> Milan,
> 
> In that case why bother with a DAO at all?  i.e. although it would be 
> nice to plug in a DB later the problem you are going to have is where to 
> store the information for the life of a user session and that is 
> typically going to be on the session itself... however until you pass 
> the http request to the DAO you won't have access to that.
> 
> Personally... I see 2 obvious choices:
> 
> #1  Use DAO's and add arguments to pass in the http request / session.
> 
> #2  Use a custom action bean context as I showed you in the previous 
> reply and put access methods on the context itself.
> 
> I would go with #2 regardless so that it encapsulates the data you are 
> retaining.
> 
> And if you need to create the additional abstraction or will want to 
> eventually go to a DB then wrap #1 around it but in that case you will 
> want to eventually change both the DAO interfaces (as the http request / 
> session will no longer be required) and the DAO implementation;  doesn't 
> totally defeat the purpose of a DAO abstraction but isn't the right thing.
> 
> In fact, the more I think about it I would look at a different design 
> pattern altogether that focuses on maintaining state or simply do #2.
> 
> --Nikolaos
> 
> Milan Halenar wrote:
> > Milan Halenar <mhale...@...> writes:
> >
> >
> >
> > Ad: im not using any DB, im just storing the content of file in memory in 
the 
> > FileParser class in an ArrayList. And i need for every session to have its 
own 
> > instance of that class. I hope i cleared it a bit.
> >
> >
> >
> > 
------------------------------------------------------------------------------
> > _______________________________________________
> > Stripes-users mailing list
> > stripes-us...@...
> > https://lists.sourceforge.net/lists/listinfo/stripes-users
> >   
> 
> -----------------------------------------------------------------------------

When i was writing the DAO, i was inspired by the book "Stripes and Java, web 
developement is fun again", so i made my class look like this:

---
public class FileParser {

   
    private List<NetflowRecord> records = new ArrayList<NetflowRecord>();
    private static FileParser fp = new FileParser();
    private long TIMECONST = 30L;
    private boolean isColored= false;
    
    private FileParser() {
    }
  

    public static FileParser getInstance() {
        return fp;
    }

//getters and setters

 public void parseFile(File file) { 
 //get contents from file to the Arraylist
}
---

In my ActionBean it looks:

public class TableActionBean implements ActionBean {

private FileBean newAttachment;
private FileParser fp = FileParser.getInstance();

 public Resolution upload() throws IOException {

        File tmpFile = File.createTempFile("temp", "txt");
        fp.parseFile(tmpFile);
        context.getRequest().setAttribute("loaded", true);
        return new RedirectResolution("/index.jsp");

    }


---

Now the situation: when I upload the file, i can see its contents from other 
sessions(browsers) as well, and i wanted to have new instance with another data 
for every session. So your suggestion #2 setting the FileParser up in the 
ActionBeanContext will do the trick? Sorry for being a bit confusing.




------------------------------------------------------------------------------
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to