Search in sources :

Example 1 with DriverManagerDataSource

use of cn.taketoday.jdbc.datasource.DriverManagerDataSource in project today-infrastructure by TAKETODAY.

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 PathMatchingPatternResourceLoader(), new JndiDataSourceLookup());
    String resource = "/cn/taketoday/orm/jpa/persistence-example4.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertThat(info).isNotNull();
    assertThat(info.length).isEqualTo(1);
    assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement4");
    assertThat(info[0].getMappingFileNames().size()).isEqualTo(1);
    assertThat(info[0].getMappingFileNames().get(0)).isEqualTo("order-mappings.xml");
    assertThat(info[0].getManagedClassNames().size()).isEqualTo(3);
    assertThat(info[0].getManagedClassNames().get(0)).isEqualTo("com.acme.Order");
    assertThat(info[0].getManagedClassNames().get(1)).isEqualTo("com.acme.Customer");
    assertThat(info[0].getManagedClassNames().get(2)).isEqualTo("com.acme.Item");
    assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should be true when no value.").isTrue();
    assertThat(info[0].getTransactionType()).isSameAs(PersistenceUnitTransactionType.RESOURCE_LOCAL);
    assertThat(info[0].getProperties().keySet().size()).isEqualTo(0);
    builder.clear();
}
Also used : SimpleNamingContextBuilder(cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) PathMatchingPatternResourceLoader(cn.taketoday.core.io.PathMatchingPatternResourceLoader) JndiDataSourceLookup(cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) DataSource(javax.sql.DataSource) Test(org.junit.jupiter.api.Test)

Example 2 with DriverManagerDataSource

use of cn.taketoday.jdbc.datasource.DriverManagerDataSource in project today-infrastructure by TAKETODAY.

the class RdbmsOperationTests method parametersSetWithList.

@Test
public void parametersSetWithList() {
    DataSource ds = new DriverManagerDataSource();
    operation.setDataSource(ds);
    operation.setSql("select * from mytable where one = ? and two = ?");
    operation.setParameters(new SqlParameter[] { new SqlParameter("one", Types.NUMERIC), new SqlParameter("two", Types.NUMERIC) });
    operation.afterPropertiesSet();
    operation.validateParameters(new Object[] { 1, "2" });
    assertThat(operation.getDeclaredParameters().size()).isEqualTo(2);
}
Also used : SqlParameter(cn.taketoday.jdbc.core.SqlParameter) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) DataSource(javax.sql.DataSource) Test(org.junit.jupiter.api.Test)

Example 3 with DriverManagerDataSource

use of cn.taketoday.jdbc.datasource.DriverManagerDataSource in project today-infrastructure by TAKETODAY.

the class RdbmsOperationTests method validateInOutParameter.

@Test
public void validateInOutParameter() {
    operation.setDataSource(new DriverManagerDataSource());
    operation.setSql("DUMMY_PROC");
    operation.declareParameter(new SqlOutParameter("DUMMY_OUT_PARAM", Types.VARCHAR));
    operation.declareParameter(new SqlInOutParameter("DUMMY_IN_OUT_PARAM", Types.VARCHAR));
    operation.validateParameters(new Object[] { "DUMMY_VALUE1", "DUMMY_VALUE2" });
}
Also used : DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) SqlOutParameter(cn.taketoday.jdbc.core.SqlOutParameter) SqlInOutParameter(cn.taketoday.jdbc.core.SqlInOutParameter) Test(org.junit.jupiter.api.Test)

Example 4 with DriverManagerDataSource

use of cn.taketoday.jdbc.datasource.DriverManagerDataSource in project today-infrastructure by TAKETODAY.

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(cn.taketoday.jdbc.datasource.DriverManagerDataSource) Test(org.junit.jupiter.api.Test)

Example 5 with DriverManagerDataSource

use of cn.taketoday.jdbc.datasource.DriverManagerDataSource in project today-framework by TAKETODAY.

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 PathMatchingPatternResourceLoader(), new JndiDataSourceLookup());
    String resource = "/cn/taketoday/orm/jpa/persistence-example4.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertThat(info).isNotNull();
    assertThat(info.length).isEqualTo(1);
    assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement4");
    assertThat(info[0].getMappingFileNames().size()).isEqualTo(1);
    assertThat(info[0].getMappingFileNames().get(0)).isEqualTo("order-mappings.xml");
    assertThat(info[0].getManagedClassNames().size()).isEqualTo(3);
    assertThat(info[0].getManagedClassNames().get(0)).isEqualTo("com.acme.Order");
    assertThat(info[0].getManagedClassNames().get(1)).isEqualTo("com.acme.Customer");
    assertThat(info[0].getManagedClassNames().get(2)).isEqualTo("com.acme.Item");
    assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should be true when no value.").isTrue();
    assertThat(info[0].getTransactionType()).isSameAs(PersistenceUnitTransactionType.RESOURCE_LOCAL);
    assertThat(info[0].getProperties().keySet().size()).isEqualTo(0);
    builder.clear();
}
Also used : SimpleNamingContextBuilder(cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) PathMatchingPatternResourceLoader(cn.taketoday.core.io.PathMatchingPatternResourceLoader) JndiDataSourceLookup(cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) DataSource(javax.sql.DataSource) Test(org.junit.jupiter.api.Test)

Aggregations

DriverManagerDataSource (cn.taketoday.jdbc.datasource.DriverManagerDataSource)16 Test (org.junit.jupiter.api.Test)16 DataSource (javax.sql.DataSource)8 PathMatchingPatternResourceLoader (cn.taketoday.core.io.PathMatchingPatternResourceLoader)4 InvalidDataAccessApiUsageException (cn.taketoday.dao.InvalidDataAccessApiUsageException)4 SqlParameter (cn.taketoday.jdbc.core.SqlParameter)4 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)4 ClassPathResource (cn.taketoday.core.io.ClassPathResource)2 JdbcTemplate (cn.taketoday.jdbc.core.JdbcTemplate)2 SqlInOutParameter (cn.taketoday.jdbc.core.SqlInOutParameter)2 SqlOutParameter (cn.taketoday.jdbc.core.SqlOutParameter)2 JndiDataSourceLookup (cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup)2 MapDataSourceLookup (cn.taketoday.jdbc.datasource.lookup.MapDataSourceLookup)2 SimpleNamingContextBuilder (cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2