Search in sources :

Example 6 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project Gargoyle by callakrsos.

the class DbUtil method getTransactionedScope.

public static <T> int getTransactionedScope(DataSource dataSource, T userObj, BiTransactionScope<T, NamedParameterJdbcTemplate> consumer, Consumer<Exception> exceptionHandler) {
    //		DataSource dataSource = null;
    try {
        //			dataSource = getDataSource();
        NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
        TransactionTemplate template = new TransactionTemplate();
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
        template.setTransactionManager(transactionManager);
        return template.execute(status -> {
            int result = -1;
            try {
                result = consumer.scope(userObj, namedParameterJdbcTemplate);
            } catch (Exception e) {
                status.setRollbackOnly();
                LOGGER.error(ValueUtil.toString(e));
                if (exceptionHandler != null)
                    exceptionHandler.accept(e);
                result = -1;
            }
            return result;
        });
    } catch (Exception e) {
        exceptionHandler.accept(e);
    } finally {
        try {
            close(dataSource);
        } catch (Exception e) {
        }
    }
    return -1;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager) SQLException(java.sql.SQLException) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) NotSupportException(com.kyj.fx.voeditor.visual.exceptions.NotSupportException)

Example 7 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate 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 8 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project camel by apache.

the class ElsqlComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    DataSource target = null;
    // endpoint options overrule component configured datasource
    DataSource ds = resolveAndRemoveReferenceParameter(parameters, "dataSource", DataSource.class);
    if (ds != null) {
        target = ds;
    }
    String dataSourceRef = getAndRemoveParameter(parameters, "dataSourceRef", String.class);
    if (target == null && dataSourceRef != null) {
        target = CamelContextHelper.mandatoryLookup(getCamelContext(), dataSourceRef, DataSource.class);
    }
    if (target == null) {
        // fallback and use component
        target = getDataSource();
    }
    if (target == null) {
        throw new IllegalArgumentException("DataSource must be configured");
    }
    NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(target);
    IntrospectionSupport.setProperties(jdbcTemplate, parameters, "template.");
    String elsqlName = remaining;
    String resUri = resourceUri;
    String[] part = remaining.split(":");
    if (part.length == 2) {
        elsqlName = part[0];
        resUri = part[1];
    } else if (part.length > 2) {
        throw new IllegalArgumentException("Invalid uri. Must by elsql:elsqlName:resourceUri, was: " + uri);
    }
    String onConsume = getAndRemoveParameter(parameters, "consumer.onConsume", String.class);
    if (onConsume == null) {
        onConsume = getAndRemoveParameter(parameters, "onConsume", String.class);
    }
    String onConsumeFailed = getAndRemoveParameter(parameters, "consumer.onConsumeFailed", String.class);
    if (onConsumeFailed == null) {
        onConsumeFailed = getAndRemoveParameter(parameters, "onConsumeFailed", String.class);
    }
    String onConsumeBatchComplete = getAndRemoveParameter(parameters, "consumer.onConsumeBatchComplete", String.class);
    if (onConsumeBatchComplete == null) {
        onConsumeBatchComplete = getAndRemoveParameter(parameters, "onConsumeBatchComplete", String.class);
    }
    ElsqlEndpoint endpoint = new ElsqlEndpoint(uri, this, jdbcTemplate, target, elsqlName, resUri);
    endpoint.setElSqlConfig(elSqlConfig);
    endpoint.setDatabaseVendor(databaseVendor);
    endpoint.setDataSource(target);
    endpoint.setDataSourceRef(dataSourceRef);
    endpoint.setOnConsume(onConsume);
    endpoint.setOnConsumeFailed(onConsumeFailed);
    endpoint.setOnConsumeBatchComplete(onConsumeBatchComplete);
    return endpoint;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) DataSource(javax.sql.DataSource)

Example 9 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project uPortal by Jasig.

the class JdbcAuthDao method setJdbcOperations.

public void setJdbcOperations(JdbcOperations jdbcOperations) {
    this.jdbcOperations = jdbcOperations;
    this.namedParameterJdbcOperations = new NamedParameterJdbcTemplate(this.jdbcOperations);
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 10 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project bamboobsc by billchen198318.

the class CleanJasperReportTempDataForContextInitAndDestroy method clean.

private void clean() throws Exception {
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate) AppContext.getBean("namedParameterJdbcTemplate");
    Map<String, Object> paramMap = new HashMap<String, Object>();
    namedParameterJdbcTemplate.update("delete from bb_swot_report_mst", paramMap);
    namedParameterJdbcTemplate.update("delete from bb_swot_report_dtl", paramMap);
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) HashMap(java.util.HashMap)

Aggregations

NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)12 HashMap (java.util.HashMap)5 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)3 NotSupportException (com.kyj.fx.voeditor.visual.exceptions.NotSupportException)3 SQLException (java.sql.SQLException)3 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)2 Date (java.util.Date)2 DataSourceConfVO (com.netsteadfast.greenstep.vo.DataSourceConfVO)1 DataSourceDriverVO (com.netsteadfast.greenstep.vo.DataSourceDriverVO)1 SysVO (com.netsteadfast.greenstep.vo.SysVO)1 DataSource (javax.sql.DataSource)1 DataSource (org.apache.tomcat.jdbc.pool.DataSource)1 JobExecutionException (org.quartz.JobExecutionException)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 DataSourceTransactionManager (org.springframework.jdbc.datasource.DataSourceTransactionManager)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1