Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DAO to Instance variables

 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bunch of DAO classes that extend the class called BaseDAO, that has instance variables like ....

private Connection _conn = null;

private boolean b_connIsReference = false;

private PreparedStatement _pstmt = null;

private Statement _stmt = null;

private ResultSet _rs = null;

private OracleCachedRowSet _crs = null;

private OracleConnectionFactory _connfactory = null;

/** stored procedure use */
private CallableStatement _cs = null;

/** @associates String */
private ArrayList a_columnNames = new ArrayList();

/** @associates String */
private ArrayList a_whereValues = new ArrayList();


Besides that the DAOs' that extend the BaseDAO. The corresponding DAOs also have the instance variables.


An instance of BaseDAO is created every time to get a copy of the instance variable.

An instance of corresponding DAO is also created whenver the DAO is has a request.

The apllication is working with out any issues.

Question...

Is it OK to have instance variables in DAOs?

Is my current design efficient?

Appreciate expert opinion and thanks in advance.
[ November 05, 2006: Message edited by: Bear Bibeault ]
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Puthriah Sarma:

Is it OK to have instance variables in DAOs?

Is my current design efficient?

Appreciate expert opinion and thanks in advance.



It totally depends !!

It depends on how you are organising your code.I will not prefer to use any variable as instance variable, which deals with database.

Using connection,statement or resultset as instance variable means you are going to use them across method.

And it is very likely that you get unexpected result.

Let say you are sharing instance variable of connection ! and in one method you close the connection and in another method you get error because of close connection. and If you don't close connection it may be possible you forget to close connection in other method.

That is why say It totally depends how you organise your code.


Shailesh
 
Prashant kumar Singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you are using a lot of instance variables there there will be unsafe.when multiple threads will access then there thread unsafe.
So if there is most requirement of those var then declare it as instance var else as local.
Regards,
Prashant kumar Singh
 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all for the valuable feed back
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic