• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

a clarification on Spring

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure Gregg.
I rectified the issue
Thanks.

-Viidhya
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic