Search in sources :

Example 46 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project av-service by dvoraka.

the class DbConfig method dataSource.

@Bean
public DataSource dataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(driver);
    dataSource.setUrl(url);
    dataSource.setUsername(user);
    dataSource.setPassword(pass);
    return dataSource;
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Bean(org.springframework.context.annotation.Bean)

Example 47 with DriverManagerDataSource

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

the class OracleDataSourceConfiguration method createDataSource.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.jdbc.testing.DataSourceConfiguration#createDataSource()
	 */
@Override
protected DataSource createDataSource() {
    if (ORACLE_CONTAINER == null) {
        LOG.info("Oracle starting...");
        OracleContainer container = new OracleContainer("gvenzl/oracle-xe:18.4.0-slim").withReuse(true);
        container.start();
        LOG.info("Oracle started");
        ORACLE_CONTAINER = container;
    }
    initDb();
    return new DriverManagerDataSource(ORACLE_CONTAINER.getJdbcUrl(), ORACLE_CONTAINER.getUsername(), ORACLE_CONTAINER.getPassword());
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) OracleContainer(org.testcontainers.containers.OracleContainer)

Example 48 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project rdbcache by rdbcache.

the class DataSourceConfig method systemDataSource.

@Bean
public DataSource systemDataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(env.getProperty("system.datasource.driver-class-name"));
    dataSource.setUrl(env.getProperty("system.datasource.url"));
    dataSource.setUsername(env.getProperty("system.datasource.username"));
    dataSource.setPassword(env.getProperty("system.datasource.password"));
    return dataSource;
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 49 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project rdbcache by rdbcache.

the class DataSourceConfig method dataSource.

@Bean
public DataSource dataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
    dataSource.setUrl(env.getProperty("spring.datasource.url"));
    dataSource.setUsername(env.getProperty("spring.datasource.username"));
    dataSource.setPassword(env.getProperty("spring.datasource.password"));
    return dataSource;
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 50 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project buffer-slayer by tramchamploo.

the class AbstractTimeUsedComparison method run.

protected void run() throws Exception {
    BatchJdbcTemplate batch;
    JdbcTemplate unbatch;
    SenderProxy proxy;
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl(propertyOr("jdbcUrl", "jdbc:mysql://127.0.0.1:3306?useSSL=false"));
    dataSource.setUsername(propertyOr("username", "root"));
    dataSource.setPassword(propertyOr("password", "root"));
    JdbcTemplate delegate = new JdbcTemplate(dataSource);
    delegate.setDataSource(dataSource);
    AtomicLong counter = new AtomicLong();
    final String CREATE_DATABASE = "CREATE DATABASE IF NOT EXISTS test";
    final String CREATE_TABLE = "CREATE TABLE test.benchmark(id INT PRIMARY KEY AUTO_INCREMENT, data VARCHAR(32), time TIMESTAMP)";
    final String DROP_TABLE = "DROP TABLE IF EXISTS test.benchmark";
    final String INSERTION = "INSERT INTO test.benchmark(data, time) VALUES(?, ?)";
    final String MODIFICATION = "UPDATE test.benchmark SET data = ? WHERE id = ?";
    CountDownLatch countDown = new CountDownLatch(1);
    proxy = new SenderProxy(new JdbcTemplateSender(delegate));
    proxy.onMessages(updated -> {
        if (counter.addAndGet(updated.size()) == 5050) {
            countDown.countDown();
        }
    });
    Reporter<Sql, Integer> reporter = reporter(proxy);
    batch = new BatchJdbcTemplate(delegate, reporter);
    batch.setDataSource(dataSource);
    unbatch = new JdbcTemplate(dataSource);
    unbatch.setDataSource(dataSource);
    unbatch.update(CREATE_DATABASE);
    unbatch.update(DROP_TABLE);
    unbatch.update(CREATE_TABLE);
    Random random = new Random(System.currentTimeMillis());
    long start = System.nanoTime();
    for (int i = 0; i < 5000; i++) {
        batch.update(INSERTION, randomString(), new Date());
        if (i % 100 == 0) {
            batch.update(MODIFICATION, randomString(), random.nextInt(i + 1) + 1);
        }
    }
    countDown.await();
    long used = System.nanoTime() - start;
    System.out.printf("batch time used:   %15d\n", used);
    reporter.close();
    unbatch.update(DROP_TABLE);
    unbatch.update(CREATE_TABLE);
    start = System.nanoTime();
    for (int i = 0; i < 5000; i++) {
        unbatch.update(INSERTION, randomString(), new Date());
        if (i % 100 == 0) {
            unbatch.update(MODIFICATION, randomString(), random.nextInt(i + 1) + 1);
        }
    }
    used = System.nanoTime() - start;
    System.out.printf("unbatch time used: %15d", used);
    unbatch.update(DROP_TABLE);
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) CountDownLatch(java.util.concurrent.CountDownLatch) Date(java.util.Date) AtomicLong(java.util.concurrent.atomic.AtomicLong) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Random(java.util.Random) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource)

Aggregations

DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)67 Bean (org.springframework.context.annotation.Bean)29 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)20 Test (org.junit.jupiter.api.Test)9 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)8 DataSource (javax.sql.DataSource)7 SQLException (java.sql.SQLException)4 Properties (java.util.Properties)4 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 InitialContext (javax.naming.InitialContext)2 XADataSource (javax.sql.XADataSource)2 Before (org.junit.Before)2 ApplicationContextHolder (org.mifos.application.servicefacade.ApplicationContextHolder)2 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)2