Announcement Announcement Module
No announcement yet.
Should DAO's be singleton Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Should DAO's be singleton


    Is if fine that DAO's be singleton
    since there is state involved ...are there any thread safe issues..


  • #2
    Depends what state you are introducing into the DAO

    If you are using one of the Spring XXXDaoSupport classes then yes, these are threadsafe.

    In as much as any sweeping generalisation is a good thing; yes, your DAOs and Services should be singleton.


    • #3
      Thanks for such a prompt..reply..

      But i asked the question in the backdrop..of this query..

      In between the DAO and the controller there is a business class..

      should i ...have even that as ..singleton="false"...

      since it has request parameters,other checking..and manipulation of response state is invloved...


      • #4
        I see.

        So you are trying to dependency inject a prototype into a singleton...yeah, that won't work.

        Without knowing a bit more about your situation, if you want to maintain stateful web beans (i.e. a User which you update in a number of steps) then you might consider Spring Web mention that the stateful bean is a "business class" which might imply it isn't a web artifact....

        Can you give concrete class names to provide context for this?


        • #5
          We cant use spring webflow because of client restrictions...

          I didnt get this...

          Can you give concrete class names to provide context for this?


          • #6
            Rather than ClassA and ClassB it would be easier to understand your situation if we had some meaningful names


            • #7
              Got it...

              public class ExtensionController implements Controller{


              RequestTags rtags=createRequestTags();
              //public method which spring populates with the object @ runtime


              return ...;



              publci RequestTags createRequestTags(){
              return null;

              Service business class
              publci class RequestTags{

              List serviceRequest(){

              //public method which spring populates with the object @ runtime
              TagRetrieve tagret=createTagRetrieve();

              List obj= tagret.getTags();
              List obj1=checkResponse(obj);
              return obj1;


              List checkResponse(List obj){

              return obj1;

              publci TagRetrieve createTagRetrieve(){
              return null;
              //Intermediate class

              public class TagRetrieve{
              List getTags(){
              //Connect to backend & gets the tags
              //The below 2 lines are mandatory to get connected to this backend..
              Access a=new Access();
              Arraylist arraylist =a.getTags();

              return arraylist;
              Last edited by A Kumar; Aug 7th, 2007, 11:18 AM. Reason: added some code