Example usage for org.springframework.jdbc.datasource.lookup JndiDataSourceLookup getDataSource

List of usage examples for org.springframework.jdbc.datasource.lookup JndiDataSourceLookup getDataSource

Introduction

In this page you can find the example usage for org.springframework.jdbc.datasource.lookup JndiDataSourceLookup getDataSource.

Prototype

@Override
    public DataSource getDataSource(String dataSourceName) throws DataSourceLookupFailureException 

Source Link

Usage

From source file:hiloTestear.ESNConfiguracionPersistencia.java

@Bean
public DataSource dataSource() {
    final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
    dsLookup.setResourceRef(true);//from   ww  w .j a  v a 2 s.c  om
    DataSource dataSource = dsLookup.getDataSource(environment.getProperty(PROPERTY_NAME_DATABASE_JNDI));
    return dataSource;
}

From source file:org.wte4j.ui.config.StandaloneJPAConfig.java

@Bean
@Lazy//  w w  w.j  av  a 2s  .c om
public DataSource wteInternalDataSource() {
    if (env.containsProperty("wte4j.jdbc.jndi")) {
        JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
        DataSource dataSource = dsLookup.getDataSource(env.getProperty("wte4j.jdbc.jndi"));
        return dataSource;

    } else if (env.containsProperty("wte4j.jdbc.url")) {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setUrl(env.getProperty("wte4j.jdbc.url"));
        dataSource.setDriverClassName(env.getProperty("wte4j.jdbc.driver"));
        dataSource.setUsername(env.getProperty("wte4j.jdbc.user"));
        dataSource.setPassword(env.getProperty("wte4j.jdbc.password"));
        return dataSource;

    } else {
        logger.info("no database configured");
        logger.info("try to start hsql database");
        hsqlServer().start();
        hsqlServerIsRunning = true;
        logger.info("hsql server started");

        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setUrl("jdbc:hsqldb:hsql://localhost/wte4j");
        dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
        dataSource.setUsername("sa");
        return dataSource;
    }

}

From source file:com.samples.platform.core.config.CoreSpringConfig.java

/**
 * Get the {@link DataSource} of {@link EipLockedoperationConfig}.
 *
 * @return the {@link DataSource} of {@link EipLockedoperationConfig}.
 *//*from   www.  j a v a 2s . c om*/
@Bean(name = EipLockedoperationConfig.DATASOURCE_BEAN_NAME)
public DataSource getEipLockedoperationDataSource() {
    JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
    DataSource bean = dsLookup.getDataSource(PersistenceConfig.DATASOURCE_JDNI_NAME);
    return bean;
}

From source file:com.samples.platform.core.config.CoreSpringConfig.java

/**
 * Get the {@link DataSource} of {@link EipModelAnalysisPersistenceConfig}.
 *
 * @return the {@link DataSource} of/*from  ww  w. j  a  va2  s.  c  o m*/
 *         {@link EipModelAnalysisPersistenceConfig}.
 */
@Bean(name = EipModelAnalysisPersistenceConfig.DATASOURCE_BEAN_NAME)
public DataSource getEipModelAnalysisDataSource() {
    JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
    DataSource bean = dsLookup.getDataSource(PersistenceConfig.DATASOURCE_JDNI_NAME);
    return bean;
}

From source file:com.samples.platform.core.config.CoreSpringConfig.java

/**
 * Get the {@link DataSource} of {@link EipPersistenceConfig}.
 *
 * @return the {@link DataSource} of {@link EipPersistenceConfig}.
 */// w w w  .j  a v  a2s  .  c  o  m
@Bean(name = EipPersistenceConfig.DATASOURCE_BEAN_NAME)
public DataSource getEipPersistenceDataSource() {
    JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
    DataSource bean = dsLookup.getDataSource(PersistenceConfig.DATASOURCE_JDNI_NAME);
    return bean;
}

From source file:com.activiti.conf.DatabaseConfiguration.java

