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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations