Announcement Announcement Module
Collapse
No announcement yet.
A re-usable connection per user? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • A re-usable connection per user?

    I was wondering what the best approach is to maintaining a connection throughout a users session, on a per-user basis. This means multiple connections at any one time, so SingleConnectionDataSource presumably wont work, yet I don't want to create a new connection with every getConnection() call (too much overhead). One solution is to write my own session bean which maintains a connection for the user, however I was wondering if there was a better, more "spring-y" way to do it?

  • #2
    Ehrm why on earth would you do that... What is wrong with a connection pool????

    Comment


    • #3
      Because each user uses their own username and password to connect to the database, so they cant share a pool of common connections.

      Comment


      • #4
        Sure they can... Have a look at the UserCredentialsDataSourceAdapter (and use the forum search because I answered questions about that quite a few times). You really don't want to cache a Connection through out the user session, if you have a lot of concurrent users, your database will stop working or at least run out of connections...

        Comment


        • #5
          Yea I'm aware of UserCreditialDataSourceAdapter, but according to the javadoc it simply parameterises the getConnection() call to the underlying datasource with the username and password. The semantics for getConnection() for most data sources is to return a new connection every time that method is called, I looked into commons DBCP, however I cant find any documentation explaining the semantics of PerUserConnectionPool beyond the sparse javadoc, I presume that is the data source I ought to be using?

          Comment


          • #6
            Oops, not PerUserConnectionPool, I meant PerUserPoolDataSource

            Comment

            Working...
            X