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/test/org/apache/ojb repository_database.xml
Date Wed, 27 Apr 2005 00:23:53 GMT
arminw      2005/04/26 17:23:53

  Modified:    src/java/org/apache/ojb/broker/accesslayer Tag:
                        OJB_1_0_RELEASE ConnectionManagerImpl.java
               src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
                        PersistenceBrokerFactorySyncImpl.java
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/platforms Tag:
                        OJB_1_0_RELEASE PlatformDefaultImpl.java
               src/test/org/apache/ojb Tag: OJB_1_0_RELEASE
                        repository_database.xml
  Log:
  make handling of OJB in managed environments more flexible, introduce methods is/setManaged
in PBImpl. Now the ConnectionManager can decide (using the new 'managed' flag) when it's allowed
to change the autoCommit state and to commit/rollback a connection (in managed environment
it's not allowed to do this). A specific ConnectionFactory implementation (ConnectionFactoryManagedImpl)
is no longer needed
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.17.2.3  +53 -17    db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionManagerImpl.java
  
  Index: ConnectionManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionManagerImpl.java,v
  retrieving revision 1.17.2.2
  retrieving revision 1.17.2.3
  diff -u -r1.17.2.2 -r1.17.2.3
  --- ConnectionManagerImpl.java	27 Jan 2005 00:11:17 -0000	1.17.2.2
  +++ ConnectionManagerImpl.java	27 Apr 2005 00:23:52 -0000	1.17.2.3
  @@ -25,6 +25,7 @@
   import org.apache.ojb.broker.TransactionAbortedException;
   import org.apache.ojb.broker.TransactionInProgressException;
   import org.apache.ojb.broker.TransactionNotInProgressException;
  +import org.apache.ojb.broker.core.PersistenceBrokerImpl;
   import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
   import org.apache.ojb.broker.metadata.MetadataManager;
   import org.apache.ojb.broker.platforms.Platform;
  @@ -44,7 +45,7 @@
   {
       private Logger log = LoggerFactory.getLogger(ConnectionManagerImpl.class);
   
  -    private PersistenceBroker broker = null;
  +    private PersistenceBrokerImpl broker = null;
       private ConnectionFactory connectionFactory;
       private JdbcConnectionDescriptor jcd;
       private Platform platform;
  @@ -57,7 +58,8 @@
   
       public ConnectionManagerImpl(PersistenceBroker broker)
       {
  -        this.broker = broker;
  +        // TODO: avoid this cast
  +        this.broker = (PersistenceBrokerImpl) broker;
           this.pbKey = broker.getPBKey();
           this.jcd = MetadataManager.getInstance().connectionRepository().getDescriptor(pbKey);
           this.connectionFactory = ConnectionFactoryFactory.getInstance().createConnectionFactory();
  @@ -168,10 +170,20 @@
               throw new PersistenceBrokerException("Can't lookup a connection", e);
           }
           if (log.isDebugEnabled()) log.debug("localBegin was called for con " + connection);
  -        if (jcd.getUseAutoCommit() == JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE)
  +        // change autoCommit state only if we are not in a managed environment
  +        // and it is enabled by user
  +        if(!broker.isManaged())
           {
  -            if (log.isDebugEnabled()) log.debug("Try to change autoCommit state to 'false'");
  -            platform.changeAutoCommitState(jcd, connection, false);
  +            if (jcd.getUseAutoCommit() == JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE)
  +            {
  +                if (log.isDebugEnabled()) log.debug("Try to change autoCommit state to
'false'");
  +                platform.changeAutoCommitState(jcd, connection, false);
  +            }
  +        }
  +        else
  +        {
  +            if(log.isDebugEnabled()) log.debug(
  +                        "Found managed environment setting in PB, will skip Platform.changeAutoCommitState(...)
call");
           }
           this.isInLocalTransaction = true;
       }
  @@ -188,13 +200,21 @@
           }
           try
           {
  -            if (batchCon != null)
  +            if(!broker.isManaged())
               {
  -                batchCon.commit();
  +                if (batchCon != null)
  +                {
  +                    batchCon.commit();
  +                }
  +                else if (con != null)
  +                {
  +                    con.commit();
  +                }
               }
  -            else if (con != null)
  +            else
               {
  -                con.commit();
  +                if(log.isDebugEnabled()) log.debug(
  +                        "Found managed environment setting in PB, will skip Connection.commit()
call");
               }
           }
           catch (SQLException e)
  @@ -225,13 +245,21 @@
           {
               //truncate the local transaction
               this.isInLocalTransaction = false;
  -            if (batchCon != null)
  +            if(!broker.isManaged())
               {
  -                batchCon.rollback();
  +                if (batchCon != null)
  +                {
  +                    batchCon.rollback();
  +                }
  +                else if (con != null && !con.isClosed())
  +                {
  +                    con.rollback();
  +                }
               }
  -            else if (con != null && !con.isClosed())
  +            else
               {
  -                con.rollback();
  +                if(log.isEnabledFor(Logger.INFO)) log.info(
  +                        "Found managed environment setting in PB, will ignore rollback
call on connection, this should be done by JTA");
               }
           }
           catch (SQLException e)
  @@ -259,10 +287,18 @@
       {
           try
           {
  -            if (jcd.getUseAutoCommit() == JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE
  -                    && originalAutoCommitState == true && con != null &&
!con.isClosed())
  +            if(!broker.isManaged())
  +            {
  +                if (jcd.getUseAutoCommit() == JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE
  +                        && originalAutoCommitState == true && con != null
&& !con.isClosed())
  +                {
  +                    platform.changeAutoCommitState(jcd, con, true);
  +                }
  +            }
  +            else
               {
  -                platform.changeAutoCommitState(jcd, con, true);
  +                if(log.isDebugEnabled()) log.debug(
  +                        "Found managed environment setting in PB, will skip Platform.changeAutoCommitState(...)
call");
               }
           }
           catch (SQLException e)
  
  
  
  No                   revision
  No                   revision
  1.7.2.4   +7 -1      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.7.2.3
  retrieving revision 1.7.2.4
  diff -u -r1.7.2.3 -r1.7.2.4
  --- PersistenceBrokerFactorySyncImpl.java	3 Apr 2005 02:11:29 -0000	1.7.2.3
  +++ PersistenceBrokerFactorySyncImpl.java	27 Apr 2005 00:23:52 -0000	1.7.2.4
  @@ -110,6 +110,7 @@
           PersistenceBrokerSyncHandle result;
           if (tx != null)
           {
  +            // try to find a broker instance already used by current tx
               obtainedBroker = txRegistry.findBroker(tx, pbKey);
           }
   
  @@ -314,6 +315,11 @@
   
           private void internBegin()
           {
  +            /*
  +            TODO: Find more elegant way to do this. In 1.x we can declare 'is/setManaged'
in PBI
  +            */
  +            PersistenceBrokerImpl pb = (PersistenceBrokerImpl) getInnermostDelegate();
  +            pb.setManaged(true);
               super.beginTransaction();
           }
   
  
  
  
  1.83.2.19 +27 -1     db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.83.2.18
  retrieving revision 1.83.2.19
  diff -u -r1.83.2.18 -r1.83.2.19
  --- PersistenceBrokerImpl.java	26 Apr 2005 03:41:36 -0000	1.83.2.18
  +++ PersistenceBrokerImpl.java	27 Apr 2005 00:23:52 -0000	1.83.2.19
  @@ -105,6 +105,11 @@
        * Reflects the transaction status of this instance.
        */
       private boolean inTransaction;
  +    /**
  +     * Flag indicate that this PB instance is handled
  +     * in a managed environment.
  +     */
  +    private boolean managed;
       private MaterializationCache objectCache;
       /**
        * m_DbAccess is used to do all Jdbc related work: connecting, executing...
  @@ -265,6 +270,25 @@
       }
   
       /**
  +     * If <em>true</em> this instance is handled by a managed
  +     * environment - registered within a JTA transaction.
  +     */
  +    public boolean isManaged()
  +    {
  +        return managed;
  +    }
  +
  +    /**
  +     * Set <em>true</em> if this instance is registered within a
  +     * JTA transaction. On {@link #close()} call this flag was reset
  +     * to <em>false</em> automatic.
  +     */
  +    public void setManaged(boolean managed)
  +    {
  +        this.managed = managed;
  +    }
  +
  +    /**
        * Lookup the current {@link DescriptorRepository} for
        * this class. This method is responsible to keep this
        * PB instance in sync with {@link MetadataManager}.
  @@ -356,6 +380,8 @@
           }
           finally
           {
  +            // reset flag indicating use in managed environment
  +            setManaged(false);
               // free current used DescriptorRepository reference
               descriptorRepository = null;
               removeAllListeners();
  
  
  
  No                   revision
  No                   revision
  1.27.2.3  +42 -31    db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
  
  Index: PlatformDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java,v
  retrieving revision 1.27.2.2
  retrieving revision 1.27.2.3
  diff -u -r1.27.2.2 -r1.27.2.3
  --- PlatformDefaultImpl.java	6 Apr 2005 13:29:33 -0000	1.27.2.2
  +++ PlatformDefaultImpl.java	27 Apr 2005 00:23:52 -0000	1.27.2.3
  @@ -44,6 +44,8 @@
   public class PlatformDefaultImpl implements Platform, JoinSyntaxTypes
   {
       protected Logger log = LoggerFactory.getLogger(PlatformDefaultImpl.class);
  +    private static final String INITIALIZATION_CHECK_AUTOCOMMIT = "initializationCheck";
  +    private static final String FALSE_STR = "false";
   
       protected boolean m_batchUpdatesChecked = false;
       protected boolean m_supportsBatchUpdates = false;
  @@ -143,45 +145,54 @@
       public void initializeJdbcConnection(JdbcConnectionDescriptor jcd, Connection conn)
throws PlatformException
       {
           if (jcd.getBatchMode()) checkForBatchSupport(conn);
  -        switch (jcd.getUseAutoCommit())
  +        /*
  +        arminw:
  +        workaround to be backward compatible. In future releases we shouldn't change the
autocommit
  +        state of a connection at initializing by the ConnectionFactory. The autocommit
state should only be
  +        changed by the ConnectionManager. We have to separate this stuff.
  +        */
  +        if(!jcd.getAttribute(INITIALIZATION_CHECK_AUTOCOMMIT, FALSE_STR).equalsIgnoreCase(FALSE_STR))
           {
  -            case JdbcConnectionDescriptor.AUTO_COMMIT_IGNORE_STATE:
  -                // nothing to do
  -                break;
  -            case JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE:
  -                try
  -                {
  -                    if (!conn.getAutoCommit()) conn.setAutoCommit(true);
  -                }
  -                catch (SQLException e)
  -                {
  -                    if (!jcd.isIgnoreAutoCommitExceptions())
  +            switch (jcd.getUseAutoCommit())
  +            {
  +                case JdbcConnectionDescriptor.AUTO_COMMIT_IGNORE_STATE:
  +                    // nothing to do
  +                    break;
  +                case JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE:
  +                    try
                       {
  -                        throw new PlatformException("Connection initializing: setAutoCommit(true)
failed", e);
  +                        if (!conn.getAutoCommit()) conn.setAutoCommit(true);
                       }
  -                    else
  +                    catch (SQLException e)
                       {
  -                        log.info("Connection initializing: setAutoCommit jdbc-driver problems.
" + e.getMessage());
  +                        if (!jcd.isIgnoreAutoCommitExceptions())
  +                        {
  +                            throw new PlatformException("Connection initializing: setAutoCommit(true)
failed", e);
  +                        }
  +                        else
  +                        {
  +                            log.info("Connection initializing: setAutoCommit jdbc-driver
problems. " + e.getMessage());
  +                        }
                       }
  -                }
  -                break;
  -            case JdbcConnectionDescriptor.AUTO_COMMIT_SET_FALSE:
  -                try
  -                {
  -                    if (conn.getAutoCommit()) conn.setAutoCommit(false);
  -                }
  -                catch (SQLException e)
  -                {
  -                    if (!jcd.isIgnoreAutoCommitExceptions())
  +                    break;
  +                case JdbcConnectionDescriptor.AUTO_COMMIT_SET_FALSE:
  +                    try
                       {
  -                        throw new PlatformException("Connection initializing: setAutoCommit(false)
failed", e);
  +                        if (conn.getAutoCommit()) conn.setAutoCommit(false);
                       }
  -                    else
  +                    catch (SQLException e)
                       {
  -                        log.info("Connection initializing: setAutoCommit jdbc-driver problems.
" + e.getMessage());
  +                        if (!jcd.isIgnoreAutoCommitExceptions())
  +                        {
  +                            throw new PlatformException("Connection initializing: setAutoCommit(false)
failed", e);
  +                        }
  +                        else
  +                        {
  +                            log.info("Connection initializing: setAutoCommit jdbc-driver
problems. " + e.getMessage());
  +                        }
                       }
  -                }
  -                break;
  +                    break;
  +            }
           }
       }
   
  
  
  
  No                   revision
  No                   revision
  1.22.2.9  +12 -1     db-ojb/src/test/org/apache/ojb/repository_database.xml
  
  Index: repository_database.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_database.xml,v
  retrieving revision 1.22.2.8
  retrieving revision 1.22.2.9
  diff -u -r1.22.2.8 -r1.22.2.9
  --- repository_database.xml	26 Apr 2005 03:41:37 -0000	1.22.2.8
  +++ repository_database.xml	27 Apr 2005 00:23:52 -0000	1.22.2.9
  @@ -48,6 +48,17 @@
           ignoreAutoCommitExceptions="false"
        >
   
  +        <!-- On initialization of connections the ConnectionFactory change the autoCommit
  +             state dependent of the used 'useAutoCommit' setting. This doesn't work in
all
  +             situations/environments, thus this check is deprecated.
  +             To use the old behavior set this property to 'true', then OJB try to
  +             change the autocommit state (if needed) of a new obtained connections at
  +             connection initialization.
  +             If 'false' or this property is removed, OJB don't try to change connection
  +             autoCommit state at connection initialization.
  +        -->
  +        <attribute attribute-name="initializationCheck" attribute-value="false" />
  +
           <!-- alternative cache implementations, see docs section "Caching" -->
           <object-cache class="org.apache.ojb.broker.cache.ObjectCacheTwoLevelImpl">
               <!-- meaning of attributes, please see docs section "Caching" -->
  
  
  

---------------------------------------------------------------------
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