01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.resource.jdbc;
18:
19: import org.apache.openejb.loader.SystemInstance;
20:
21: import javax.sql.DataSource;
22: import java.sql.SQLException;
23: import java.util.Properties;
24: import java.util.Map;
25: import java.util.HashMap;
26: import java.io.File;
27:
28: public class BasicDataSource extends
29: org.apache.commons.dbcp.BasicDataSource {
30:
31: public synchronized String getUserName() {
32: return super .getUsername();
33: }
34:
35: public synchronized void setUserName(String string) {
36: super .setUsername(string);
37: }
38:
39: public synchronized String getJdbcDriver() {
40: return super .getDriverClassName();
41: }
42:
43: public synchronized void setJdbcDriver(String string) {
44: super .setDriverClassName(string);
45: }
46:
47: public synchronized String getJdbcUrl() {
48: return super .getUrl();
49: }
50:
51: public synchronized void setJdbcUrl(String string) {
52: super .setUrl(string);
53: }
54:
55: public synchronized void setDefaultTransactionIsolation(String s) {
56: if (s == null || s.equals(""))
57: return;
58: int level = IsolationLevels.getIsolationLevel(s);
59: super .setDefaultTransactionIsolation(level);
60: }
61:
62: protected synchronized DataSource createDataSource()
63: throws SQLException {
64: if (dataSource != null) {
65: return dataSource;
66: }
67:
68: // get the plugin
69: DataSourcePlugin helper = BasicDataSourceUtil
70: .getDataSourcePlugin(getUrl());
71:
72: // configure this
73: if (helper != null) {
74: helper.configure(this );
75: }
76:
77: // creat the data source
78: if (helper == null || !helper.enableUserDirHack()) {
79: return super .createDataSource();
80: } else {
81: // wrap super call with code that sets user.dir to openejb.base and then resets it
82: Properties systemProperties = System.getProperties();
83: synchronized (systemProperties) {
84: String userDir = systemProperties
85: .getProperty("user.dir");
86: try {
87: File base = SystemInstance.get().getBase()
88: .getDirectory();
89: systemProperties.setProperty("user.dir", base
90: .getAbsolutePath());
91: return super .createDataSource();
92: } finally {
93: systemProperties.setProperty("user.dir", userDir);
94: }
95: }
96: }
97: }
98: }
|