com.amazon.redshift.osgi.RedshiftDataSourceFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redshift-jdbc42 Show documentation
Show all versions of redshift-jdbc42 Show documentation
Java JDBC 4.2 (JRE 8+) driver for Redshift database
/*
* Copyright (c) 2003, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package com.amazon.redshift.osgi;
import com.amazon.redshift.ds.common.BaseDataSource;
import com.amazon.redshift.jdbc2.optional.ConnectionPool;
import com.amazon.redshift.jdbc2.optional.PoolingDataSource;
import com.amazon.redshift.jdbc2.optional.SimpleDataSource;
import com.amazon.redshift.util.GT;
import com.amazon.redshift.util.RedshiftException;
import com.amazon.redshift.util.RedshiftState;
import com.amazon.redshift.xa.RedshiftXADataSource;
import org.osgi.service.jdbc.DataSourceFactory;
import java.sql.SQLException;
import java.util.Map.Entry;
import java.util.Properties;
import javax.sql.ConnectionPoolDataSource;
import javax.sql.DataSource;
import javax.sql.XADataSource;
/**
* This factory service is designed to be used in OSGi Enterprise environments to create and
* configure JDBC data-sources.
*/
public class RedshiftDataSourceFactory implements DataSourceFactory {
/**
* A class that removes properties as they are used (without modifying the supplied initial
* Properties).
*/
private static class SingleUseProperties extends Properties {
private static final long serialVersionUID = 1L;
SingleUseProperties(Properties initialProperties) {
super();
if (initialProperties != null) {
putAll(initialProperties);
}
}
@Override
public String getProperty(String key) {
String value = super.getProperty(key);
remove(key);
return value;
}
}
private void configureBaseDataSource(BaseDataSource ds, Properties props) throws SQLException {
if (props.containsKey(JDBC_URL)) {
ds.setUrl(props.getProperty(JDBC_URL));
}
if (props.containsKey(JDBC_SERVER_NAME)) {
ds.setServerName(props.getProperty(JDBC_SERVER_NAME));
}
if (props.containsKey(JDBC_PORT_NUMBER)) {
ds.setPortNumber(Integer.parseInt(props.getProperty(JDBC_PORT_NUMBER)));
}
if (props.containsKey(JDBC_DATABASE_NAME)) {
ds.setDatabaseName(props.getProperty(JDBC_DATABASE_NAME));
}
if (props.containsKey(JDBC_USER)) {
ds.setUser(props.getProperty(JDBC_USER));
}
if (props.containsKey(JDBC_PASSWORD)) {
ds.setPassword(props.getProperty(JDBC_PASSWORD));
}
for (Entry