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

  • Should DAO's be singleton

    Hi,

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

    Regards

  • #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.

    Comment


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

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

      http://forum.springframework.org/showthread.php?t=41714


      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 ..so state is invloved...

      Comment


      • #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 Flow....you 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?

        Comment


        • #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?

          Comment


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

            Comment


            • #7
              Got it...


              public class ExtensionController implements Controller{

              handleRequest(REQUEST,RESPONSE){
              checkCookie();

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

              rtags.serviceRequest();

              return ...;
              }

              checkCookie(){

              }

              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

              Comment

              Working...
              X