James,

J2EE EJB containers are not required to implement persistence mechanisms in
any particular way.  Because the interface between J2EE servers and EJB
containers is left up to the server vendors, I do not believe that there is
any "standard" way to communicate with a container to determine what, if
any, datasources have been configured.  

If no datasources have been configured, then there will likely be some kind
of EJB deployment error when Orion (or presumably other EJB servers) start
up.  For example, if you set up Orion to run the Cart demo, but do not
configure any data source, it will probably complain.  

Though some container vendors may provide methods to communicate with their
servers and containers, I do not believe the spec requires that they do so.

The only possible way I can think of to do this would be to do a JNDI
lookup of the name of the default database.  In datasources.xml there is
are "location", "ejb-location", "xa-location" and "pooled-location"
parameters that are defined in orion/docs/data-sources.xml.html:

"location - The JNDI-path to bind this DataSource to."

"ejb-location - The JNDI-path to bind an EJB-aware and pooled version of
this DataSource to. (only applies to ConnectionDataSources). This version
of the datasoruce will automatically take part in container-managed
transactions and is the type of source that should be used from within EJBs
and similar (if you use a "clean" datasource you loose the
container-managed transactions support)."

Here's an example data-source.xml file provided by Orion:
<data-sources>

<data-source 

name="Default data-source"
class="com.evermind.sql.ConnectionDataSource"
location="jdbc/DefaultDS"
pooled-location="jdbc/DefaultPooledDS"
xa-location="jdbc/xa/DefaultXADS"
ejb-location="jdbc/DefaultEJBDS"
url="jdbc:HypersonicSQL:defaultdb"
connection-driver="hSql.hDriver"
username="xxx"
password="yyy"
schema="database-schemas/hypersonic.xml"

/>
</data-sources>

What this says to me, is that you should be able to look up the "location",
"ejb-location", "pooled-location", and "xa-location" in JNDI under the
"jdbc" tree.

So, I added the following code to the simple Cart EJB demo in Orion:
  Object dumObject = context.lookup( "jdbc/DefaultDS" );
  System.out.println( dumObject );
 
When I ran the Cart demo, it printed out the following:
jdbc:HypersonicSQL:hsql://localhost
Item not found in cart: Oranges

So, you can see that it found my default data source, which is the "server"
version of HypersonicSQL.

Hope this helps.  Anyone else out there?

Jay Armstrong
[EMAIL PROTECTED]

At 04:30 PM 3/2/01 -0600, you wrote:
>
>Is there a j2ee standard way to get the default datasource (that your CMP
>beans would be using) from a servlet or a session bean?
>
>
>Thanks,
>James
>
>
>


Reply via email to