db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/connector/main/org/apache/ojb/jboss ODMGFactory.java
Date Mon, 03 May 2004 23:06:56 GMT
arminw      2004/05/03 16:06:56

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerFactorySyncImpl.java
                        NamingLocator.java
               src/ejb/org/apache/ojb/ejb/odmg ODMGSessionBean.java
                        ODMGBaseBeanImpl.java
               src/connector/main/org/apache/ojb/jboss ODMGFactory.java
  Log:
  - move internal package org.apache.ojb.odmg.transaction to org.apache.ojb.broker.transaction.tm
  - adapt all API's to use new kernel based OJBTxManager, instead duplicate code in each API
  - Make org.odmg.Implementation implementation configurable via OJB.properties
  - Enable ConfigurableFactory class to instantiate private/protected classes too
  - Adapt ejb-examples
  - PBFSyncImpl class now release used connections before the JTA transaction was commited/rolled
back
  
  Revision  Changes    Path
  1.5       +21 -4     db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.java
  
  Index: PersistenceBrokerFactorySyncImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PersistenceBrokerFactorySyncImpl.java	4 Apr 2004 23:53:33 -0000	1.4
  +++ PersistenceBrokerFactorySyncImpl.java	3 May 2004 23:06:55 -0000	1.5
  @@ -23,8 +23,8 @@
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  -import org.apache.ojb.odmg.transaction.TransactionManagerFactoryException;
  -import org.apache.ojb.odmg.transaction.TransactionManagerFactoryFactory;
  +import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException;
  +import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryFactory;
   
   /* Copyright 2004-2004 The Apache Software Foundation
    *
  @@ -239,13 +239,30 @@
               else
               {
                   /*
  -                if in JTA-tx, we don't really close the underlying PB instance (return
to PB
  +                arminw:
  +                if in JTA-tx, we don't really close the underlying PB instance (return
PB
                   instance to pool, release used connection). As recently as the JTA was
                   completed we can return PB instance to pool. Thus after tx completion method
                   doRealClose() was called to close (return to pool) underlying PB instance.
  +
  +                But to free used resources as soon as possible, we release the used connection
  +                immediately. The JTA-tx will handle the connection status in a proper way.
                   */
                   if (log.isDebugEnabled())
  -                    log.debug("PB close was called, but do not close PB instance when in
JTA-tx");
  +                    log.debug("PB close was called, only close the PB handle when in JTA-tx");
  +                ConnectionManagerIF cm = serviceConnectionManager();
  +                if(cm.isInLocalTransaction())
  +                {
  +                    /*
  +                    arminw:
  +                    in managed environment this call will be ignored because, the JTA transaction
  +                    manager control the connection status. But to make connectionManager
happy we
  +                    have to complete the "local tx" of the connectionManager before release
the
  +                    connection
  +                    */
  +                    cm.localCommit();
  +                }
  +                cm.releaseConnection();
               }
               return true;
           }
  
  
  
  1.4       +31 -52    db-ojb/src/java/org/apache/ojb/broker/core/NamingLocator.java
  
  Index: NamingLocator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/NamingLocator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NamingLocator.java	4 Apr 2004 23:53:33 -0000	1.3
  +++ NamingLocator.java	3 May 2004 23:06:55 -0000	1.4
  @@ -41,25 +41,28 @@
        * Returns the naming context.
        */
       public static Context getContext()
  -
       {
           if (ctx == null)
           {
               try
               {
  -                log.info("Init NamingLocator");
                   setContext(null);
               }
               catch (Exception e)
               {
  -                log.error("Cannot instantiate the InitialContext.");
  -                log.error(e);
  +                log.error("Cannot instantiate the InitialContext", e);
                   throw new OJBRuntimeException(e);
               }
           }
           return ctx;
       }
   
  +    /**
  +     * Lookup an object instance from JNDI context.
  +     *
  +     * @param jndiName JNDI lookup name
  +     * @return Matching object or <em>null</em> if none found.
  +     */
       public static Object lookup(String jndiName)
       {
           if(log.isDebugEnabled()) log.debug("lookup("+jndiName+") was called");
  @@ -69,43 +72,17 @@
           }
           catch (NamingException e)
           {
  -            log.error("Lookup failed for: " + jndiName);
  +            throw new OJBRuntimeException("Lookup failed for: " + jndiName, e);
  +        }
  +        catch(OJBRuntimeException e)
  +        {
  +            throw e;
           }
  -        return null;
       }
   
  -//    private static synchronized void initContext() throws NamingException
  -//    {
  -//        try
  -//        {
  -//            Configurator configurator = OjbConfigurator.getInstance();
  -//            Configuration conf = configurator.getConfigurationFor(null);
  -//
  -//            //INITIAL_CONTEXT_FACTORY = "java.naming.factory.initial"
  -//            String fac = conf.getString(Context.INITIAL_CONTEXT_FACTORY, null);
  -//            //PROVIDER_URL = "java.naming.provider.url";
  -//            String url = conf.getString(Context.PROVIDER_URL, null);
  -//            //URL_PKG_PREFIXES = "java.naming.factory.url.pkgs";
  -//            String pkgs = conf.getString(Context.URL_PKG_PREFIXES, null);
  -//
  -//            prop = new Properties();
  -//            if (fac != null)
  -//                prop.put(Context.INITIAL_CONTEXT_FACTORY, fac);
  -//            if (url != null)
  -//                prop.put(Context.PROVIDER_URL, url);
  -//            if (pkgs != null)
  -//                prop.put(Context.URL_PKG_PREFIXES, pkgs);
  -//
  -//            setContext(prop);
  -//        }
  -//        catch (ConfigurationException ex)
  -//        {
  -//            log.error(ex);
  -//            throw new NamingException(ex.getMessage());
  -//        }
  -//
  -//    }
  -
  +    /**
  +     * Refresh the used {@link InitialContext} instance.
  +     */
       public static void refresh()
       {
           try
  @@ -115,27 +92,29 @@
           catch (NamingException e)
           {
               log.error("Unable to refresh the naming context");
  +            throw new OJBRuntimeException("Refresh of context failed, used properties:
"
  +                    + (prop != null ? prop.toString() : "none"), e);
           }
       }
   
  +    /**
  +     * Set the used {@link InitialContext}. If properties argument is <em>null</em>,
the default
  +     * initial context was used.
  +     *
  +     * @param properties The properties used for context instantiation - the properties
are:
  +     *  {@link Context#INITIAL_CONTEXT_FACTORY}, {@link Context#PROVIDER_URL}, {@link Context#URL_PKG_PREFIXES}
  +     * @throws NamingException
  +     */
       public static synchronized void setContext(Properties properties) throws NamingException
       {
  -        log.info("Properties for creating the initial context: " + properties);
  -        try
  +        log.info("Instantiate naming context, properties: " + properties);
  +        if(properties != null)
           {
  -            if(properties != null)
  -            {
  -                ctx = new InitialContext(properties);
  -            }
  -            else
  -            {
  -                ctx = new InitialContext();
  -            }
  +            ctx = new InitialContext(properties);
           }
  -        catch (NamingException e)
  +        else
           {
  -            log.error("# Instantiation of InitialContext failed #");
  -            throw e;
  +            ctx = new InitialContext();
           }
           prop = properties;
       }
  
  
  
  1.5       +3 -3      db-ojb/src/ejb/org/apache/ojb/ejb/odmg/ODMGSessionBean.java
  
  Index: ODMGSessionBean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/odmg/ODMGSessionBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ODMGSessionBean.java	5 Apr 2004 00:17:08 -0000	1.4
  +++ ODMGSessionBean.java	3 May 2004 23:06:56 -0000	1.5
  @@ -33,7 +33,7 @@
   import org.apache.ojb.ejb.ArticleVO;
   import org.apache.ojb.ejb.BeanConstants;
   import org.apache.ojb.ejb.PersonVO;
  -import org.apache.ojb.odmg.OJBJ2EE_2;
  +import org.apache.ojb.odmg.OJB;
   import org.apache.ojb.odmg.TransactionExt;
   import org.odmg.DList;
   import org.odmg.Database;
  @@ -118,7 +118,7 @@
       public void ejbCreate()
       {
           log.info("ejbCreate was called");
  -        odmg = OJBJ2EE_2.getInstance();
  +        odmg = OJB.getInstance();
           db = odmg.newDatabase();
           try
           {
  
  
  
  1.5       +3 -3      db-ojb/src/ejb/org/apache/ojb/ejb/odmg/ODMGBaseBeanImpl.java
  
  Index: ODMGBaseBeanImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/odmg/ODMGBaseBeanImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ODMGBaseBeanImpl.java	5 Apr 2004 00:17:08 -0000	1.4
  +++ ODMGBaseBeanImpl.java	3 May 2004 23:06:56 -0000	1.5
  @@ -26,7 +26,7 @@
   import org.apache.ojb.ejb.BeanConstants;
   import org.apache.ojb.ejb.SessionBeanImpl;
   import org.apache.ojb.odmg.HasBroker;
  -import org.apache.ojb.odmg.OJBJ2EE_2;
  +import org.apache.ojb.odmg.OJB;
   import org.apache.ojb.odmg.TransactionExt;
   import org.odmg.Database;
   import org.odmg.Implementation;
  @@ -180,7 +180,7 @@
        */
       private void ojbPrepare()
       {
  -        odmg = OJBJ2EE_2.getInstance();
  +        odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
           try
           {
  
  
  
  1.7       +6 -6      db-ojb/src/connector/main/org/apache/ojb/jboss/ODMGFactory.java
  
  Index: ODMGFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/connector/main/org/apache/ojb/jboss/ODMGFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ODMGFactory.java	5 Apr 2004 00:41:38 -0000	1.6
  +++ ODMGFactory.java	3 May 2004 23:06:56 -0000	1.7
  @@ -15,11 +15,6 @@
    * limitations under the License.
    */
   
  -import org.apache.ojb.odmg.ODMGJ2EEFactory;
  -import org.apache.ojb.odmg.OJBJ2EE_2;
  -import org.jboss.system.ServiceMBeanSupport;
  -import org.odmg.Implementation;
  -
   import javax.naming.Context;
   import javax.naming.InitialContext;
   import javax.naming.Name;
  @@ -27,6 +22,11 @@
   import javax.naming.NamingException;
   import java.io.Serializable;
   
  +import org.apache.ojb.odmg.ODMGJ2EEFactory;
  +import org.apache.ojb.odmg.OJB;
  +import org.jboss.system.ServiceMBeanSupport;
  +import org.odmg.Implementation;
  +
   public class ODMGFactory extends ServiceMBeanSupport
           implements ODMGJ2EEFactory, Serializable, ODMGFactoryMBean
   {
  @@ -72,7 +72,7 @@
   
       public Implementation getInstance()
       {
  -        return OJBJ2EE_2.getInstance();
  +        return OJB.getInstance();
       }
   
       public void setJndiName(String jndiName)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message