Search in sources :

Example 21 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project tutorials by eugenp.

the class AppConfig method dataSource.

@Bean
public DataSource dataSource() {
    final DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(env.getProperty("driverClassName"));
    dataSource.setUrl(env.getProperty("url"));
    dataSource.setUsername(env.getProperty("user"));
    dataSource.setPassword(env.getProperty("password"));
    return dataSource;
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 22 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project tutorials by eugenp.

the class PersistenceConfig method dataSource.

// 
@Bean
public DataSource dataSource() {
    final DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
    dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url")));
    dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user")));
    dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass")));
    return dataSource;
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Bean(org.springframework.context.annotation.Bean)

Example 23 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project workbench by all-of-us.

the class TestJpaConfig method dataSource.

@Bean
public DataSource dataSource() {
    final DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("org.h2.Driver");
    dataSource.setUrl("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1");
    dataSource.setUsername("sa");
    dataSource.setPassword("sa");
    return dataSource;
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 24 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project narayana by jbosstm.

the class StableConnections method getDataSource.

private static DataSource getDataSource(String user) throws NamingException, SQLException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException {
    InitialContext initialContext = prepareInitialContext();
    Class clazz = Class.forName("org.postgresql.xa.PGXADataSource");
    XADataSource xaDataSource = (XADataSource) clazz.newInstance();
    clazz.getMethod("setServerName", new Class[] { String.class }).invoke(xaDataSource, new Object[] { DB_HOST });
    clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(xaDataSource, new Object[] { DB_SID });
    clazz.getMethod("setUser", new Class[] { String.class }).invoke(xaDataSource, new Object[] { user });
    clazz.getMethod("setPassword", new Class[] { String.class }).invoke(xaDataSource, new Object[] { user });
    clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(xaDataSource, new Object[] { 5432 });
    final String name = "java:/comp/env/jdbc/" + user;
    initialContext.bind(name, xaDataSource);
    DriverManagerDataSource dataSource = new DriverManagerDataSource("jdbc:arjuna:" + name);
    dataSource.setDriverClassName("com.arjuna.ats.jdbc.TransactionalDriver");
    return dataSource;
}
Also used : XADataSource(javax.sql.XADataSource) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) InitialContext(javax.naming.InitialContext)

Example 25 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project irida by phac-nml.

the class JobDetailsCommandLineTransfer method main.

public static void main(String[] args) {
    checkNotNull(GALAXY_URL, "Galaxy URL is required. [galaxy.url]");
    checkNotNull(GALAXY_API, "Galaxy API key is required. [galaxy.api.key]");
    checkNotNull(JDBC_URL, "JDBC URL is required. [jdbc.url]");
    checkNotNull(JDBC_USER, "JDBC user is required. [jdbc.user]");
    checkNotNull(JDBC_PASS, "JDBC password is required. [jdbc.pass]");
    final GalaxyInstance gi = GalaxyInstanceFactory.get(GALAXY_URL, GALAXY_API);
    final JobsClient jobsClient = gi.getJobsClient();
    final DriverManagerDataSource dataSource = new DriverManagerDataSource(JDBC_URL, JDBC_USER, JDBC_PASS);
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    final JdbcTemplate template = new JdbcTemplate(dataSource);
    template.query("select id, execution_manager_identifier from tool_execution", (rs, row) -> Pair.of(rs.getLong("id"), rs.getString("execution_manager_identifier"))).forEach(e -> {
        final JobDetails jobDetails = jobsClient.showJob(e.v);
        template.update("update tool_execution set command_line = ? where id = ?", jobDetails.getCommandLine(), e.k);
        logger.debug(String.format("Updated tool execution [%s] with command line [%s]", e.k, jobDetails.getCommandLine()));
    });
}
Also used : Logger(org.slf4j.Logger) GalaxyInstance(com.github.jmchilton.blend4j.galaxy.GalaxyInstance) LoggerFactory(org.slf4j.LoggerFactory) GalaxyInstanceFactory(com.github.jmchilton.blend4j.galaxy.GalaxyInstanceFactory) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Preconditions(com.google.common.base.Preconditions) JobsClient(com.github.jmchilton.blend4j.galaxy.JobsClient) JobDetails(com.github.jmchilton.blend4j.galaxy.beans.JobDetails) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) GalaxyInstance(com.github.jmchilton.blend4j.galaxy.GalaxyInstance) JobDetails(com.github.jmchilton.blend4j.galaxy.beans.JobDetails) JobsClient(com.github.jmchilton.blend4j.galaxy.JobsClient)

Aggregations

DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)66 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