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 org.hibernate.internal.SessionImpl;
import org.hibernate.jpa.HibernateEntityManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import play.db.jpa.JPA;
import play.exceptions.DatabaseException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.sql.DataSource;
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 static java.util.stream.Collectors.toMap;
/**
* 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 datasource;
/**
* The method used to destroy the data source
*/
private final String destroyMethod;
public ExtendedDatasource(DataSource ds, String destroyMethod) {
this.datasource = ds;
this.destroyMethod = destroyMethod;
}
public String getDestroyMethod() {
return destroyMethod;
}
public DataSource getDataSource() {
return datasource;
}
}
/**
* @deprecated Use datasources instead
* @since 1.3.0
* @see #datasources
* @see ExtendedDatasource
*/
@Deprecated
public static DataSource datasource = null;
/**
* The method used to destroy the datasource
*
* @deprecated Use datasources instead
* @since 1.3.0
* @see #datasources
* @see ExtendedDatasource
*/
@Deprecated
public static String destroyMethod = "";
public static final String DEFAULT = "default";
static final ThreadLocal