Home » openejb-3.1.2-src » org.apache » openejb » resource » [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.resource;
   19   
   20   import org.apache.geronimo.connector.outbound.GenericConnectionManager;
   21   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.LocalTransactions;
   22   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool;
   23   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoTransactions;
   24   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PartitionedPool;
   25   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
   26   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool;
   27   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
   28   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions;
   29   import org.apache.geronimo.transaction.manager.RecoverableTransactionManager;
   30   
   31   import javax.transaction.TransactionManager;
   32   
   33   public class GeronimoConnectionManagerFactory   {
   34       private String name;
   35       private ClassLoader classLoader;
   36   
   37       private TransactionManager transactionManager;
   38   
   39       // Type of transaction used by the ConnectionManager
   40       // local, none, or xa
   41       private String transactionSupport;
   42   
   43       // pooling properties
   44       private boolean pooling = true;
   45       private String partitionStrategy; //: none, by-subject, by-connector-properties
   46       private int poolMaxSize = 10;
   47       private int poolMinSize = 0;
   48       private boolean allConnectionsEqual = true;
   49       private int connectionMaxWaitMilliseconds = 5000;
   50       private int connectionMaxIdleMinutes = 15;
   51   
   52       public String getName() {
   53           return name;
   54       }
   55   
   56       public void setName(String name) {
   57           this.name = name;
   58       }
   59   
   60       public ClassLoader getClassLoader() {
   61           return classLoader;
   62       }
   63   
   64       public void setClassLoader(ClassLoader classLoader) {
   65           this.classLoader = classLoader;
   66       }
   67   
   68       public TransactionManager getTransactionManager() {
   69           return transactionManager;
   70       }
   71   
   72       public void setTransactionManager(TransactionManager transactionManager) {
   73           this.transactionManager = transactionManager;
   74       }
   75   
   76       public String getTransactionSupport() {
   77           return transactionSupport;
   78       }
   79   
   80       public void setTransactionSupport(String transactionSupport) {
   81           this.transactionSupport = transactionSupport;
   82       }
   83   
   84       public boolean isPooling() {
   85           return pooling;
   86       }
   87   
   88       public void setPooling(boolean pooling) {
   89           this.pooling = pooling;
   90       }
   91   
   92       public String getPartitionStrategy() {
   93           return partitionStrategy;
   94       }
   95   
   96       public void setPartitionStrategy(String partitionStrategy) {
   97           this.partitionStrategy = partitionStrategy;
   98       }
   99   
  100       public int getPoolMaxSize() {
  101           return poolMaxSize;
  102       }
  103   
  104       public void setPoolMaxSize(int poolMaxSize) {
  105           this.poolMaxSize = poolMaxSize;
  106       }
  107   
  108       public int getPoolMinSize() {
  109           return poolMinSize;
  110       }
  111   
  112       public void setPoolMinSize(int poolMinSize) {
  113           this.poolMinSize = poolMinSize;
  114       }
  115   
  116       public boolean isAllConnectionsEqual() {
  117           return allConnectionsEqual;
  118       }
  119   
  120       public void setAllConnectionsEqual(boolean allConnectionsEqual) {
  121           this.allConnectionsEqual = allConnectionsEqual;
  122       }
  123   
  124       public int getConnectionMaxWaitMilliseconds() {
  125           return connectionMaxWaitMilliseconds;
  126       }
  127   
  128       public void setConnectionMaxWaitMilliseconds(int connectionMaxWaitMilliseconds) {
  129           this.connectionMaxWaitMilliseconds = connectionMaxWaitMilliseconds;
  130       }
  131   
  132       public int getConnectionMaxIdleMinutes() {
  133           return connectionMaxIdleMinutes;
  134       }
  135   
  136       public void setConnectionMaxIdleMinutes(int connectionMaxIdleMinutes) {
  137           this.connectionMaxIdleMinutes = connectionMaxIdleMinutes;
  138       }
  139   
  140       public GenericConnectionManager create() {
  141           PoolingSupport poolingSupport = createPoolingSupport();
  142   
  143           ClassLoader classLoader = this.classLoader;
  144           if (classLoader == null) Thread.currentThread().getContextClassLoader();
  145           if (classLoader == null) classLoader = getClass().getClassLoader();
  146           if (classLoader == null) classLoader = ClassLoader.getSystemClassLoader();
  147           GenericConnectionManager connectionManager = new GenericConnectionManager(
  148                   createTransactionSupport(),
  149                   poolingSupport,
  150                   null,
  151                   new AutoConnectionTracker(),
  152                   (RecoverableTransactionManager)transactionManager,
  153                   name,
  154                   classLoader);
  155           return connectionManager;
  156       }
  157   
  158       private TransactionSupport createTransactionSupport() {
  159           if (transactionSupport == null || "local".equalsIgnoreCase(transactionSupport)) {
  160               return LocalTransactions.INSTANCE;
  161           } else if ("none".equalsIgnoreCase(transactionSupport)) {
  162               return NoTransactions.INSTANCE;
  163           } else if ("xa".equalsIgnoreCase(transactionSupport)) {
  164               return new XATransactions(true, false);
  165           } else {
  166               throw new IllegalArgumentException("Unknown transaction type " + transactionSupport);
  167           }
  168       }
  169   
  170   
  171       private PoolingSupport createPoolingSupport() {
  172           // pooling off?
  173           if (!pooling) {
  174               return new NoPool();
  175           }
  176   
  177           if (partitionStrategy == null || "none".equalsIgnoreCase(partitionStrategy)) {
  178   
  179               // unpartitioned pool
  180               return new SinglePool(poolMaxSize,
  181                       poolMinSize,
  182                       connectionMaxWaitMilliseconds,
  183                       connectionMaxIdleMinutes,
  184                       allConnectionsEqual,
  185                       !allConnectionsEqual,
  186                       false);
  187   
  188           } else if ("by-connector-properties".equalsIgnoreCase(partitionStrategy)) {
  189   
  190               // partition by contector properties such as username and password on a jdbc connection
  191               return new PartitionedPool(poolMaxSize,
  192                       poolMinSize,
  193                       connectionMaxWaitMilliseconds,
  194                       connectionMaxIdleMinutes,
  195                       allConnectionsEqual,
  196                       !allConnectionsEqual,
  197                       false,
  198                       true,
  199                       false);
  200           } else if ("by-subject".equalsIgnoreCase(partitionStrategy)) {
  201   
  202               // partition by caller subject
  203               return new PartitionedPool(poolMaxSize,
  204                       poolMinSize,
  205                       connectionMaxWaitMilliseconds,
  206                       connectionMaxIdleMinutes,
  207                       allConnectionsEqual,
  208                       !allConnectionsEqual,
  209                       false,
  210                       false,
  211                       true);
  212           } else {
  213               throw new IllegalArgumentException("Unknown partition strategy " + partitionStrategy);
  214           }
  215       }
  216   }

Home » openejb-3.1.2-src » org.apache » openejb » resource » [javadoc | source]