Search in sources :

Example 66 with DataSource

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

the class InitializeDatabaseIntegrationTests method testDisableCreateEmbeddedDatabase.

@Test(expected = BadSqlGrammarException.class)
public void testDisableCreateEmbeddedDatabase() throws Exception {
    System.setProperty("ENABLED", "false");
    context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-config.xml");
    assertCorrectSetup(context.getBean("dataSource", DataSource.class));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 67 with DataSource

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

the class InitializeDatabaseIntegrationTests method testCreateEmbeddedDatabase.

@Test
public void testCreateEmbeddedDatabase() throws Exception {
    context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-config.xml");
    assertCorrectSetup(context.getBean("dataSource", DataSource.class));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 68 with DataSource

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

the class JdbcNamespaceIntegrationTests method createAndDestroy.

@Test
public void createAndDestroy() throws Exception {
    ClassPathXmlApplicationContext context = context("jdbc-destroy-config.xml");
    try {
        DataSource dataSource = context.getBean(DataSource.class);
        JdbcTemplate template = new JdbcTemplate(dataSource);
        assertNumRowsInTestTable(template, 1);
        context.getBean(DataSourceInitializer.class).destroy();
        // Table has been dropped
        expected.expect(BadSqlGrammarException.class);
        assertNumRowsInTestTable(template, 1);
    } finally {
        context.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DataSourceInitializer(org.springframework.jdbc.datasource.init.DataSourceInitializer) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AbstractDriverBasedDataSource(org.springframework.jdbc.datasource.AbstractDriverBasedDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 69 with DataSource

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

the class JdbcNamespaceIntegrationTests method createAndDestroyNestedWithH2.

@Test
public void createAndDestroyNestedWithH2() throws Exception {
    ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config-h2.xml");
    try {
        DataSource dataSource = context.getBean(DataSource.class);
        JdbcTemplate template = new JdbcTemplate(dataSource);
        assertNumRowsInTestTable(template, 1);
        context.getBean(EmbeddedDatabaseFactoryBean.class).destroy();
        // Table has been dropped
        expected.expect(BadSqlGrammarException.class);
        assertNumRowsInTestTable(template, 1);
    } finally {
        context.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) EmbeddedDatabaseFactoryBean(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean) AbstractDriverBasedDataSource(org.springframework.jdbc.datasource.AbstractDriverBasedDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 70 with DataSource

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

the class DataSourceUtils method getConnectionSynchronizationOrder.

/**
	 * Determine the connection synchronization order to use for the given
	 * DataSource. Decreased for every level of nesting that a DataSource
	 * has, checked through the level of DelegatingDataSource nesting.
	 * @param dataSource the DataSource to check
	 * @return the connection synchronization order to use
	 * @see #CONNECTION_SYNCHRONIZATION_ORDER
	 */
private static int getConnectionSynchronizationOrder(DataSource dataSource) {
    int order = CONNECTION_SYNCHRONIZATION_ORDER;
    DataSource currDs = dataSource;
    while (currDs instanceof DelegatingDataSource) {
        order--;
        currDs = ((DelegatingDataSource) currDs).getTargetDataSource();
    }
    return order;
}
Also used : 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