KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > dbcp > datasources > PerUserPoolDataSourceFactory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.dbcp.datasources;
18
19 import java.io.IOException JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import javax.naming.RefAddr JavaDoc;
23 import javax.naming.Reference JavaDoc;
24
25 /**
26  * A JNDI ObjectFactory which creates <code>SharedPoolDataSource</code>s
27  *
28  * @version $Revision: 1.4 $ $Date: 2004/02/28 12:18:17 $
29  */

30 public class PerUserPoolDataSourceFactory
31     extends InstanceKeyObjectFactory
32 {
33     private static final String JavaDoc PER_USER_POOL_CLASSNAME =
34         PerUserPoolDataSource.class.getName();
35
36     protected boolean isCorrectClass(String JavaDoc className) {
37         return PER_USER_POOL_CLASSNAME.equals(className);
38     }
39
40     protected InstanceKeyDataSource getNewInstance(Reference JavaDoc ref)
41         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
42         PerUserPoolDataSource pupds = new PerUserPoolDataSource();
43         RefAddr JavaDoc ra = ref.get("defaultMaxActive");
44         if (ra != null && ra.getContent() != null) {
45             pupds.setDefaultMaxActive(
46                 Integer.parseInt(ra.getContent().toString()));
47         }
48
49         ra = ref.get("defaultMaxIdle");
50         if (ra != null && ra.getContent() != null) {
51             pupds.setDefaultMaxIdle(
52                 Integer.parseInt(ra.getContent().toString()));
53         }
54
55         ra = ref.get("defaultMaxWait");
56         if (ra != null && ra.getContent() != null) {
57             pupds.setDefaultMaxWait(
58                 Integer.parseInt(ra.getContent().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 JavaDoc) 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 =
71                 (Map JavaDoc) deserialize(serialized);
72         }
73
74         ra = ref.get("perUserMaxActive");
75         if (ra != null && ra.getContent() != null) {
76             byte[] serialized = (byte[]) ra.getContent();
77             pupds.perUserMaxActive = (Map JavaDoc) deserialize(serialized);
78         }
79         
80         ra = ref.get("perUserMaxIdle");
81         if (ra != null && ra.getContent() != null) {
82             byte[] serialized = (byte[]) ra.getContent();
83             pupds.perUserMaxIdle = (Map JavaDoc) deserialize(serialized);
84         }
85         
86         ra = ref.get("perUserMaxWait");
87         if (ra != null && ra.getContent() != null) {
88             byte[] serialized = (byte[]) ra.getContent();
89             pupds.perUserMaxWait = (Map JavaDoc) deserialize(serialized);
90         }
91                 
92         ra = ref.get("perUserDefaultReadOnly");
93         if (ra != null && ra.getContent() != null) {
94             byte[] serialized = (byte[]) ra.getContent();
95             pupds.perUserDefaultReadOnly = (Map JavaDoc) deserialize(serialized);
96         }
97         return pupds;
98     }
99 }
100
101
Popular Tags