Search in sources :

Example 56 with DataSource

use of javax.sql.DataSource in project platformlayer by platformlayer.

the class GuiceDataSourceProvider method bindJndi.

public static Provider<? extends DataSource> bindJndi(final String key) {
    Provider<DataSource> provider = new Provider<DataSource>() {

        @Override
        public DataSource get() {
            try {
                InitialContext context = new InitialContext();
                DataSource dataSource = (DataSource) context.lookup(key);
                return dataSource;
            } catch (NamingException e) {
                throw new IllegalStateException("Error getting JDNI connection: " + key, e);
            }
        }
    };
    return provider;
}
Also used : NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) Provider(com.google.inject.Provider) DataSource(javax.sql.DataSource)

Example 57 with DataSource

use of javax.sql.DataSource in project spring-boot by spring-projects.

the class AbstractDevToolsDataSourceAutoConfigurationTests method singleManuallyConfiguredDataSourceIsNotClosed.

@Test
public void singleManuallyConfiguredDataSourceIsNotClosed() throws SQLException {
    ConfigurableApplicationContext context = createContext(DataSourcePropertiesConfiguration.class, SingleDataSourceConfiguration.class);
    DataSource dataSource = context.getBean(DataSource.class);
    Statement statement = configureDataSourceBehaviour(dataSource);
    verify(statement, times(0)).execute("SHUTDOWN");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Statement(java.sql.Statement) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 58 with DataSource

use of javax.sql.DataSource in project spring-boot by spring-projects.

the class AbstractDevToolsDataSourceAutoConfigurationTests method emptyFactoryMethodMetadataIgnored.

@Test
public void emptyFactoryMethodMetadataIgnored() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    DataSource dataSource = mock(DataSource.class);
    AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(dataSource.getClass());
    context.registerBeanDefinition("dataSource", beanDefinition);
    context.register(DataSourcePropertiesConfiguration.class);
    context.register(DevToolsDataSourceAutoConfiguration.class);
    context.refresh();
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 59 with DataSource

use of javax.sql.DataSource in project spring-boot by spring-projects.

the class AbstractDevToolsDataSourceAutoConfigurationTests method multipleDataSourcesAreIgnored.

@Test
public void multipleDataSourcesAreIgnored() throws SQLException {
    ConfigurableApplicationContext context = createContext(DataSourcePropertiesConfiguration.class, MultipleDataSourcesConfiguration.class);
    Collection<DataSource> dataSources = context.getBeansOfType(DataSource.class).values();
    for (DataSource dataSource : dataSources) {
        Statement statement = configureDataSourceBehaviour(dataSource);
        verify(statement, times(0)).execute("SHUTDOWN");
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Statement(java.sql.Statement) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 60 with DataSource

use of javax.sql.DataSource in project spring-boot by spring-projects.

the class AtomikosXADataSourceWrapperTests method wrap.

@Test
public void wrap() throws Exception {
    XADataSource dataSource = mock(XADataSource.class);
    AtomikosXADataSourceWrapper wrapper = new AtomikosXADataSourceWrapper();
    DataSource wrapped = wrapper.wrapDataSource(dataSource);
    assertThat(wrapped).isInstanceOf(AtomikosDataSourceBean.class);
    assertThat(((AtomikosDataSourceBean) wrapped).getXaDataSource()).isSameAs(dataSource);
}
Also used : XADataSource(javax.sql.XADataSource) DataSource(javax.sql.DataSource) XADataSource(javax.sql.XADataSource) Test(org.junit.Test)

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