• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a clarification on Spring

 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on Spring and I am having a small doubt.
When we try to refer to the dao at the manager,which is the ideal way of coding.
<code>
public class JdbcManager implements com.altum.jdbc.manager.JdbcManager {
private JdbcDao jdbcDao;
public Map getResultSetData(String sql) throws SQLException{
return this.getJdbcDao().getResultSetData(sql);
}
</code>
Is this right
{OR}
<code>
public class JdbcManager implements com.altum.jdbc.manager.JdbcManager {
private JdbcDao jdbcDao;
public Map getResultSetData(String sql) throws SQLException{
return jdbcDao.getResultSetData(sql);
}
</code>
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are only talking about whether to use this or not, it doesn't matter unless your method contains a local variable of the same name.
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing was I wanted to know which of them is the ideal way of writing.
Somewhere I had read that the best practice is to write
getJdbcDao().getResultSetData(sql)
as this incorporates the Spring dependency injection to the fullest.

Thats Y I raised this question as to which way is considered the best practice.

Thanks,
-Viidhya
 
Paul Yule
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shriya Kishore:

Somewhere I had read that the best practice is to write
getJdbcDao().getResultSetData(sql)


I believe that's referring to the fact that getResultSetData is dependant on the getJdbcDao and any advisors will not neccessarily be called on the Dao if the advice was written for the method specifically instead of watching the object as a whole. Basically encapsulation at its most complex. With spring your depencies are often counting on that encapsulation.
[ November 18, 2008: Message edited by: Paul Yule ]
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry Paul.
But I did not quite follow.
Let me rephrase : using the getter method for the dao
i.e getJdbcDao() is it better than using jdbcDao?

-Viidhya
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shriya Kishore:
I am sorry Paul.
But I did not quite follow.
Let me rephrase : using the getter method for the dao
i.e getJdbcDao() is it better than using jdbcDao?

-Viidhya


Not unless you have additional logic in the getJdbcDao() method.
 
Paul Yule
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well then I did a poor job of explaining myself and this may totally be off the mark but here goes...

You can set up advice at different levels of your objects. However if you set up a point cut/ advice on the getter method of your DAO which you often do so that you may check to see if the DAO already has connections or objects. This way you don't make them again if you do not call the getter method then advice that was specifically placed on the getter method getJdbcDao() will not run. If the advice had dependant code in it for methods inside the DAO then it isn't impossible (although highly unlikely that anyone would put dependant code there) that it could break.
[ November 18, 2008: Message edited by: Paul Yule ]
 
Paul Yule
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:


Not unless you have additional logic in the getJdbcDao() method.


Exactly, however what would happen should you go back and for some strange reason have dependant code inside the getJdbcDao() method? Well along the same lines is dependant code inside the advice of that same method. If you just used the jdbcDao without the call then you would need to alter the code to call the get method so the code inside the advice runs. Really it's one of those things that yea--it's best practice-- but if it breaks because you didn't then there is something likely wrong elsewhere.
[ November 18, 2008: Message edited by: Paul Yule ]
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.
So its a best practice to have it the getter way.

Thanks a lot everyone for your valuable responses.

-Viidhya
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Viidhya, please check your private messages for an administrative matter.

Thanks.
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure Gregg.
I rectified the issue
Thanks.

-Viidhya
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vidhya N:
Sure Gregg.
I rectified the issue
Thanks.

-Viidhya


Almost. Just need more of a last name. Your first name can be an initial but not the last name. Sorry to be so particular but it helps keep our culture here at JavaRanch.

Thanks for understanding.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic