Announcement Announcement Module
Collapse
No announcement yet.
Hibernate/Bean wiring with Dynamic DB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate/Bean wiring with Dynamic DB

    Hi,

    I have an application where user selects the Database on the login screen. Can someone guide me how to configure the DataSource/Spring wiring in this scenario?

    Another requirement is NOT to use a connection-pool so I am using UserCredentialsDataSourceAdapter to set userId/password before each DAO call but don't know how/when to specify the DB name as well.

    Thanks,
    /t

  • #2
    You can always declare your datasource programmatically. If you don't want to use a connection pool, then you can either use DriverManagerDataSource or SingleConnectionDataSource. The latter uses a single connection for all processing but it requires a call to destroy() when you are done with your JDBC processing. The DriverManagerDataSource aquires a new connection for each use. Are you using transactions at all or do you relly on auto-commit?

    Comment


    • #3
      But how to tie DataSource to Hibernate SessionFactory/Beans

      But how to tie this DataSource to Hibernate SessionFactory and my DAOs those are configured in Spring's configuration file. Should I have an ApplicationContext for each user with a different DataSource? Or is it possible to switch DataSource in the Context for each DAO call?

      thanks
      /t

      Comment


      • #4
        Should I have an ApplicationContext for each user with a different DataSource?
        Possible, but I don't know how suitable this would be. It depends on your situation, I guess.

        Or is it possible to switch DataSource in the Context for each DAO call?
        If you watch the DAO support implementation, there isn't much going on there. Mostly setting and getting a XxxTemplate object. For example the hibernate dao support is mainly about this single liner:

        Code:
        template = new HibernateTemplate(sessionFactory);
        So I guess you can create your own DAO support with ease and allow setting the DataSource lazily (the original dao support classes are sealed by the word final).

        For other classes, I guess you will need a hand written factory bean selecting the right object according to some informations about the used data source and create objects as needed. (or even to create the data source). Just take a look on the FactoryBean type and its type hierarchy).


        Cheers,

        Martin (Kersten)

        Comment

        Working...
        X