Package org.hivedb.meta.persistence

Source Code of org.hivedb.meta.persistence.HiveBasicDataSourceProvider

/**
*
*/
package org.hivedb.meta.persistence;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hivedb.HiveRuntimeException;
import org.hivedb.meta.Node;
import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy;

import javax.sql.DataSource;
import java.util.Collection;
import java.util.HashSet;

public class HiveBasicDataSourceProvider implements HiveDataSourceProvider {
  private Log log = LogFactory.getLog(HiveBasicDataSource.class);

  private Collection<HiveBasicDataSource> dataSourcesToClose;

  public HiveBasicDataSourceProvider() {
    dataSourcesToClose = new HashSet<HiveBasicDataSource>();
  }

  public DataSource getDataSource(Node node) {
    return getDataSource(node.getUri());
  }

  /**
   * @see HiveDataSourceProvider#close()
   */
  public void close() {
    HiveRuntimeException exceptionWhileClosing = null;
    for (HiveBasicDataSource dataSource : dataSourcesToClose) {
      try {
        dataSource.close();
      } catch (Exception e) {
        exceptionWhileClosing = new HiveRuntimeException("Error closing datasources. Possibly more than one cause.", e);
      }
    }
    if (exceptionWhileClosing != null) {
      throw exceptionWhileClosing;
    }
  }

  public DataSource getDataSource(String uri) {
    HiveBasicDataSource ds = new HiveBasicDataSource(uri);
    LazyConnectionDataSourceProxy dataSourceProxy = new LazyConnectionDataSourceProxy(ds);
    dataSourcesToClose.add(ds);
    return dataSourceProxy;
  }
}
TOP

Related Classes of org.hivedb.meta.persistence.HiveBasicDataSourceProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.