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. package org.apache.commons.dbcp.datasources;
  17. import java.io.IOException;
  18. import java.util.Map;
  19. import javax.naming.RefAddr;
  20. import javax.naming.Reference;
  21. /**
  22. * A JNDI ObjectFactory which creates <code>SharedPoolDataSource</code>s
  23. *
  24. * @version $Revision: 1.4 $ $Date: 2004/02/28 12:18:17 $
  25. */
  26. public class PerUserPoolDataSourceFactory
  27. extends InstanceKeyObjectFactory
  28. {
  29. private static final String PER_USER_POOL_CLASSNAME =
  30. PerUserPoolDataSource.class.getName();
  31. protected boolean isCorrectClass(String className) {
  32. return PER_USER_POOL_CLASSNAME.equals(className);
  33. }
  34. protected InstanceKeyDataSource getNewInstance(Reference ref)
  35. throws IOException, ClassNotFoundException {
  36. PerUserPoolDataSource pupds = new PerUserPoolDataSource();
  37. RefAddr ra = ref.get("defaultMaxActive");
  38. if (ra != null && ra.getContent() != null) {
  39. pupds.setDefaultMaxActive(
  40. Integer.parseInt(ra.getContent().toString()));
  41. }
  42. ra = ref.get("defaultMaxIdle");
  43. if (ra != null && ra.getContent() != null) {
  44. pupds.setDefaultMaxIdle(
  45. Integer.parseInt(ra.getContent().toString()));
  46. }
  47. ra = ref.get("defaultMaxWait");
  48. if (ra != null && ra.getContent() != null) {
  49. pupds.setDefaultMaxWait(
  50. Integer.parseInt(ra.getContent().toString()));
  51. }
  52. ra = ref.get("perUserDefaultAutoCommit");
  53. if (ra != null && ra.getContent() != null) {
  54. byte[] serialized = (byte[]) ra.getContent();
  55. pupds.perUserDefaultAutoCommit = (Map) deserialize(serialized);
  56. }
  57. ra = ref.get("perUserDefaultTransactionIsolation");
  58. if (ra != null && ra.getContent() != null) {
  59. byte[] serialized = (byte[]) ra.getContent();
  60. pupds.perUserDefaultTransactionIsolation =
  61. (Map) deserialize(serialized);
  62. }
  63. ra = ref.get("perUserMaxActive");
  64. if (ra != null && ra.getContent() != null) {
  65. byte[] serialized = (byte[]) ra.getContent();
  66. pupds.perUserMaxActive = (Map) deserialize(serialized);
  67. }
  68. ra = ref.get("perUserMaxIdle");
  69. if (ra != null && ra.getContent() != null) {
  70. byte[] serialized = (byte[]) ra.getContent();
  71. pupds.perUserMaxIdle = (Map) deserialize(serialized);
  72. }
  73. ra = ref.get("perUserMaxWait");
  74. if (ra != null && ra.getContent() != null) {
  75. byte[] serialized = (byte[]) ra.getContent();
  76. pupds.perUserMaxWait = (Map) deserialize(serialized);
  77. }
  78. ra = ref.get("perUserDefaultReadOnly");
  79. if (ra != null && ra.getContent() != null) {
  80. byte[] serialized = (byte[]) ra.getContent();
  81. pupds.perUserDefaultReadOnly = (Map) deserialize(serialized);
  82. }
  83. return pupds;
  84. }
  85. }