3 Replies Latest reply on Aug 26, 2002 11:05 AM by davidjencks

    Dynamic selection of datasource

    charoy

      Hello,

      we have a specific problem and i'm not sure it is possible to solve it simply.

      Our application needs to access to data that can be in several database. I would like to use CMP Bean but I don't know how to select dynamically the datasource.
      From the JCA spec, it is possible to provide the factory with some properties to build the connection but i don't see a simple way to provide the information needed to the connection factory (the connection url or a way to compute it). Is there a way to do that or do we have to stay with BMP ?
      In our application a Bean may be store in different databases. The database can only be selected when we try to find the bean and load it.

      François

        • 1. Re: Dynamic selection of datasource
          davidjencks

          The jca spec explicitly says in several places that a deployed connection factory is expected to communicate with only one EIS instance, and that connection properties you supply should not include urls etc to specify which EIS instance to use.

          Your proposal doesn't make sense to me yet. How exactly are you determining which database to access? If you supply enough info I may be able to suggest a way to do what you want.

          For instance, Dan Bunker wrote a modified adapter that supplied connections to different databases depending on the security info of the caller (different users get different dbs).

          • 2. Re: Dynamic selection of datasource
            charoy

            I agree that it may sounds like a strange scenario and I just reached the same conclusion as you.
            The problem is that our database is partitionned horizontally mainly for performance reason, also because we have some legacy software that works with these databases and to allow some scenario that we have in mind.
            Thus the database containing the bean is known in the session that wants to instantiate it. We don't need to pass an url but just some data from which we are able to retrieve the Database.
            At this time the only solutions are BMP or SB with direct connection. I checked the code and did not find other easy way to do it.

            The adapter of Dan Bunker may be a solution if we are able to pass other data than just the security info which is not sufficient. Our partitionning does not depends on the user. Is this code available somewhere ?

            François

            • 3. Re: Dynamic selection of datasource
              davidjencks

              unfortunately Dan's code is stuck on my laptop which is having network problems at the moment.

              I don't think a fancy datasource will help you unless you can figure out a way to call the entities with different security information depending on which db you want to use.

              How about deploying the entity beans multiple times, once per database, under different jndi names? Then you can look up the home depending on which db you want, but the Home interface will always be the same.