001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.resource.jdbc;
018:
019: import java.io.File;
020: import java.sql.SQLException;
021: import java.util.Properties;
022:
023: import javax.sql.DataSource;
024:
025: import org.apache.openejb.loader.SystemInstance;
026:
027: public class BasicManagedDataSource extends
028: org.apache.commons.dbcp.managed.BasicManagedDataSource {
029: public synchronized String getUserName() {
030: return super .getUsername();
031: }
032:
033: public synchronized void setUserName(String string) {
034: super .setUsername(string);
035: }
036:
037: public synchronized String getJdbcDriver() {
038: return super .getDriverClassName();
039: }
040:
041: public synchronized void setJdbcDriver(String string) {
042: super .setDriverClassName(string);
043: }
044:
045: public synchronized String getJdbcUrl() {
046: return super .getUrl();
047: }
048:
049: public synchronized void setJdbcUrl(String string) {
050: super .setUrl(string);
051: }
052:
053: public synchronized void setDefaultTransactionIsolation(String s) {
054: if (s == null || s.equals(""))
055: return;
056: int level = IsolationLevels.getIsolationLevel(s);
057: super .setDefaultTransactionIsolation(level);
058: }
059:
060: protected synchronized DataSource createDataSource()
061: throws SQLException {
062: if (dataSource != null) {
063: return dataSource;
064: }
065:
066: // get the plugin
067: DataSourcePlugin helper = BasicDataSourceUtil
068: .getDataSourcePlugin(getUrl());
069:
070: // configure this
071: if (helper != null) {
072: helper.configure(this );
073: }
074:
075: wrapTransactionManager();
076: // create the data source
077: if (helper == null || !helper.enableUserDirHack()) {
078: return super .createDataSource();
079: } else {
080: // wrap super call with code that sets user.dir to openejb.base and then resets it
081: Properties systemProperties = System.getProperties();
082: synchronized (systemProperties) {
083: String userDir = systemProperties
084: .getProperty("user.dir");
085: try {
086: File base = SystemInstance.get().getBase()
087: .getDirectory();
088: systemProperties.setProperty("user.dir", base
089: .getAbsolutePath());
090: return super .createDataSource();
091: } finally {
092: systemProperties.setProperty("user.dir", userDir);
093: }
094: }
095: }
096: }
097:
098: protected void wrapTransactionManager() {
099: }
100:
101: }
|