Example usage for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate

List of usage examples for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate

Introduction

In this page you can find the example usage for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate.

Prototype

public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate) 

Source Link

Document

Create a new NamedParameterJdbcTemplate for the given classic Spring org.springframework.jdbc.core.JdbcTemplate .

Usage

From source file:org.mskcc.cbio.portal.dao.internal.PortalUserJDBCDAO.java

/**
 * Constructor.//w  w  w. j a  v  a2  s . c  om
  *
  * Takes a datasource reference used to get user data.
  *
  * @param dataSource DataSource
 */
public PortalUserJDBCDAO(DataSource dataSource) {
    this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}

From source file:org.ojbc.adapters.analyticaldatastore.dao.AnalyticalDatastoreDAOImpl.java

public void setDataSource(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}

From source file:org.openengsb.core.edbi.jdbc.JdbcService.java

public NamedParameterJdbcTemplate jdbcn() {
    if (jdbcn == null) {
        jdbcn = new NamedParameterJdbcTemplate(dataSource);
    }

    return jdbcn;
}

From source file:org.openiot.security.oauth.OAuth20PermissionController.java

public OAuth20PermissionController(final ServicesManager servicesManager, final TicketRegistry ticketRegistry,
        DataSource dataSource) {/*from  w  w w  .  j av a  2s.  co m*/
    this.servicesManager = servicesManager;
    this.ticketRegistry = ticketRegistry;

    Set<String> userAttributeNames = new HashSet<String>();
    userAttributeNames.add("role_name");

    namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}

From source file:org.patientview.radar.dao.impl.BaseDaoImpl.java

public void setDataSource(DataSource dataSource) {
    jdbcTemplate = new JdbcTemplate(dataSource);
    namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}

From source file:org.paxml.tag.sql.SqlTag.java

protected Object executeSql(String sql, Context context) {

    return executeSql(sql, new ISqlExecutor() {
        @Override/*w ww  .  j a  va2  s  .co  m*/
        public Object update(final String sql) {
            if (param != null) {
                NamedParameterJdbcTemplate t = new NamedParameterJdbcTemplate(jdbcTemplate);
                return t.execute(sql, param, new PreparedStatementCallback<Void>() {

                    @Override
                    public Void doInPreparedStatement(PreparedStatement ps)
                            throws SQLException, DataAccessException {
                        ps.executeUpdate();
                        return null;
                    }

                });
            } else {
                jdbcTemplate.execute(sql);
            }
            return null;
        }

        @Override
        public Object query(String sql, boolean close) {
            if (param != null) {
                NamedParameterJdbcTemplate t = new NamedParameterJdbcTemplate(jdbcTemplate);
                return t.queryForList(sql, param);
            } else {
                return jdbcTemplate.queryForList(sql);
            }
        }

    });

}

From source file:org.paxml.tag.sql.SqlTag.java

private Object executeSql(String sql, ISqlExecutor exe) {

    Object result = null;/*from w w  w.  ja  v  a 2s.  co m*/
    List<String> sqlList;
    if (singleStatement) {
        sqlList = Arrays.asList(sql);
    } else {
        sqlList = DBUtils.breakSql(sql);
    }

    final int maxIndex = sqlList.size() - 1;
    for (int i = 0; i <= maxIndex; i++) {

        if (isQuery(sql)) {
            if (list) {
                if (log.isDebugEnabled()) {
                    log.debug("Running sql: " + sql);
                }
                try {
                    if (param != null) {
                        NamedParameterJdbcTemplate t = new NamedParameterJdbcTemplate(jdbcTemplate);
                        result = t.queryForList(sql, param);
                    } else {
                        result = jdbcTemplate.queryForList(sql);
                    }
                } catch (RuntimeException e) {
                    throw new PaxmlRuntimeException("Cannot execute sql: " + sql, e);
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Running sql: " + sqlList.get(i));
                }
                try {
                    result = exe.query(sqlList.get(i), true);
                } catch (RuntimeException e) {
                    throw new PaxmlRuntimeException("Cannot execute sql: " + sqlList.get(i), e);
                }
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Running sql: " + sqlList.get(i));
            }
            try {
                exe.update(sqlList.get(i));
            } catch (RuntimeException e) {
                throw new PaxmlRuntimeException("Cannot execute sql: " + sqlList.get(i), e);
            }
        }

    }
    return result;

}

From source file:org.pssframework.dao.BaseSpringJdbcDao.java

protected void checkDaoConfig() {
    super.checkDaoConfig();
    if (dialect == null)
        throw new IllegalStateException("'dialect' property must be not null");
    log.info("use jdbc dialect:" + dialect);
    simpleJdbcTemplate = new SimpleJdbcTemplate(getJdbcTemplate());
    namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate());
}

From source file:org.springframework.batch.item.database.JdbcBatchItemWriter.java

/**
 * Public setter for the data source for injection purposes.
 *
 * @param dataSource {@link javax.sql.DataSource} to use for querying against
 *///from  w  w w. j  a  va 2  s.c om
public void setDataSource(DataSource dataSource) {
    if (namedParameterJdbcTemplate == null) {
        this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    }
}

From source file:org.springframework.integration.jdbc.store.JdbcChannelMessageStore.java

/**
 * This method executes a call to the DB to get the oldest Message in the
 * MessageGroup which in the context of the {@link JdbcChannelMessageStore}
 * means the channel identifier./*from   w  w w. j  a  va 2  s.c  o  m*/
 *
 * @param groupIdKey String representation of message group (Channel) ID
 * @return a message; could be null if query produced no Messages
 */
protected Message<?> doPollForMessage(String groupIdKey) {

    final NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
    final MapSqlParameterSource parameters = new MapSqlParameterSource();

    parameters.addValue("region", region);
    parameters.addValue("group_key", groupIdKey);

    final String query;

    final List<Message<?>> messages;

    this.idCacheReadLock.lock();
    try {
        if (this.usingIdCache && !this.idCache.isEmpty()) {
            query = getQuery(this.channelMessageStoreQueryProvider.getPollFromGroupExcludeIdsQuery());
            parameters.addValue("message_ids", idCache);
        } else {
            query = getQuery(this.channelMessageStoreQueryProvider.getPollFromGroupQuery());
        }
        messages = namedParameterJdbcTemplate.query(query, parameters, messageRowMapper);
    } finally {
        this.idCacheReadLock.unlock();
    }

    Assert.isTrue(messages.size() == 0 || messages.size() == 1);
    if (messages.size() > 0) {

        final Message<?> message = messages.get(0);
        final String messageId = message.getHeaders().getId().toString();

        if (this.usingIdCache) {
            this.idCacheWriteLock.lock();
            try {
                boolean added = this.idCache.add(messageId);

                if (logger.isDebugEnabled()) {
                    logger.debug(String.format("Polled message with id '%s' added: '%s'.", messageId, added));
                }
            } finally {
                this.idCacheWriteLock.unlock();
            }
        }

        return message;
    }
    return null;
}