org.sca4j.jndi.datasource.JndiDataSourceProxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sca4j-jndi Show documentation
Show all versions of sca4j-jndi Show documentation
SCA4J JNDI Resource Framework.
/**
* SCA4J
* Copyright (c) 2009 - 2099 Service Symphony Ltd
*
* Licensed to you under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. A copy of the license
* is included in this distrubtion or you may obtain a copy at
*
* http://www.opensource.org/licenses/apache2.0.php
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* This project contains code licensed from the Apache Software Foundation under
* the Apache License, Version 2.0 and original code from project contributors.
*/
package org.sca4j.jndi.datasource;
import org.oasisopen.sca.annotation.EagerInit;
import org.oasisopen.sca.annotation.Init;
import org.oasisopen.sca.annotation.Property;
import org.oasisopen.sca.annotation.Reference;
import org.sca4j.jndi.AbstractJndiProxy;
import org.sca4j.jndi.config.JndiEnvPrefix;
import org.sca4j.jndi.config.JndiResourceConfig ;
import org.sca4j.spi.resource.ResourceRegistry;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
/**
* Proxy class for a JNDI-based datasources.
*
* @author deanb
*
*/
@EagerInit
public class JndiDataSourceProxy extends AbstractJndiProxy implements DataSource {
private ResourceRegistry resourceRegistry;
private List dataSourceKeys;
public JndiDataSourceProxy() {
setEnvPrefix(JndiEnvPrefix.COMP_ENV);
}
@Init
public void init(JndiResourceConfig resourceConfig) throws NamingException {
lookup(resourceConfig);
for (String key : dataSourceKeys) {
resourceRegistry.registerResource(DataSource.class, key, this);
}
}
@Reference
public void setResourceRegistry(ResourceRegistry resourceRegistry) {
this.resourceRegistry = resourceRegistry;
}
@Property
public void setDataSourceKeys(List dataSourceKeys) {
this.dataSourceKeys = dataSourceKeys;
}
public Connection getConnection() throws SQLException {
return getDelegate().getConnection();
}
public Connection getConnection(String userName, String password) throws SQLException {
return getDelegate().getConnection(userName, password);
}
public PrintWriter getLogWriter() throws SQLException {
return getDelegate().getLogWriter();
}
public int getLoginTimeout() throws SQLException {
return getDelegate().getLoginTimeout();
}
public void setLogWriter(PrintWriter writer) throws SQLException {
getDelegate().setLogWriter(writer);
}
public void setLoginTimeout(int timeout) throws SQLException {
getDelegate().setLoginTimeout(timeout);
}
public boolean isWrapperFor(Class> iface) throws SQLException {
//return getDelegate().isWrapperFor(iface);
throw new UnsupportedOperationException("isWrapperFor not supported");
}
public T unwrap(Class iface) throws SQLException {
//return unwrap(iface);
throw new UnsupportedOperationException("unwrap not supported");
}
}