use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project libresonic by Libresonic.
the class AbstractDao method namedQueryWithLimit.
protected <T> List<T> namedQueryWithLimit(String sql, RowMapper<T> rowMapper, Map<String, Object> args, int limit) {
long t = System.nanoTime();
JdbcTemplate jdbcTemplate = new JdbcTemplate(daoHelper.getDataSource());
jdbcTemplate.setMaxRows(limit);
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
List<T> result = namedTemplate.query(sql, args, rowMapper);
log(sql, t);
return result;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project bamboobsc by billchen198318.
the class ClearTempDataJobImpl method executeInternal.
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
if (ContextLoader.getCurrentWebApplicationContext() == null) {
log.warn("ApplicationContext no completed, AppContext.getApplicationContext() == null");
return;
}
log.info("begin....");
try {
/**
* document reference:
* com.netsteadfast.greenstep.support.CleanTempUploadForContextInitAndDestroy.java
*/
this.loginForBackgroundProgram();
List<SysVO> systems = ApplicationSiteUtils.getSystems();
if (systems == null || systems.size() < 1) {
return;
}
for (SysVO sys : systems) {
UploadSupportUtils.cleanTempUpload(sys.getSysId());
}
/**
* document reference:
* com.netsteadfast.greenstep.bsc.support.CleanJasperReportTempDataForContextInitAndDestroy.java
*
*/
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);
} catch (ServiceException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
this.logoutForBackgroundProgram();
} catch (Exception e) {
e.printStackTrace();
}
}
log.info("end....");
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project bamboobsc by billchen198318.
the class SysEventLogSupport method log.
public static void log(String userId, String sysId, String executeEventId, boolean permit) {
if (StringUtils.isBlank(userId) || StringUtils.isBlank(sysId) || StringUtils.isBlank(executeEventId)) {
log.warn("null userId=" + userId + ", sysId=" + sysId + ", executeEventId=" + executeEventId);
return;
}
if (executeEventId.indexOf(Constants._COMMON_LOAD_FORM_ACTION) > -1) {
log.warn("Common load form no need event log : " + executeEventId + " , permit = " + permit);
return;
}
NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate) AppContext.getBean("namedParameterJdbcTemplate");
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("oid", SimpleUtils.getUUIDStr());
paramMap.put("user", userId);
paramMap.put("sysId", sysId);
paramMap.put("executeEvent", (executeEventId.length() > 255 ? executeEventId.substring(0, 255) : executeEventId));
paramMap.put("isPermit", (permit ? "Y" : "N"));
paramMap.put("cuserid", "SYS");
paramMap.put("cdate", new Date());
try {
namedParameterJdbcTemplate.update("insert into tb_sys_event_log(OID, USER, SYS_ID, EXECUTE_EVENT, IS_PERMIT, CUSERID, CDATE) " + "values(:oid, :user, :sysId, :executeEvent, :isPermit, :cuserid, :cdate)", paramMap);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage().toString());
}
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project bamboobsc by billchen198318.
the class SysLoginLogSupport method log.
public static void log(String userId) {
if (StringUtils.isBlank(userId)) {
log.warn("null userId");
return;
}
NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate) AppContext.getBean("namedParameterJdbcTemplate");
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("oid", SimpleUtils.getUUIDStr());
paramMap.put("user", userId);
paramMap.put("cuserid", "SYS");
paramMap.put("cdate", new Date());
try {
namedParameterJdbcTemplate.update("insert into tb_sys_login_log(OID, USER, CUSERID, CDATE) values(:oid, :user, :cuserid, :cdate)", paramMap);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage().toString());
}
}
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;
}
Aggregations