• Post Reply Bookmark Topic Watch Topic
  • New Topic

File I/O without using EJB??

 
Alok Garg
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I have typical Project requirement.
1) I want to update a Database.
2) I need to write a file to a Disk.
The above should happen in one transaction.
The real problem is that I cannot use any EJB's to write a file to a disk, the other problem is that I have to use a servlet which I need to keep with my other EJB's so that my file is saved to one place where all the Data transaction is taking place I cannot pass this Servlet in webContainer.
Can anybody help me with the above problem and if you can suggest me a good soild design pattern it would be helpful
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hogwash! you can too do this within an EJB. As I've stated about a dozen times within Javaranch in the last month alone :roll: there is NOTHING that actually prevents you from writing to a file within an EJB. However, it'd be neater to write a plain old Java class that writes to the file and is called by the EJB, but that's beside the point.
Make sure that you do a setRollbackOnly() if there's a failure writing to the file, too.
Kyle
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kyle Brown:
Hogwash! you can too do this within an EJB. As I've stated about a dozen times within Javaranch in the last month alone :roll: there is NOTHING that actually prevents you from writing to a file within an EJB. However, it'd be neater to write a plain old Java class that writes to the file and is called by the EJB, but that's beside the point.
Kyle

True, but personally, I'd feel more comfortable starting a transaction within the servlet and doing both EJB work and file I/O relative to the servlet and its transaction wrapper. OR have the servlet invoke a utility class that wraps this functionality. Admittedly in some cases the difference between such a utility class and a Session EJB that does I/O can be pretty thin, though.
It sounds like in this specific instance, however, the idea is to have an atomic function that can be accessed by multiple servlets, possibly under multiple servers ???
Two other possibilities to keep things "ideologically pure" (actually I can't abide ideology, but I DO try demonstrate some cleverness by making things work WITHIN the framework - I just reserve the right to toss the framework if the "proper" solution becomes more unwieldy than an "improper" one).
Anyway:
1) If the EJB server supports alternative forms of persistency, see if you can make your file work as opne of those forms.
2) Consider storing the file as a BLOB or CLOB in a regular EJB
And, related to it - ask the question "Does this REALLY need to be a FILE?"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!