11 Replies Latest reply on Jun 30, 2003 5:16 PM by Ivan O. Parra

    how to configure multiple data sources in standardjbosscmpjd

    cliffwei Newbie

      And how to configure multiple data sources in deploy/jms/jbossmq-service.xml a

        • 1. Re: how to configure multiple data sources in standardjbossc
          Ivan O. Parra Novice

          1)You should be able to configure as many datasources as you want, as long as the have unique JNDI names and JMX Object Names. A bunch of sample datasource can be found under jboss/docs/examples/jca

          2)CMP
          You can assign a default Datasource for all entities, then override each individual entity. Here is a snippet from the cmpjdbc.dtd
          <!ELEMENT entity (ejb-name, (datasource, datasource-mapping)?, create-table?,
          remove-table?, read-only?, read-time-out?, row-locking?,
          pk-constraint?, read-ahead?, list-cache-max?, fetch-size?, table-name?,
          cmp-field*, load-groups?, eager-load-group?, lazy-load-groups?,
          query*)>

          You can specify your unique datasource per entity which overrides the default.

          3) JMS, in jbossmq-service.xml, you'll see this line
          <depends optional-attribute-name="ConnectionManager">jboss.jca:service=LocalTxCM,name=DefaultDS

          You can change DefaultDS to be any name that you set your DS to in step 1.

          I don't know if you can specify a different persistent mechanism per Topic/Queue, would be nice though.

          Answer your question?



          • 2. Re: how to configure multiple data sources in standardjbossc
            cliffwei Newbie

            sorry, still not clear

            If I have multiple data sources specified in 1, for JMS,
            name=DefaultDS---> Here how can I put several JNDI names here?

            • 3. Re: how to configure multiple data sources in standardjbossc
              Ivan O. Parra Novice

              Is this(sorta) what you are trying to do:

              Datasources: OracleDS, InformixDS

              JMS Destinations: TopicA, TopicB

              Are you trying to link TopicA with OracleDS and TopicB with InformixDS?

              Originally, I thought it could not be possible. But I just read through the descriptors and I think it may be possible. Before I bang my head into the wall a few times, I want to make sure that the answer to this scenario is what you're looking for.

              -Ivan

              • 4. Re: how to configure multiple data sources in standardjbossc
                cliffwei Newbie

                sorry I am not clear about the JMS destination.
                Acutally I am using DefaultDS to store Message queue.
                So I don't need to modify jbossmq-service.xml file?
                I have another three databases needed to be configured to store the application data. So I have added another mysql-petstore-ds.xml in deploy directory and I have modified the login-config.xml to add these three data sources. I have modified the standardjaws.xml and standardjbosscmpjdbc.xml .
                I don't know if it is correct. :

                java:/jdbc/opc/OPCDB;java:/jdbc/petstore/PetStoreDB;java:/jdbc/supplier/SupplierDB
                <datasource-mapping>mySQL</datasource-mapping>

                the application still cannot connect to the three application data sources correctly, I don't know why

                • 5. Re: how to configure multiple data sources in standardjbossc
                  Ivan O. Parra Novice

                  I don't think you can do that.
                  The datasource field, as I understand, is what the CMP engine will use to access the ds from jndi. The datasource mapping instructs the CMP engine on how to create its SQL for each individual driver type(someone correct me if I'm wrong). Having more than 1 Datasource(as in your example) will probably not work. I'm going to guess that it if doesn't offer a runtime error, it'll only use the first DS and ignore the rest.


                  If you want to use a multiple DS, you should specify the non-default DS for each entity in the jbosscmp-jdbc.xml that would use a different DS. Only 1 DS per Entity. You'll still need multiple -ds.xml files to define each DS.

                  -Ivan

                  • 6. Re: how to configure multiple data sources in standardjbossc
                    cliffwei Newbie

                    here is the modified version of standardjbosscmpjdbc.xml after taking your advice

                    But I can only find two data sources DefaultDS and OPC, Can you tell me how to modify it?

                    Do I need to modify standardjaws.xml? Isn't it the file for old CMP?

                    THANK YOU VERY MUCH


                    DefaultDS
                    <datasource-mapping>Hypersonic SQL</datasource-mapping>


                    <create-table>true</create-table>
                    <remove-table>false</remove-table>
                    <read-only>false</read-only>
                    <time-out>300</time-out>
                    <pk-constraint>true</pk-constraint>
                    <fk-constraint>false</fk-constraint>
                    <row-locking>false</row-locking>
                    <preferred-relation-mapping>foreign-key</preferred-relation-mapping>
                    <read-ahead>
                    on-load
                    <page-size>1000</page-size>
                    <eager-load-group>*</eager-load-group>
                    </read-ahead>
                    <list-cache-max>1000</list-cache-max>

                    <unknown-pk>
                    <key-generator-factory>UUIDKeyGeneratorFactory</key-generator-factory>
                    <unknown-pk-class>java.lang.String</unknown-pk-class>
                    <jdbc-type>VARCHAR</jdbc-type>
                    <sql-type>VARCHAR(32)</sql-type>
                    </unknown-pk>

                    <entity-command name="default"/>





                    java:/jdbc/petstore/PetStoreDB
                    <datasource-mapping>mySQL</datasource-mapping>


                    <create-table>true</create-table>
                    <remove-table>false</remove-table>
                    <read-only>false</read-only>
                    <time-out>300</time-out>
                    <pk-constraint>true</pk-constraint>
                    <fk-constraint>false</fk-constraint>
                    <row-locking>false</row-locking>
                    <preferred-relation-mapping>foreign-key</preferred-relation-mapping>
                    <read-ahead>
                    on-load
                    <page-size>1000</page-size>
                    <eager-load-group>*</eager-load-group>
                    </read-ahead>
                    <list-cache-max>1000</list-cache-max>

                    <unknown-pk>
                    <key-generator-factory>UUIDKeyGeneratorFactory</key-generator-factory>
                    <unknown-pk-class>java.lang.String</unknown-pk-class>
                    <jdbc-type>VARCHAR</jdbc-type>
                    <sql-type>VARCHAR(32)</sql-type>
                    </unknown-pk>

                    <entity-command name="petstore"/>





                    java:/jdbc/opc/OPCDB
                    <datasource-mapping>mySQL</datasource-mapping>


                    <create-table>true</create-table>
                    <remove-table>false</remove-table>
                    <read-only>false</read-only>
                    <time-out>300</time-out>
                    <pk-constraint>true</pk-constraint>
                    <fk-constraint>false</fk-constraint>
                    <row-locking>false</row-locking>
                    <preferred-relation-mapping>foreign-key</preferred-relation-mapping>
                    <read-ahead>
                    on-load
                    <page-size>1000</page-size>
                    <eager-load-group>*</eager-load-group>
                    </read-ahead>
                    <list-cache-max>1000</list-cache-max>

                    <unknown-pk>
                    <key-generator-factory>UUIDKeyGeneratorFactory</key-generator-factory>
                    <unknown-pk-class>java.lang.String</unknown-pk-class>
                    <jdbc-type>VARCHAR</jdbc-type>
                    <sql-type>VARCHAR(32)</sql-type>
                    </unknown-pk>

                    <entity-command name="opc"/>





                    java:/jdbc/supplier/SupplierDB
                    <datasource-mapping>mySQL</datasource-mapping>


                    <create-table>true</create-table>
                    <remove-table>false</remove-table>
                    <read-only>false</read-only>
                    <time-out>300</time-out>
                    <pk-constraint>true</pk-constraint>
                    <fk-constraint>false</fk-constraint>
                    <row-locking>false</row-locking>
                    <preferred-relation-mapping>foreign-key</preferred-relation-mapping>
                    <read-ahead>
                    on-load
                    <page-size>1000</page-size>
                    <eager-load-group>*</eager-load-group>
                    </read-ahead>
                    <list-cache-max>1000</list-cache-max>

                    <unknown-pk>
                    <key-generator-factory>UUIDKeyGeneratorFactory</key-generator-factory>
                    <unknown-pk-class>java.lang.String</unknown-pk-class>
                    <jdbc-type>VARCHAR</jdbc-type>
                    <sql-type>VARCHAR(32)</sql-type>
                    </unknown-pk>

                    <entity-command name="supplier"/>

                    • 7. Re: how to configure multiple data sources in standardjbossc
                      Ivan O. Parra Novice

                      Fun Stuff...

                      Lets backtrace for a bit. Lets assume that the conf directory is untouched. Lets not concern ourselves with standardjbosscmp-jdbc.xml, jaws, or any other configuration in these directories. We can always override these values if we need to, but leave the defaults alone for now.

                      First we will need the different datasources. You can either have each datasource defined in seperate "-ds.xml" files, or all in one -ds.xml.(I recommend multiple DS files).

                      Second,
                      in your ejb.jar/META-INF/jbosscmp-jdbc.xml, your descriptor should look something like this:

                      <?xml version="1.0" encoding="UTF-8"?>
                      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">

                      <jbosscmp-jdbc>

                      java:/OracleDS
                      <datasource-mapping>Oracle9i</datasource-mapping>

                      <enterprise-beans>


                      <ejb-name>Binky</ejb-name>
                      java:/SomeOtherDS
                      <datasource-mapping>SomeOtherMapping



                      <ejb-name>Scape</ejb-name>
                      java:/ScapeDS
                      <datasource-mapping>ScapeMapping


                      </enterprise-beans>
                      </jbosscmp-jdbc>



                      This descriptor should deploy 2 CMP associated to their own DataSource with their respective mappings. Both CMPS override the defaults specified in this file as well as the the ones specified in the conf directory.

                      G/L... let me know how it turns out.

                      -Ivan

                      • 8. Re: how to configure multiple data sources in standardjbossc
                        cliffwei Newbie

                        Thank you very much for your help. But I don't have
                        ejb.jar/META-INF/jbosscmp-jdbc.xml since I am deploying some ear files. I cannot find these files in the source code,either. Then what should I do?

                        • 9. Re: how to configure multiple data sources in standardjbossc
                          Ivan O. Parra Novice

                          You should have a .jar either in the deploy directory(or some other place where the directory scanner is looking) or in an ear.
                          If you have it in an ear, then you should have a .ear/META-INF/application.xml that describes which modules make up this ear. One of these modules is your <some-cmp>.jar you want to configure. In that jar file, should be a <some-cmp>.jar/META-INF/jbosscmp-jdbc.jar that tells the CMP engine how to map the data to the database.

                          If this file is missing, the CMP Engine be assuming alot(DB, type mapping, name->row mapping, etc.) . I really don't know to what extent the CMP Engine will assume. I've always defined the jbosscmp-jdbc.xml, never thought about what would happen if I didn't have it.

                          Try creating a jbosscmp-jdbc.xml in your jar with a minimal entry and see what happens. Something like:

                          <?xml version="1.0" encoding="UTF-8"?>
                          <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">


                          <jbosscmp-jdbc>
                          <enterprise-beans>

                          <ejb-name>***my-ejb-name***</ejb-name>
                          java:/SomeOtherDS
                          <datasource-mapping>SomeOtherMapping



                          <ejb-name>Scape</ejb-name>
                          java:/ScapeDS
                          <datasource-mapping>ScapeMapping


                          </enterprise-beans>
                          </jbosscmp-jdbc>


                          It is quite possible that the CMPEngine is figuring all the information found in the jbosscmp-jdbc.xml from the jboss.xml/ejb-jar.xml. Pretty cool engine!

                          -Ivan

                          • 10. Re: how to configure multiple data sources in standardjbossc
                            cliffwei Newbie

                            THANK YOU VERY MUCH FOR YOUR HELP!

                            I did find jboss.xml & ejb-jar.xml in source code but I cannot find
                            jbosscmp-jdbc.xml ? Then what should I do?
                            create a jbosscmp-jdbc.xml myself?

                            • 11. Re: how to configure multiple data sources in standardjbossc
                              Ivan O. Parra Novice

                              Yeah, create the file.

                              BTW.. Check your hotmail account. :)