Home » geronimo-2.2-source-release » org.apache.geronimo.corba.transaction.nodistributedtransactions » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.geronimo.corba.transaction.nodistributedtransactions;
   18   
   19   import javax.transaction.TransactionManager;
   20   
   21   import org.omg.CORBA.Any;
   22   import org.omg.CORBA.INTERNAL;
   23   import org.omg.CosTransactions.PropagationContext;
   24   import org.omg.CosTransactions.PropagationContextHelper;
   25   import org.omg.CosTransactions.TransIdentity;
   26   import org.omg.CosTransactions.otid_t;
   27   import org.omg.IOP.Codec;
   28   import org.omg.IOP.CodecPackage.InvalidTypeForEncoding;
   29   import org.omg.IOP.ServiceContext;
   30   import org.omg.IOP.TransactionService;
   31   import org.omg.PortableInterceptor.ClientRequestInfo;
   32   import org.apache.geronimo.corba.transaction.ClientTransactionPolicyConfig;
   33   import org.apache.geronimo.corba.util.Util;
   34   import org.apache.openejb.util.TransactionUtils;
   35   
   36   /**
   37    * @version $Rev: 451417 $ $Date: 2006-09-29 13:13:22 -0700 (Fri, 29 Sep 2006) $
   38    */
   39   public class NoDTxClientTransactionPolicyConfig implements ClientTransactionPolicyConfig {
   40   
   41       private static final TransIdentity[] NO_PARENTS = new TransIdentity[0];
   42       private static final otid_t NULL_XID = new otid_t(0, 0, new byte[0]);
   43   
   44       private final TransactionManager transactionManager;
   45   
   46       public NoDTxClientTransactionPolicyConfig(TransactionManager transactionManager) {
   47           if (transactionManager == null) {
   48               throw new IllegalArgumentException("transactionManager must not be null");
   49           }
   50           this.transactionManager = transactionManager;
   51       }
   52   
   53       public void exportTransaction(ClientRequestInfo ri) {
   54           if (TransactionUtils.isTransactionActive(transactionManager)) {
   55               //19.6.2.1 (1) propagate an "empty" transaction context.
   56               //but, it needs an xid!
   57               TransIdentity transIdentity = new TransIdentity(null, null, NULL_XID);
   58               int timeout = 0;
   59               Any implementationSpecificData = Util.getORB().create_any();
   60               PropagationContext propagationContext = new PropagationContext(timeout, transIdentity, NO_PARENTS, implementationSpecificData);
   61               Codec codec = Util.getCodec();
   62               Any any = Util.getORB().create_any();
   63               PropagationContextHelper.insert(any, propagationContext);
   64               byte[] encodedPropagationContext;
   65               try {
   66                   encodedPropagationContext = codec.encode_value(any);
   67               } catch (InvalidTypeForEncoding invalidTypeForEncoding) {
   68                   throw (INTERNAL)new INTERNAL("Could not encode propagationContext").initCause(invalidTypeForEncoding);
   69               }
   70               ServiceContext otsServiceContext = new ServiceContext(TransactionService.value, encodedPropagationContext);
   71               ri.add_request_service_context(otsServiceContext, true);
   72           }
   73   
   74       }
   75   }

Home » geronimo-2.2-source-release » org.apache.geronimo.corba.transaction.nodistributedtransactions » [javadoc | source]