01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
18: package org.apache.commons.dbcp.datasources;
19:
20: import java.io.IOException;
21: import java.util.Map;
22:
23: import javax.naming.RefAddr;
24: import javax.naming.Reference;
25:
26: /**
27: * A JNDI ObjectFactory which creates <code>SharedPoolDataSource</code>s
28: *
29: * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
30: */
31: public class PerUserPoolDataSourceFactory extends
32: InstanceKeyObjectFactory {
33: private static final String PER_USER_POOL_CLASSNAME = PerUserPoolDataSource.class
34: .getName();
35:
36: protected boolean isCorrectClass(String className) {
37: return PER_USER_POOL_CLASSNAME.equals(className);
38: }
39:
40: protected InstanceKeyDataSource getNewInstance(Reference ref)
41: throws IOException, ClassNotFoundException {
42: PerUserPoolDataSource pupds = new PerUserPoolDataSource();
43: RefAddr ra = ref.get("defaultMaxActive");
44: if (ra != null && ra.getContent() != null) {
45: pupds.setDefaultMaxActive(Integer.parseInt(ra.getContent()
46: .toString()));
47: }
48:
49: ra = ref.get("defaultMaxIdle");
50: if (ra != null && ra.getContent() != null) {
51: pupds.setDefaultMaxIdle(Integer.parseInt(ra.getContent()
52: .toString()));
53: }
54:
55: ra = ref.get("defaultMaxWait");
56: if (ra != null && ra.getContent() != null) {
57: pupds.setDefaultMaxWait(Integer.parseInt(ra.getContent()
58: .toString()));
59: }
60:
61: ra = ref.get("perUserDefaultAutoCommit");
62: if (ra != null && ra.getContent() != null) {
63: byte[] serialized = (byte[]) ra.getContent();
64: pupds.perUserDefaultAutoCommit = (Map) deserialize(serialized);
65: }
66:
67: ra = ref.get("perUserDefaultTransactionIsolation");
68: if (ra != null && ra.getContent() != null) {
69: byte[] serialized = (byte[]) ra.getContent();
70: pupds.perUserDefaultTransactionIsolation = (Map) deserialize(serialized);
71: }
72:
73: ra = ref.get("perUserMaxActive");
74: if (ra != null && ra.getContent() != null) {
75: byte[] serialized = (byte[]) ra.getContent();
76: pupds.perUserMaxActive = (Map) deserialize(serialized);
77: }
78:
79: ra = ref.get("perUserMaxIdle");
80: if (ra != null && ra.getContent() != null) {
81: byte[] serialized = (byte[]) ra.getContent();
82: pupds.perUserMaxIdle = (Map) deserialize(serialized);
83: }
84:
85: ra = ref.get("perUserMaxWait");
86: if (ra != null && ra.getContent() != null) {
87: byte[] serialized = (byte[]) ra.getContent();
88: pupds.perUserMaxWait = (Map) deserialize(serialized);
89: }
90:
91: ra = ref.get("perUserDefaultReadOnly");
92: if (ra != null && ra.getContent() != null) {
93: byte[] serialized = (byte[]) ra.getContent();
94: pupds.perUserDefaultReadOnly = (Map) deserialize(serialized);
95: }
96: return pupds;
97: }
98: }
|