@Bean
public DataSource dataSource() {
    log.info("Configuring Datasource");

    String dataSourceJndiName = env.getProperty("datasource.jndi.name");
    if (StringUtils.isNotEmpty(dataSourceJndiName)) {

        log.info("Using jndi datasource '" + dataSourceJndiName + "'");
        JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
        dsLookup.setResourceRef(env.getProperty("datasource.jndi.resourceRef", Boolean.class, Boolean.TRUE));
        DataSource dataSource = dsLookup.getDataSource(dataSourceJndiName);
        return dataSource;

    } else {/*from w w  w .j  a va2s  .  c  o m*/

        String dataSourceDriver = env.getProperty("datasource.driver", "com.mysql.jdbc.Driver");
        String dataSourceUrl = env.getProperty("datasource.url",
                "jdbc:mysql://127.0.0.1:3306/activiti6admin?characterEncoding=UTF-8");

        String dataSourceUsername = env.getProperty("datasource.username", "alfresco");
        String dataSourcePassword = env.getProperty("datasource.password", "alfresco");

        Integer minPoolSize = env.getProperty("datasource.min-pool-size", Integer.class);
        if (minPoolSize == null) {
            minPoolSize = 5;
        }

        Integer maxPoolSize = env.getProperty("datasource.max-pool-size", Integer.class);
        if (maxPoolSize == null) {
            maxPoolSize = 20;
        }

        Integer acquireIncrement = env.getProperty("datasource.acquire-increment", Integer.class);
        if (acquireIncrement == null) {
            acquireIncrement = 1;
        }

        String preferredTestQuery = env.getProperty("datasource.preferred-test-query");

        Boolean testConnectionOnCheckin = env.getProperty("datasource.test-connection-on-checkin",
                Boolean.class);
        if (testConnectionOnCheckin == null) {
            testConnectionOnCheckin = true;
        }

        Boolean testConnectionOnCheckOut = env.getProperty("datasource.test-connection-on-checkout",
                Boolean.class);
        if (testConnectionOnCheckOut == null) {
            testConnectionOnCheckOut = true;
        }

        Integer maxIdleTime = env.getProperty("datasource.max-idle-time", Integer.class);
        if (maxIdleTime == null) {
            maxIdleTime = 1800;
        }

        Integer maxIdleTimeExcessConnections = env.getProperty("datasource.max-idle-time-excess-connections",
                Integer.class);
        if (maxIdleTimeExcessConnections == null) {
            maxIdleTimeExcessConnections = 1800;
        }

        if (log.isInfoEnabled()) {
            log.info("Configuring Datasource with following properties (omitted password for security)");
            log.info("datasource driver: " + dataSourceDriver);
            log.info("datasource url : " + dataSourceUrl);
            log.info("datasource user name : " + dataSourceUsername);
            log.info("Min pool size | Max pool size | acquire increment : " + minPoolSize + " | " + maxPoolSize
                    + " | " + acquireIncrement);
        }

        ComboPooledDataSource ds = new ComboPooledDataSource();
        try {
            ds.setDriverClass(dataSourceDriver);
        } catch (PropertyVetoException e) {
            log.error("Could not set Jdbc Driver class", e);
            return null;
        }

        // Connection settings
        ds.setJdbcUrl(dataSourceUrl);
        ds.setUser(dataSourceUsername);
        ds.setPassword(dataSourcePassword);

        // Pool config: see http://www.mchange.com/projects/c3p0/#configuration
        ds.setMinPoolSize(minPoolSize);
        ds.setMaxPoolSize(maxPoolSize);
        ds.setAcquireIncrement(acquireIncrement);
        if (preferredTestQuery != null) {
            ds.setPreferredTestQuery(preferredTestQuery);
        }
        ds.setTestConnectionOnCheckin(testConnectionOnCheckin);
        ds.setTestConnectionOnCheckout(testConnectionOnCheckOut);
        ds.setMaxIdleTimeExcessConnections(maxIdleTimeExcessConnections);
        ds.setMaxIdleTime(maxIdleTime);

        return ds;
    }
}

From source file:org.activiti.app.conf.DatabaseConfiguration.java

