Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File IO in Stateless Session bean

 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Requirement : Read contents of a text file and upload the same to Oracle database (table).

I have created a Java class (application kind of) which opens, reads a file and transfers its data to a Oracle table.

Can I instantiate the same class within a Session Bean to perform the same operation or as per the EJB Restrictions this is not supposed to be done?

EJB Specifications 2.1 pdf guide
(refer 25.1.2 Programming restrictions
An enterprise bean must not use the java.io package to attempt to access files and directories in the file system. The file system APIs are not well-suited for business components to access data. Business components should use a resource manager API, such as JDBC, to store data.
)

Awaiting ur responses at the earliest.

Thanking in advance,

Seetesh
 
Aboo Bolaky
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ya...
yeah ure right...the EJB specs specifically says that EJBS cannot perform file i/o. if u need to log messages or access files, you must find another mechanism...
 
Rajan Punchouty
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick follow up.... rather a doubt...
How does Log4J work with EJB's then???
 
Aboo Bolaky
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The other mechanism as Rajan pointed out is Log4J..
have a look at Vikram Goyal's introductory explanation
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aboo and Rajan,

Thks for ur post. I am using Log4J but my query was that I want to read a file (txt file) and insert its contents in a oracle table.

I have one file called FileIO.class which does the same. Question is If I instantiate this class in a business method of Stateless Session Bean and call the appropriate method of uploading the file contents in a oracle table, will it create any issues?

I am not bothered abt transaction issues here.

Rgds,

Seetesh
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can have a util class. which could has a method which reads the file and returns a string. just call that method from your bean, pass the filename and get the string.

how it sounds?
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just trying the same. Will revert back shortly.

Seetesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic