001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.resource;
018:
019: import org.apache.geronimo.connector.outbound.GenericConnectionManager;
020: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.LocalTransactions;
021: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool;
022: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoTransactions;
023: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PartitionedPool;
024: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
025: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool;
026: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
027: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions;
028: import org.apache.geronimo.transaction.manager.RecoverableTransactionManager;
029:
030: import javax.transaction.TransactionManager;
031:
032: public class GeronimoConnectionManagerFactory {
033: private String name;
034: private ClassLoader classLoader;
035:
036: private TransactionManager transactionManager;
037:
038: // Type of transaction used by the ConnectionManager
039: // local, none, or xa
040: private String transactionSupport;
041:
042: // pooling properties
043: private boolean pooling = true;
044: private String partitionStrategy; //: none, by-subject, by-connector-properties
045: private int poolMaxSize = 10;
046: private int poolMinSize = 0;
047: private boolean allConnectionsEqual = true;
048: private int connectionMaxWaitMilliseconds = 5000;
049: private int connectionMaxIdleMinutes = 15;
050:
051: public String getName() {
052: return name;
053: }
054:
055: public void setName(String name) {
056: this .name = name;
057: }
058:
059: public ClassLoader getClassLoader() {
060: return classLoader;
061: }
062:
063: public void setClassLoader(ClassLoader classLoader) {
064: this .classLoader = classLoader;
065: }
066:
067: public TransactionManager getTransactionManager() {
068: return transactionManager;
069: }
070:
071: public void setTransactionManager(
072: TransactionManager transactionManager) {
073: this .transactionManager = transactionManager;
074: }
075:
076: public String getTransactionSupport() {
077: return transactionSupport;
078: }
079:
080: public void setTransactionSupport(String transactionSupport) {
081: this .transactionSupport = transactionSupport;
082: }
083:
084: public boolean isPooling() {
085: return pooling;
086: }
087:
088: public void setPooling(boolean pooling) {
089: this .pooling = pooling;
090: }
091:
092: public String getPartitionStrategy() {
093: return partitionStrategy;
094: }
095:
096: public void setPartitionStrategy(String partitionStrategy) {
097: this .partitionStrategy = partitionStrategy;
098: }
099:
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(
129: int connectionMaxWaitMilliseconds) {
130: this .connectionMaxWaitMilliseconds = connectionMaxWaitMilliseconds;
131: }
132:
133: public int getConnectionMaxIdleMinutes() {
134: return connectionMaxIdleMinutes;
135: }
136:
137: public void setConnectionMaxIdleMinutes(int connectionMaxIdleMinutes) {
138: this .connectionMaxIdleMinutes = connectionMaxIdleMinutes;
139: }
140:
141: public GenericConnectionManager create() {
142: PoolingSupport poolingSupport = createPoolingSupport();
143:
144: ClassLoader classLoader = this .classLoader;
145: if (classLoader == null)
146: Thread.currentThread().getContextClassLoader();
147: if (classLoader == null)
148: classLoader = getClass().getClassLoader();
149: if (classLoader == null)
150: classLoader = ClassLoader.getSystemClassLoader();
151: GenericConnectionManager connectionManager = new GenericConnectionManager(
152: createTransactionSupport(), poolingSupport, null,
153: new AutoConnectionTracker(),
154: (RecoverableTransactionManager) transactionManager,
155: name, classLoader);
156: return connectionManager;
157: }
158:
159: private TransactionSupport createTransactionSupport() {
160: if (transactionSupport == null
161: || "local".equalsIgnoreCase(transactionSupport)) {
162: return LocalTransactions.INSTANCE;
163: } else if ("none".equalsIgnoreCase(transactionSupport)) {
164: return NoTransactions.INSTANCE;
165: } else if ("xa".equalsIgnoreCase(transactionSupport)) {
166: return new XATransactions(true, false);
167: } else {
168: throw new IllegalArgumentException(
169: "Unknown transaction type " + transactionSupport);
170: }
171: }
172:
173: private PoolingSupport createPoolingSupport() {
174: // pooling off?
175: if (!pooling) {
176: return new NoPool();
177: }
178:
179: if (partitionStrategy == null
180: || "none".equalsIgnoreCase(partitionStrategy)) {
181:
182: // unpartitioned pool
183: return new SinglePool(poolMaxSize, poolMinSize,
184: connectionMaxWaitMilliseconds,
185: connectionMaxIdleMinutes, allConnectionsEqual,
186: !allConnectionsEqual, false);
187:
188: } else if ("by-connector-properties"
189: .equalsIgnoreCase(partitionStrategy)) {
190:
191: // partition by contector properties such as username and password on a jdbc connection
192: return new PartitionedPool(poolMaxSize, poolMinSize,
193: connectionMaxWaitMilliseconds,
194: connectionMaxIdleMinutes, allConnectionsEqual,
195: !allConnectionsEqual, false, true, false);
196: } else if ("by-subject".equalsIgnoreCase(partitionStrategy)) {
197:
198: // partition by caller subject
199: return new PartitionedPool(poolMaxSize, poolMinSize,
200: connectionMaxWaitMilliseconds,
201: connectionMaxIdleMinutes, allConnectionsEqual,
202: !allConnectionsEqual, false, false, true);
203: } else {
204: throw new IllegalArgumentException(
205: "Unknown partition strategy " + partitionStrategy);
206: }
207: }
208: }
|