@Bean
public DataSource dataSource() {
    log.info("Configuring Datasource");

    String dataSourceJndiName = env.getProperty("datasource.jndi.name");
    if (StringUtils.isNotEmpty(dataSourceJndiName)) {

        log.info("Using jndi datasource '" + dataSourceJndiName + "'");
        JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
        dsLookup.setResourceRef(env.getProperty("datasource.jndi.resourceRef", Boolean.class, Boolean.TRUE));
        DataSource dataSource = dsLookup.getDataSource(dataSourceJndiName);
        return dataSource;

    } else {/*ww w.j  a v  a2s.  c  o m*/

        String dataSourceDriver = env.getProperty("datasource.driver", "org.h2.Driver");
        String dataSourceUrl = env.getProperty("datasource.url", "jdbc:h2:mem:activiti;DB_CLOSE_DELAY=-1");

        String dataSourceUsername = env.getProperty("datasource.username", "sa");
        String dataSourcePassword = env.getProperty("datasource.password", "");

        Integer minPoolSize = env.getProperty("datasource.min-pool-size", Integer.class);
        if (minPoolSize == null) {
            minPoolSize = 10;
        }

        Integer maxPoolSize = env.getProperty("datasource.max-pool-size", Integer.class);
        if (maxPoolSize == null) {
            maxPoolSize = 100;
        }

        Integer acquireIncrement = env.getProperty("datasource.acquire-increment", Integer.class);
        if (acquireIncrement == null) {
            acquireIncrement = 5;
        }

        String preferredTestQuery = env.getProperty("datasource.preferred-test-query");

        Boolean testConnectionOnCheckin = env.getProperty("datasource.test-connection-on-checkin",
                Boolean.class);
        if (testConnectionOnCheckin == null) {
            testConnectionOnCheckin = true;
        }

        Boolean testConnectionOnCheckOut = env.getProperty("datasource.test-connection-on-checkout",
                Boolean.class);
        if (testConnectionOnCheckOut == null) {
            testConnectionOnCheckOut = true;
        }

        Integer maxIdleTime = env.getProperty("datasource.max-idle-time", Integer.class);
        if (maxIdleTime == null) {
            maxIdleTime = 1800;
        }

        Integer maxIdleTimeExcessConnections = env.getProperty("datasource.max-idle-time-excess-connections",
                Integer.class);
        if (maxIdleTimeExcessConnections == null) {
            maxIdleTimeExcessConnections = 1800;
        }

        if (log.isInfoEnabled()) {
            log.info("Configuring Datasource with following properties (omitted password for security)");
            log.info("datasource driver: " + dataSourceDriver);
            log.info("datasource url : " + dataSourceUrl);
            log.info("datasource user name : " + dataSourceUsername);
            log.info("Min pool size | Max pool size | acquire increment : " + minPoolSize + " | " + maxPoolSize
                    + " | " + acquireIncrement);
        }

        ComboPooledDataSource ds = new ComboPooledDataSource();
        try {
            ds.setDriverClass(dataSourceDriver);
        } catch (PropertyVetoException e) {
            log.error("Could not set Jdbc Driver class", e);
            return null;
        }

        // Connection settings
        ds.setJdbcUrl(dataSourceUrl);
        ds.setUser(dataSourceUsername);
        ds.setPassword(dataSourcePassword);

        // Pool config: see http://www.mchange.com/projects/c3p0/#configuration
        ds.setMinPoolSize(minPoolSize);
        ds.setMaxPoolSize(maxPoolSize);
        ds.setAcquireIncrement(acquireIncrement);
        if (preferredTestQuery != null) {
            ds.setPreferredTestQuery(preferredTestQuery);
        }
        ds.setTestConnectionOnCheckin(testConnectionOnCheckin);
        ds.setTestConnectionOnCheckout(testConnectionOnCheckOut);
        ds.setMaxIdleTimeExcessConnections(maxIdleTimeExcessConnections);
        ds.setMaxIdleTime(maxIdleTime);

        return ds;
    }
}

From source file:org.activiti.conf.DatabaseConfiguration.java

@Bean
public DataSource dataSource() {
    log.info("Configuring Datasource");

    String dataSourceJndiName = env.getProperty("datasource.jndi.name");
    if (StringUtils.isNotEmpty(dataSourceJndiName)) {

        log.info("Using jndi datasource '" + dataSourceJndiName + "'");
        JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
        dsLookup.setResourceRef(env.getProperty("datasource.jndi.resourceRef", Boolean.class, Boolean.TRUE));
        DataSource dataSource = dsLookup.getDataSource(dataSourceJndiName);
        return dataSource;

    } else {/*from  ww  w . j a  v  a  2  s. com*/

        String dataSourceDriver = env.getProperty("datasource.driver", "com.mysql.jdbc.Driver");
        String dataSourceUrl = env.getProperty("datasource.url",
                "jdbc:mysql://127.0.0.1:3306/flowable?characterEncoding=UTF-8");

        String dataSourceUsername = env.getProperty("datasource.username", "flowable");
        String dataSourcePassword = env.getProperty("datasource.password", "flowable");

        Integer minPoolSize = env.getProperty("datasource.min-pool-size", Integer.class);
        if (minPoolSize == null) {
            minPoolSize = 5;
        }

        Integer maxPoolSize = env.getProperty("datasource.max-pool-size", Integer.class);
        if (maxPoolSize == null) {
            maxPoolSize = 20;
        }

        Integer acquireIncrement = env.getProperty("datasource.acquire-increment", Integer.class);
        if (acquireIncrement == null) {
            acquireIncrement = 1;
        }

        String preferredTestQuery = env.getProperty("datasource.preferred-test-query");

        Boolean testConnectionOnCheckin = env.getProperty("datasource.test-connection-on-checkin",
                Boolean.class);
        if (testConnectionOnCheckin == null) {
            testConnectionOnCheckin = true;
        }

        Boolean testConnectionOnCheckOut = env.getProperty("datasource.test-connection-on-checkout",
                Boolean.class);
        if (testConnectionOnCheckOut == null) {
            testConnectionOnCheckOut = true;
        }

        Integer maxIdleTime = env.getProperty("datasource.max-idle-time", Integer.class);
        if (maxIdleTime == null) {
            maxIdleTime = 1800;
        }

        Integer maxIdleTimeExcessConnections = env.getProperty("datasource.max-idle-time-excess-connections",
                Integer.class);
        if (maxIdleTimeExcessConnections == null) {
            maxIdleTimeExcessConnections = 1800;
        }

        if (log.isInfoEnabled()) {
            log.info("Configuring Datasource with following properties (omitted password for security)");
            log.info("datasource driver: " + dataSourceDriver);
            log.info("datasource url : " + dataSourceUrl);
            log.info("datasource user name : " + dataSourceUsername);
            log.info("Min pool size | Max pool size | acquire increment : " + minPoolSize + " | " + maxPoolSize
                    + " | " + acquireIncrement);
        }

        ComboPooledDataSource ds = new ComboPooledDataSource();
        try {
            ds.setDriverClass(dataSourceDriver);
        } catch (PropertyVetoException e) {
            log.error("Could not set Jdbc Driver class", e);
            return null;
        }

        // Connection settings
        ds.setJdbcUrl(dataSourceUrl);
        ds.setUser(dataSourceUsername);
        ds.setPassword(dataSourcePassword);

        // Pool config: see http://www.mchange.com/projects/c3p0/#configuration
        ds.setMinPoolSize(minPoolSize);
        ds.setMaxPoolSize(maxPoolSize);
        ds.setAcquireIncrement(acquireIncrement);
        if (preferredTestQuery != null) {
            ds.setPreferredTestQuery(preferredTestQuery);
        }
        ds.setTestConnectionOnCheckin(testConnectionOnCheckin);
        ds.setTestConnectionOnCheckout(testConnectionOnCheckOut);
        ds.setMaxIdleTimeExcessConnections(maxIdleTimeExcessConnections);
        ds.setMaxIdleTime(maxIdleTime);

        return ds;
    }
}

From source file:org.flowable.admin.conf.DatabaseConfiguration.java

@Bean
public DataSource dataSource() {
    log.info("Configuring Datasource");

    String dataSourceJndiName = env.getProperty("datasource.jndi.name");
    if (StringUtils.isNotEmpty(dataSourceJndiName)) {

        log.info("Using jndi datasource '{}'", dataSourceJndiName);
        JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
        dsLookup.setResourceRef(env.getProperty("datasource.jndi.resourceRef", Boolean.class, Boolean.TRUE));
        DataSource dataSource = dsLookup.getDataSource(dataSourceJndiName);
        return dataSource;

    } else {/* w  w  w  .j  a v  a 2 s.  com*/

        String dataSourceDriver = env.getProperty("datasource.driver", "com.mysql.jdbc.Driver");
        String dataSourceUrl = env.getProperty("datasource.url",
                "jdbc:mysql://127.0.0.1:3306/flowable?characterEncoding=UTF-8");

        String dataSourceUsername = env.getProperty("datasource.username", "flowable");
        String dataSourcePassword = env.getProperty("datasource.password", "flowable");

        Integer minPoolSize = env.getProperty("datasource.min-pool-size", Integer.class);
        if (minPoolSize == null) {
            minPoolSize = 5;
        }

        Integer maxPoolSize = env.getProperty("datasource.max-pool-size", Integer.class);
        if (maxPoolSize == null) {
            maxPoolSize = 20;
        }

        Integer acquireIncrement = env.getProperty("datasource.acquire-increment", Integer.class);
        if (acquireIncrement == null) {
            acquireIncrement = 1;
        }

        String preferredTestQuery = env.getProperty("datasource.preferred-test-query");

        Boolean testConnectionOnCheckin = env.getProperty("datasource.test-connection-on-checkin",
                Boolean.class);
        if (testConnectionOnCheckin == null) {
            testConnectionOnCheckin = true;
        }

        Boolean testConnectionOnCheckOut = env.getProperty("datasource.test-connection-on-checkout",
                Boolean.class);
        if (testConnectionOnCheckOut == null) {
            testConnectionOnCheckOut = true;
        }

        Integer maxIdleTime = env.getProperty("datasource.max-idle-time", Integer.class);
        if (maxIdleTime == null) {
            maxIdleTime = 1800;
        }

        Integer maxIdleTimeExcessConnections = env.getProperty("datasource.max-idle-time-excess-connections",
                Integer.class);
        if (maxIdleTimeExcessConnections == null) {
            maxIdleTimeExcessConnections = 1800;
        }

        if (log.isInfoEnabled()) {
            log.info("Configuring Datasource with following properties (omitted password for security)");
            log.info("datasource driver : {}", dataSourceDriver);
            log.info("datasource url : {}", dataSourceUrl);
            log.info("datasource user name : {}", dataSourceUsername);
            log.info("Min pool size | Max pool size | acquire increment : {} | {} | {}", minPoolSize,
                    maxPoolSize, acquireIncrement);
        }

        ComboPooledDataSource ds = new ComboPooledDataSource();
        try {
            ds.setDriverClass(dataSourceDriver);
        } catch (PropertyVetoException e) {
            log.error("Could not set Jdbc Driver class", e);
            return null;
        }

        // Connection settings
        ds.setJdbcUrl(dataSourceUrl);
        ds.setUser(dataSourceUsername);
        ds.setPassword(dataSourcePassword);

        // Pool config: see http://www.mchange.com/projects/c3p0/#configuration
        ds.setMinPoolSize(minPoolSize);
        ds.setMaxPoolSize(maxPoolSize);
        ds.setAcquireIncrement(acquireIncrement);
        if (preferredTestQuery != null) {
            ds.setPreferredTestQuery(preferredTestQuery);
        }
        ds.setTestConnectionOnCheckin(testConnectionOnCheckin);
        ds.setTestConnectionOnCheckout(testConnectionOnCheckOut);
        ds.setMaxIdleTimeExcessConnections(maxIdleTimeExcessConnections);
        ds.setMaxIdleTime(maxIdleTime);

        return ds;
    }
}

From source file:org.flowable.app.conf.DatabaseConfiguration.java

@Bean
public DataSource dataSource() {
    log.info("Configuring Datasource");

    String dataSourceJndiName = env.getProperty("datasource.jndi.name");
    if (StringUtils.isNotEmpty(dataSourceJndiName)) {

        log.info("Using jndi datasource '{}'", dataSourceJndiName);
        JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
        dsLookup.setResourceRef(env.getProperty("datasource.jndi.resourceRef", Boolean.class, Boolean.TRUE));
        DataSource dataSource = dsLookup.getDataSource(dataSourceJndiName);
        return dataSource;

    } else {// w w w . j a  va  2  s .c om

        String dataSourceDriver = env.getProperty("datasource.driver", "org.h2.Driver");
        String dataSourceUrl = env.getProperty("datasource.url", "jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1");

        String dataSourceUsername = env.getProperty("datasource.username", "sa");
        String dataSourcePassword = env.getProperty("datasource.password", "");

        Integer minPoolSize = env.getProperty("datasource.min-pool-size", Integer.class);
        if (minPoolSize == null) {
            minPoolSize = 10;
        }

        Integer maxPoolSize = env.getProperty("datasource.max-pool-size", Integer.class);
        if (maxPoolSize == null) {
            maxPoolSize = 100;
        }

        Integer acquireIncrement = env.getProperty("datasource.acquire-increment", Integer.class);
        if (acquireIncrement == null) {
            acquireIncrement = 5;
        }

        String preferredTestQuery = env.getProperty("datasource.preferred-test-query");

        Boolean testConnectionOnCheckin = env.getProperty("datasource.test-connection-on-checkin",
                Boolean.class);
        if (testConnectionOnCheckin == null) {
            testConnectionOnCheckin = true;
        }

        Boolean testConnectionOnCheckOut = env.getProperty("datasource.test-connection-on-checkout",
                Boolean.class);
        if (testConnectionOnCheckOut == null) {
            testConnectionOnCheckOut = true;
        }

        Integer maxIdleTime = env.getProperty("datasource.max-idle-time", Integer.class);
        if (maxIdleTime == null) {
            maxIdleTime = 1800;
        }

        Integer maxIdleTimeExcessConnections = env.getProperty("datasource.max-idle-time-excess-connections",
                Integer.class);
        if (maxIdleTimeExcessConnections == null) {
            maxIdleTimeExcessConnections = 1800;
        }

        if (log.isInfoEnabled()) {
            log.info("Configuring Datasource with following properties (omitted password for security)");
            log.info("datasource driver : {}", dataSourceDriver);
            log.info("datasource url : {}", dataSourceUrl);
            log.info("datasource user name : {}", dataSourceUsername);
            log.info("Min pool size | Max pool size | acquire increment : {} | {} | {}", minPoolSize,
                    maxPoolSize, acquireIncrement);
        }

        ComboPooledDataSource ds = new ComboPooledDataSource();
        try {
            ds.setDriverClass(dataSourceDriver);
        } catch (PropertyVetoException e) {
            log.error("Could not set Jdbc Driver class", e);
            return null;
        }

        // Connection settings
        ds.setJdbcUrl(dataSourceUrl);
        ds.setUser(dataSourceUsername);
        ds.setPassword(dataSourcePassword);

        // Pool config: see http://www.mchange.com/projects/c3p0/#configuration
        ds.setMinPoolSize(minPoolSize);
        ds.setMaxPoolSize(maxPoolSize);
        ds.setAcquireIncrement(acquireIncrement);
        if (preferredTestQuery != null) {
            ds.setPreferredTestQuery(preferredTestQuery);
        }
        ds.setTestConnectionOnCheckin(testConnectionOnCheckin);
        ds.setTestConnectionOnCheckout(testConnectionOnCheckOut);
        ds.setMaxIdleTimeExcessConnections(maxIdleTimeExcessConnections);
        ds.setMaxIdleTime(maxIdleTime);

        return ds;
    }
}