Search in sources :

Example 26 with DataSource

use of javax.sql.DataSource in project druid by alibaba.

the class SqlMapClientWrapperTest method setUp.

protected void setUp() throws Exception {
    context = new ClassPathXmlApplicationContext("com/alibaba/druid/pool/ibatis/spring-config-ibatis-1.xml");
    DataSource dataSource = (DataSource) context.getBean("dataSource");
    {
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        stmt.execute("CREATE TABLE sequence_seed (value INTEGER, name VARCHAR(50))");
        stmt.close();
        conn.close();
    }
    {
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        stmt.execute("CREATE TABLE t_User (id BIGINT, name VARCHAR(50))");
        stmt.close();
        conn.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Statement(java.sql.Statement) Connection(java.sql.Connection) DataSource(javax.sql.DataSource)

Example 27 with DataSource

use of javax.sql.DataSource in project java-design-patterns by iluwatar.

the class AppConfig method dataSource.

/**
   * Creation of H2 db
   * 
   * @return A new Instance of DataSource
   */
@Bean(destroyMethod = "close")
public DataSource dataSource() {
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName("org.h2.Driver");
    basicDataSource.setUrl("jdbc:h2:~/databases/person");
    basicDataSource.setUsername("sa");
    basicDataSource.setPassword("sa");
    return (DataSource) basicDataSource;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) DataSource(javax.sql.DataSource) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 28 with DataSource

use of javax.sql.DataSource in project eweb4j-framework by laiweiwei.

the class DAOFactory method getSearchDAO.

/**
	 * 创建SearchDAOImpl实例
	 * 
	 * @param dsName
	 *            数据库配置信息Bean的名字,默认下在eweb4j-dbInfo-config.xml文件中<name></name>
	 *            找到这个值
	 * @return
	 */
public static SearchDAO getSearchDAO(String dsName) {
    DataSource ds = DataSourceWrapCache.get(dsName);
    DBInfoConfigBean dcb = DBInfoConfigBeanCache.get(dsName);
    return new SearchDAOImpl(ds, dcb.getDataBaseType());
}
Also used : SearchDAOImpl(org.eweb4j.orm.dao.select.SearchDAOImpl) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) DataSource(javax.sql.DataSource)

Example 29 with DataSource

use of javax.sql.DataSource in project eweb4j-framework by laiweiwei.

the class DAOFactory method getSelectDAO.

/**
	 * 创建SelectDAOImpl实例
	 * 
	 * @param dsName
	 *            数据库配置信息Bean的名字,默认下在eweb4j-dbInfo-config.xml文件中<name></name>
	 *            找到这个值
	 * @return
	 */
public static SelectDAO getSelectDAO(String dsName) {
    DataSource ds = DataSourceWrapCache.get(dsName);
    DBInfoConfigBean dcb = DBInfoConfigBeanCache.get(dsName);
    return new SelectDAOImpl(ds, dcb.getDataBaseType());
}
Also used : SelectDAOImpl(org.eweb4j.orm.dao.select.SelectDAOImpl) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) DataSource(javax.sql.DataSource)

Example 30 with DataSource

use of javax.sql.DataSource in project eweb4j-framework by laiweiwei.

the class DAOFactory method getSearchDAO.

public static SearchDAO getSearchDAO() {
    DataSource ds = DataSourceWrapCache.get();
    DBInfoConfigBean dcb = DBInfoConfigBeanCache.get();
    return new SearchDAOImpl(ds, dcb.getDataBaseType());
}
Also used : SearchDAOImpl(org.eweb4j.orm.dao.select.SearchDAOImpl) DBInfoConfigBean(org.eweb4j.orm.dao.config.bean.DBInfoConfigBean) DataSource(javax.sql.DataSource)

Aggregations

DataSource (javax.sql.DataSource)546 Connection (java.sql.Connection)200 Test (org.junit.Test)192 SQLException (java.sql.SQLException)118 Context (javax.naming.Context)70 ResultSet (java.sql.ResultSet)59 Statement (java.sql.Statement)59 NamingException (javax.naming.NamingException)57 InitialContext (javax.naming.InitialContext)55 EJBException (javax.ejb.EJBException)40 HashMap (java.util.HashMap)38 PreparedStatement (java.sql.PreparedStatement)37 Properties (java.util.Properties)35 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)34 RemoteException (java.rmi.RemoteException)32 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)31 UserTransaction (javax.transaction.UserTransaction)30 IOException (java.io.IOException)29 ArrayList (java.util.ArrayList)26 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)21