Search in sources :

Example 6 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project spring-framework by spring-projects.

the class RdbmsOperationTests method compileTwice.

@Test
public void compileTwice() {
    operation.setDataSource(new DriverManagerDataSource());
    operation.setSql("select * from mytable");
    operation.setTypes(null);
    operation.compile();
    operation.compile();
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Test(org.junit.Test)

Example 7 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project spring-framework by spring-projects.

the class RdbmsOperationTests method parameterPropagation.

@Test
public void parameterPropagation() {
    SqlOperation operation = new SqlOperation() {
    };
    DataSource ds = new DriverManagerDataSource();
    operation.setDataSource(ds);
    operation.setFetchSize(10);
    operation.setMaxRows(20);
    JdbcTemplate jt = operation.getJdbcTemplate();
    assertEquals(ds, jt.getDataSource());
    assertEquals(10, jt.getFetchSize());
    assertEquals(20, jt.getMaxRows());
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataSource(javax.sql.DataSource) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Test(org.junit.Test)

Example 8 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project spring-framework by spring-projects.

the class PersistenceXmlParsingTests method testExampleComplex.

@Test
public void testExampleComplex() throws Exception {
    DataSource ds = new DriverManagerDataSource();
    String resource = "/org/springframework/orm/jpa/persistence-complex.xml";
    MapDataSourceLookup dataSourceLookup = new MapDataSourceLookup();
    Map<String, DataSource> dataSources = new HashMap<>();
    dataSources.put("jdbc/MyPartDB", ds);
    dataSources.put("jdbc/MyDB", ds);
    dataSourceLookup.setDataSources(dataSources);
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), dataSourceLookup);
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertEquals(2, info.length);
    PersistenceUnitInfo pu1 = info[0];
    assertEquals("pu1", pu1.getPersistenceUnitName());
    assertEquals("com.acme.AcmePersistence", pu1.getPersistenceProviderClassName());
    assertEquals(1, pu1.getMappingFileNames().size());
    assertEquals("ormap2.xml", pu1.getMappingFileNames().get(0));
    assertEquals(1, pu1.getJarFileUrls().size());
    assertEquals(new ClassPathResource("order.jar").getURL(), pu1.getJarFileUrls().get(0));
    assertFalse(pu1.excludeUnlistedClasses());
    assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, pu1.getTransactionType());
    Properties props = pu1.getProperties();
    assertEquals(2, props.keySet().size());
    assertEquals("on", props.getProperty("com.acme.persistence.sql-logging"));
    assertEquals("bar", props.getProperty("foo"));
    assertNull(pu1.getNonJtaDataSource());
    assertSame(ds, pu1.getJtaDataSource());
    assertFalse("Exclude unlisted should default false in 1.0.", pu1.excludeUnlistedClasses());
    PersistenceUnitInfo pu2 = info[1];
    assertSame(PersistenceUnitTransactionType.JTA, pu2.getTransactionType());
    assertEquals("com.acme.AcmePersistence", pu2.getPersistenceProviderClassName());
    assertEquals(1, pu2.getMappingFileNames().size());
    assertEquals("order2.xml", pu2.getMappingFileNames().get(0));
    // the following assertions fail only during coverage runs
    // assertEquals(1, pu2.getJarFileUrls().size());
    // assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), pu2.getJarFileUrls().get(0));
    assertTrue(pu2.excludeUnlistedClasses());
    assertNull(pu2.getJtaDataSource());
    assertEquals(ds, pu2.getNonJtaDataSource());
    assertTrue("Exclude unlisted should be true when no value.", pu2.excludeUnlistedClasses());
}
Also used : HashMap(java.util.HashMap) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Properties(java.util.Properties) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) DataSource(javax.sql.DataSource) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) MapDataSourceLookup(org.springframework.jdbc.datasource.lookup.MapDataSourceLookup) Test(org.junit.Test)

Example 9 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project spring-framework by spring-projects.

the class PersistenceXmlParsingTests method testExample4.

@Test
public void testExample4() throws Exception {
    SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
    DataSource ds = new DriverManagerDataSource();
    builder.bind("java:comp/env/jdbc/MyDB", ds);
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/orm/jpa/persistence-example4.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertNotNull(info);
    assertEquals(1, info.length);
    assertEquals("OrderManagement4", info[0].getPersistenceUnitName());
    assertEquals(1, info[0].getMappingFileNames().size());
    assertEquals("order-mappings.xml", info[0].getMappingFileNames().get(0));
    assertEquals(3, info[0].getManagedClassNames().size());
    assertEquals("com.acme.Order", info[0].getManagedClassNames().get(0));
    assertEquals("com.acme.Customer", info[0].getManagedClassNames().get(1));
    assertEquals("com.acme.Item", info[0].getManagedClassNames().get(2));
    assertTrue("Exclude unlisted should be true when no value.", info[0].excludeUnlistedClasses());
    assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, info[0].getTransactionType());
    assertEquals(0, info[0].getProperties().keySet().size());
    builder.clear();
}
Also used : SimpleNamingContextBuilder(org.springframework.tests.mock.jndi.SimpleNamingContextBuilder) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) JndiDataSourceLookup(org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) DataSource(javax.sql.DataSource) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Test(org.junit.Test)

Example 10 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project simple-java by angryziber.

the class JDBCPhotoSpotRepositoryIntegrationTest method initMockDB.

@Before
public void initMockDB() throws Exception {
    repo.dataSource = new DriverManagerDataSource("jdbc:h2:mem:test", "sa", "sa");
    conn = repo.dataSource.getConnection();
    conn.createStatement().execute("create table PhotoSpot (id int auto_increment primary key, name varchar, description varchar, latitude float, longitude float)");
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Before(org.junit.Before)

Aggregations

DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)16 Test (org.junit.Test)8 DataSource (javax.sql.DataSource)4 Bean (org.springframework.context.annotation.Bean)3 SQLException (java.sql.SQLException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)2 Before (org.junit.Before)2 ApplicationContextHolder (org.mifos.application.servicefacade.ApplicationContextHolder)2 ApplicationContext (org.springframework.context.ApplicationContext)2 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)2 SqlParameter (org.springframework.jdbc.core.SqlParameter)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1