Search in sources :

Example 6 with DataSource

use of org.apache.tomcat.jdbc.pool.DataSource in project spring-boot by spring-projects.

the class TomcatDataSourcePoolMetadataTests method createDataSource.

private DataSource createDataSource(int minSize, int maxSize) {
    DataSource dataSource = (DataSource) initializeBuilder().type(DataSource.class).build();
    dataSource.setMinIdle(minSize);
    dataSource.setMaxActive(maxSize);
    // Avoid warnings
    dataSource.setInitialSize(minSize);
    dataSource.setMaxIdle(maxSize);
    return dataSource;
}
Also used : DataSource(org.apache.tomcat.jdbc.pool.DataSource)

Example 7 with DataSource

use of org.apache.tomcat.jdbc.pool.DataSource in project spring-boot by spring-projects.

the class TomcatDataSourcePoolMetadataTests method getValidationQuery.

@Override
public void getValidationQuery() {
    DataSource dataSource = createDataSource(0, 4);
    dataSource.setValidationQuery("SELECT FROM FOO");
    assertThat(new TomcatDataSourcePoolMetadata(dataSource).getValidationQuery()).isEqualTo("SELECT FROM FOO");
}
Also used : DataSource(org.apache.tomcat.jdbc.pool.DataSource)

Example 8 with DataSource

use of org.apache.tomcat.jdbc.pool.DataSource in project Gargoyle by callakrsos.

the class FxDAOReadFunction method apply.

@Override
public TbmSysDaoDVO apply(TbmSysDaoDVO t) {
    DataSource dataSource = null;
    try {
        dataSource = DbUtil.getDataSource();
        boolean existsSchemaDatabase = DbUtil.isExistsSchemaDatabase();
        List<TbpSysDaoMethodsDVO> methods = getMethod(dataSource, t, existsSchemaDatabase);
        List<TbpSysDaoColumnsDVO> columns = getColumns(dataSource, t, existsSchemaDatabase);
        List<TbpSysDaoFieldsDVO> fields = getField(dataSource, t, existsSchemaDatabase);
        for (TbpSysDaoMethodsDVO m : methods) {
            m.setTbpSysDaoColumnsDVOList(columns.stream().filter(col -> m.getMethodName().equals(col.getMethodName())).collect(Collectors.toList()));
            m.setTbpSysDaoFieldsDVOList(fields.stream().filter(col -> m.getMethodName().equals(col.getMethodName())).collect(Collectors.toList()));
        }
        t.setTbpSysDaoMethodsDVOList(methods);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            DbUtil.close(dataSource);
        } catch (Exception e) {
        }
    }
    return t;
}
Also used : TbpSysDaoMethodsDVO(kyj.Fx.dao.wizard.core.model.vo.TbpSysDaoMethodsDVO) TbpSysDaoColumnsDVO(kyj.Fx.dao.wizard.core.model.vo.TbpSysDaoColumnsDVO) SQLException(java.sql.SQLException) DataSource(org.apache.tomcat.jdbc.pool.DataSource) TbpSysDaoFieldsDVO(kyj.Fx.dao.wizard.core.model.vo.TbpSysDaoFieldsDVO)

Example 9 with DataSource

use of org.apache.tomcat.jdbc.pool.DataSource in project Gargoyle by callakrsos.

the class DbUtil method select.

/**
	 * SQL을 실행하고 결과를 반환
	 *
	 * @param sql
	 * @return
	 * @throws Exception
	 */
public static <T> List<T> select(final String sql, MapSqlParameterSource paramMap, RowMapper<T> rowMapper) throws Exception {
    DataSource dataSource = null;
    List<T> query = null;
    try {
        noticeQuery(sql);
        dataSource = getDataSource();
        NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
        // String _sql = ValueUtil.getVelocityToText(sql,
        // paramMap.getValues());
        query = jdbcTemplate.query(sql, paramMap, rowMapper);
    } catch (Exception e) {
        // cleanDataSource();
        // close(dataSource);
        LOGGER.error(ValueUtil.toString(e));
        throw e;
    } finally {
        cleanDataSource();
    // close(dataSource);
    }
    return query;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) NotSupportException(com.kyj.fx.voeditor.visual.exceptions.NotSupportException) DataSource(org.apache.tomcat.jdbc.pool.DataSource)

Example 10 with DataSource

use of org.apache.tomcat.jdbc.pool.DataSource in project Gargoyle by callakrsos.

the class DbUtil method select.

/**
	 * SQL을 실행하고 결과를 반환
	 *
	 * @param sql
	 * @return
	 * @throws Exception
	 */
public static <T> List<T> select(final String sql, Map<String, Object> paramMap, RowMapper<T> rowMapper) throws Exception {
    DataSource dataSource = null;
    List<T> query = null;
    try {
        dataSource = getDataSource();
        query = select(dataSource, sql, paramMap, rowMapper);
    } catch (Exception e) {
        LOGGER.error(ValueUtil.toString(e));
        query = Collections.emptyList();
    } finally {
        close(dataSource);
    }
    return query;
}
Also used : SQLException(java.sql.SQLException) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) NotSupportException(com.kyj.fx.voeditor.visual.exceptions.NotSupportException) DataSource(org.apache.tomcat.jdbc.pool.DataSource)

Aggregations

DataSource (org.apache.tomcat.jdbc.pool.DataSource)21 PoolProperties (org.apache.tomcat.jdbc.pool.PoolProperties)8 Test (org.junit.Test)8 Connection (java.sql.Connection)5 SQLException (java.sql.SQLException)5 DefaultProperties (org.apache.tomcat.jdbc.test.DefaultProperties)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)2 NotSupportException (com.kyj.fx.voeditor.visual.exceptions.NotSupportException)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 PoolConfiguration (org.apache.tomcat.jdbc.pool.PoolConfiguration)2 BeanSerializerFactory (com.fasterxml.jackson.databind.ser.BeanSerializerFactory)1 SerializerFactory (com.fasterxml.jackson.databind.ser.SerializerFactory)1 GargoyleConnectionFailException (com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException)1 ScriptRunner (com.linkedin.thirdeye.datalayer.ScriptRunner)1 FileReader (java.io.FileReader)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1