play.db.DB Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of framework Show documentation
Show all versions of framework Show documentation
RePlay is a fork of the Play1 framework, created by Codeborne.
package play.db;
import static java.util.stream.Collectors.toMap;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.sql.DataSource;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import play.db.jpa.JPA;
import play.exceptions.DatabaseException;
/** Database connection utilities. */
public class DB {
private static final Logger logger = LoggerFactory.getLogger(DB.class);
/**
* The loaded datasource.
*
* @see ExtendedDatasource
*/
protected static final Map dataSources = new ConcurrentHashMap<>();
public static class ExtendedDatasource {
/** Connection to the physical data source */
private final DataSource internalDataSource;
/** The method used to destroy the data source */
private final String internalDestroyMethod;
public ExtendedDatasource(DataSource ds, String destroyMethod) {
this.internalDataSource = ds;
this.internalDestroyMethod = destroyMethod;
}
public String getDestroyMethod() {
return internalDestroyMethod;
}
public DataSource getDataSource() {
return internalDataSource;
}
}
/**
* @see #dataSources
* @see ExtendedDatasource
* @since 1.3.0
* @deprecated Use dataSources instead
*/
@Deprecated public static DataSource dataSource = null;
/**
* The method used to destroy the datasource
*
* @see #dataSources
* @see ExtendedDatasource
* @since 1.3.0
* @deprecated Use dataSources instead
*/
@Deprecated public static String destroyMethod = "";
public static final String DEFAULT = "default";
static final ThreadLocal