> On Wed, 7 Mar 2001 23:57:45 -0800, Gene Chuang <[EMAIL PROTECTED]>
> wrote:
> >I think a better question to ask first is WHY do you need to know if a class
> >of yours is running in a container?
>
> The way you ask that seems to imply that there's something inherently
> wrong with such a requirement, so I'll explain. I have lots and lots
> of database I/O code that does object-relational mapping. I need to
> run this code in both EJB and non-EJB applications. To get a JDBC
> Connection in an EJB container, I do a JNDI lookup on a DataSource,
> which gives me the connection, and when I'm done with it, to place it
> back in the container's connection pool, I call its close() method. If
> I'm in a non-EJB application, I use the standard
> DriverManager.getConnection() call to create a connection, a homemade
> ConnectionPool class to pool it, and when I'm done with it, I place it
> back in the pool rather than calling its close() method.
Given that explanation, one question would be wether or not you can afford
to make the Connection pool package act as a DataSource. If so, you might
be able to access it in the same way that you access the EJB DS.
[...snip...]
> Some responders suggested trying a new InitialContext().lookup(), and
> if it failed, the code could assume it was running outside of an EJB
> container. This would probably work in most cases, but it wouldn't be
> guaranteed to always work. There might just be a jndi.properties file
> lurking in the classpath pointing to a live JNDI service.
I disagree. The way to do this is to define a specific environment setting
in your EJB deployment that is available via InitialContext.lookup(). That
lookup will fail, regardless of other JNDI contexts, if you are not running
within your EJB app server.
tim.
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".