Example usage for org.springframework.jdbc.core JdbcTemplate update

List of usage examples for org.springframework.jdbc.core JdbcTemplate update

Introduction

In this page you can find the example usage for org.springframework.jdbc.core JdbcTemplate update.

Prototype

@Override
    public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException 

Source Link

Usage

From source file:no.kantega.publishing.common.ao.ContentAOJdbcImpl.java

/**
 * Set number of comments for content//  w w w  .  j a  v a  2  s .c o  m
 * @param contentId - ContentId
 * @param numberOfComments - numberOfComments
 */
public void setNumberOfComments(int contentId, int numberOfComments) {
    JdbcTemplate template = dbConnectionFactory.getJdbcTemplate();
    template.update("update content set NumberOfComments = ? where ContentId = ?", numberOfComments, contentId);
}

From source file:org.cloudfoundry.identity.uaa.oauth.token.UaaTokenStore.java

@Override
public String createAuthorizationCode(OAuth2Authentication authentication) {
    final int max_tries = 3;
    performExpirationClean();//from  w w w  .  ja  v a2  s  . c o  m
    JdbcTemplate template = new JdbcTemplate(dataSource);
    int tries = 0;
    while ((tries++) <= max_tries) {
        try {
            String code = generator.generate();
            long expiresAt = System.currentTimeMillis() + getExpirationTime();
            String userId = authentication.getUserAuthentication() == null ? null
                    : ((UaaPrincipal) authentication.getUserAuthentication().getPrincipal()).getId();
            String clientId = authentication.getOAuth2Request().getClientId();
            SqlLobValue data = new SqlLobValue(serializeOauth2Authentication(authentication));
            int updated = template.update(SQL_INSERT_STATEMENT,
                    new Object[] { code, userId, clientId, expiresAt, data },
                    new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.NUMERIC, Types.BLOB });
            if (updated == 0) {
                throw new DataIntegrityViolationException("[oauth_code] Failed to insert code. Result was 0");
            }
            return code;
        } catch (DataIntegrityViolationException exists) {
            if (tries >= max_tries)
                throw exists;
        }
    }
    return null;
}