Search in sources :

Example 1 with NamedParameterJdbcTemplate

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;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 2 with NamedParameterJdbcTemplate

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....");
}
Also used : ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) HashMap(java.util.HashMap) SysVO(com.netsteadfast.greenstep.vo.SysVO) JobExecutionException(org.quartz.JobExecutionException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException)

Example 3 with NamedParameterJdbcTemplate

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());
    }
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) HashMap(java.util.HashMap) Date(java.util.Date)

Example 4 with NamedParameterJdbcTemplate

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());
    }
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) HashMap(java.util.HashMap) Date(java.util.Date)

Example 5 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)

Aggregations

NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)119 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)66 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)42 HashMap (java.util.HashMap)30 ResultSet (java.sql.ResultSet)16 SQLException (java.sql.SQLException)16 DbXref (org.nextprot.api.core.domain.DbXref)8 NextProtException (org.nextprot.api.commons.exception.NextProtException)7 PublicationDbXref (org.nextprot.api.core.domain.PublicationDbXref)7 ArrayList (java.util.ArrayList)5 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)5 List (java.util.List)4 Map (java.util.Map)4 CvTerm (org.nextprot.api.core.domain.CvTerm)4 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)3 NotSupportException (com.kyj.fx.voeditor.visual.exceptions.NotSupportException)3 DataSource (javax.sql.DataSource)3 UserProteinList (org.nextprot.api.user.domain.UserProteinList)3 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)2 Date (java.util.Date)2