aspose file tools*
The moose likes Other Application Frameworks and the fly likes a clarification on Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "a clarification on Spring" Watch "a clarification on Spring" New topic
Author

a clarification on Spring

Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
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

Joined: May 12, 2008
Posts: 229
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

Joined: Jan 03, 2007
Posts: 99
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: May 12, 2008
Posts: 229
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

Joined: May 12, 2008
Posts: 229
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

Joined: Jan 03, 2007
Posts: 99
ok.
So its a best practice to have it the getter way.

Thanks a lot everyone for your valuable responses.

-Viidhya
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Viidhya, please check your private messages for an administrative matter.

Thanks.
Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
Sure Gregg.
I rectified the issue
Thanks.

-Viidhya
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: a clarification on Spring