Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » core » stateful » [javadoc | source]
    1   /**
    2    *
    3    * Licensed to the Apache Software Foundation (ASF) under one or more
    4    * contributor license agreements.  See the NOTICE file distributed with
    5    * this work for additional information regarding copyright ownership.
    6    * The ASF licenses this file to You under the Apache License, Version 2.0
    7    * (the "License"); you may not use this file except in compliance with
    8    * the License.  You may obtain a copy of the License at
    9    *
   10    *     http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing, software
   13    *  distributed under the License is distributed on an "AS IS" BASIS,
   14    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    *  See the License for the specific language governing permissions and
   16    *  limitations under the License.
   17    */
   18   package org.apache.openejb.core.stateful;
   19   
   20   import javax.transaction.UserTransaction;
   21   import javax.transaction.NotSupportedException;
   22   import javax.transaction.SystemException;
   23   import javax.transaction.HeuristicMixedException;
   24   import javax.transaction.HeuristicRollbackException;
   25   import javax.transaction.RollbackException;
   26   
   27   import org.apache.openejb.persistence.JtaEntityManagerRegistry;
   28   import org.apache.openejb.core.ThreadContext;
   29   import org.apache.openejb.core.CoreDeploymentInfo;
   30   import org.apache.openejb.BeanType;
   31   
   32   public class StatefulUserTransaction implements UserTransaction {
   33       private final UserTransaction userTransaction;
   34       private final JtaEntityManagerRegistry jtaEntityManagerRegistry;
   35   
   36       public StatefulUserTransaction(UserTransaction userTransaction, JtaEntityManagerRegistry jtaEntityManagerRegistry) {
   37           this.userTransaction = userTransaction;
   38           this.jtaEntityManagerRegistry = jtaEntityManagerRegistry;
   39       }
   40   
   41       public void begin() throws NotSupportedException, SystemException {
   42           userTransaction.begin();
   43   
   44           // get the callContext
   45           ThreadContext callContext = ThreadContext.getThreadContext();
   46           if (callContext == null) {
   47               // someone is using the user transaction out side of the component
   48               return;
   49           }
   50   
   51           // get the deployment info
   52           CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
   53           if (deploymentInfo.getComponentType() != BeanType.STATEFUL) {
   54               // some other non-stateful ejb is using our user transaction
   55               return;
   56           }
   57   
   58           // get the primary key
   59           Object primaryKey = callContext.getPrimaryKey();
   60           if (primaryKey == null) {
   61               // is is not a bean method
   62               return;
   63           }
   64           jtaEntityManagerRegistry.transactionStarted((String)deploymentInfo.getDeploymentID(), primaryKey);
   65       }
   66   
   67       public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
   68           userTransaction.commit();
   69       }
   70   
   71       public int getStatus() throws SystemException {
   72           return userTransaction.getStatus();
   73       }
   74   
   75       public void rollback() throws IllegalStateException, SecurityException, SystemException {
   76           userTransaction.rollback();
   77       }
   78   
   79       public void setRollbackOnly() throws IllegalStateException, SystemException {
   80           userTransaction.setRollbackOnly();
   81       }
   82   
   83       public void setTransactionTimeout(int i) throws SystemException {
   84           userTransaction.setTransactionTimeout(i);
   85       }
   86   }

Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » core » stateful » [javadoc | source]