View Javadoc

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