You can't catch EJBException in you client code - it will cause the server
to destroy your bean instance.

Tom
 
On Mon, 5 Mar 2001 [EMAIL PROTECTED] wrote:

> Below is ejbCreate.  The call to startService() is in a try...catch(Throwable)
> block, so I should catch the SQLException.  I'm not sure what I'm missing.
> 
> Also, I'm new to EJBs, could you explain the portability issue?
> 
> Rob
> 
> 
>     public void ejbCreate() throws EJBException
>     {
> 
>         try
>         {
>             //try to get a connection to the DB
>             connection = getConnection();
>         }
>         catch (DatabaseConnectionException dce)
>         {
>             dce.printStackTrace();
>             throw new EJBException(dce.getMessage());
>         }
>         catch (NameNotFoundException ne)
>         {
>             //this exception indicates that the MBean for the EME DB has
>             //not been created
>             XADataSourceLoader ds = null;
>             ObjectName oname = null;
>             MBeanServer server = null;
>             try
>             {
>                 ArrayList servers = MBeanServerFactory.findMBeanServer(null);
>                 //there should be just one server in this JVM, the server for
>                 //jBoss
>                 if (servers.size() > 0)
>                 {
>                     server = (MBeanServer) servers.get(0);
>                     //create an ObjectName for this MBean
>                     oname = new ObjectName(server.getDefaultDomain() +
>                                            ":service=XADataSource,name=" +
> 
> SiteContext.EME_CONNECTION_POOL_NAME);
>                     //create the data source loader (as you might expect this
>                     //class is the MBean)
>                     ds = new XADataSourceLoader(
> SiteContext.EME_CONNECTION_POOL_NAME,
> 
> "org.jboss.minerva.xa.XADataSourceImpl");
>                     //configure the MBean
>                     configDS(ds);
> 
>                     //register the MBean with the server
>                     server.registerMBean( ds, oname );
> 
>                     //start the MBean
>                     ds.startService();
>                 }
>             }
>             catch(Throwable e)
>             {
> System.out.println("Exception caught!");
>                 //stop and unregister the MBean service if it was created
>                 if (ds != null)
>                     ds.stopService();
> 
>                 try
>                 {
>                     if (oname != null)
>                         server.unregisterMBean(oname);
>                 }
>                 catch (Exception se)
>                 { }
> 
>                 e.printStackTrace();
>                 throw new EJBException(e.getMessage());
>             }
> 
>             //try to get a connection again
>             try
>             {
>                 connection = getConnection();
>             }
>             catch (DatabaseConnectionException dcex)
>             {
>                 dcex.printStackTrace();
>                 throw new EJBException(dcex.getMessage());
>             }
>             catch (NameNotFoundException nex)
>             {
>                 nex.printStackTrace();
>                 throw new EJBException(nex.getMessage());
>             }
>         }
> 
> 
> 
>     }
> 
> 
>     private Connection getConnection() throws DatabaseConnectionException,
>                                               NameNotFoundException
>     {
> 
>         Connection conn = null;
> 
>         try
>         {
>             Object object = SiteContext.lookup(SiteContext.EME_CONNECTION_POOL);
>             if (object != null)
>             {
>                 javax.sql.DataSource dataSource = (javax.sql.DataSource)
>                                      PortableRemoteObject.narrow(object,
> javax.sql.DataSource.class);
>                 conn = dataSource.getConnection();
>             }
>         }
>         catch(NameNotFoundException nnfe)
>         {
>             //NameNotFoundException is a subclass of NamingException.  Want
>             //getConnection to throw NameNotFoundException if it occurrs
>             //rather than a DatabaseConnectionException
>             throw nnfe;
>         }
>         catch(NamingException ne)
>         {
>             throw new DatabaseConnectionException(ne,
> FPException_I.ERROR_STOP_PROCESSING_IMMEDIATELY);
>         }
>         catch(SQLException se)
>         {
>             throw new DatabaseConnectionException(se,
> FPException_I.ERROR_STOP_PROCESSING_IMMEDIATELY);
>         }
> 
> 
>         return conn;
>     }
> 
> 
> 
> 
> 
> |--------+---------------------------------->
> |        |          Toby Allsopp            |
> |        |          <[EMAIL PROTECTED]>|
> |        |          Sent by:                |
> |        |          <[EMAIL PROTECTED]|
> |        |          -dogs.com>              |
> |        |                                  |
> |        |                                  |
> |        |          03/03/01 05:47 AM       |
> |        |          Please respond to       |
> |        |          "JBoss-User"            |
> |        |                                  |
> |--------+---------------------------------->
>   >----------------------------------------------------------------------------|
>   |                                                                            |
>   |       To:     JBoss-User <[EMAIL PROTECTED]>                |
>   |       cc:                                                                  |
>   |    Groups: Don't Expand                                                    |
>   |       Subject:     Re: [jBoss-User] dynamically adding XADataSourceLoader  |
>   |       MBean                                                                |
>   >----------------------------------------------------------------------------|
> 
> 
> 
> [EMAIL PROTECTED] wrote:
> 
>  > i've dynmically added a XADataSourceLoader MBean during program
>  > execution, and i was testing the behavior if the connection failed.
>  >   an exception is thrown inside jBoss, but it isnt' returned to my
>  > application.  (the exception is shown below)  unless i've missed
>  > something, i correctly handle a SQLException in
> EMEDBAdapaterEJB.ejbCreate()
>  >   any ideas why this is happening?
> 
> Well, from the stacktrace, it looks like you're not catching the
> SQLException. Can you post the code?
> 
>  > also, what should be the behavior of jBoss is a connection is lost?
>  >  is there a built-in recovery mechanism or a facility to add an
>  > application level recovery mechanism?
> 
> The idea of throwing the SQLException if there's a problem in
> startService is so that the pool will be shut down if there's a problem.
> I'm too lazy to look it up right now, but the code that normally calls
> startService etc on the MBeans will catch the exception and kill the MBean.
> 
> What really interests me about this is why you would want to create a
> new connection pool in ejbCreate. There's no way that's going to be
> portable.
> 
> Toby.
> 
> 
> 
> --
> --------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> 
> 
> 
> 
> 
> 
> 
> --
> --------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> 
> 

-- 
"If you mess with something for long enough it will break." - Schmidt



--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]

Reply via email to