use of org.springframework.jdbc.core.PreparedStatementSetter in project spring-security-oauth by spring-projects.
the class JdbcApprovalStore method updateApproval.
private boolean updateApproval(final String sql, final Approval approval) {
logger.debug(String.format("refreshing approval: [%s]", approval));
int refreshed = jdbcTemplate.update(sql, new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps) throws SQLException {
ps.setTimestamp(1, new Timestamp(approval.getExpiresAt().getTime()));
ps.setString(2, (approval.getStatus() == null ? APPROVED : approval.getStatus()).toString());
ps.setTimestamp(3, new Timestamp(approval.getLastUpdatedAt().getTime()));
ps.setString(4, approval.getUserId());
ps.setString(5, approval.getClientId());
ps.setString(6, approval.getScope());
}
});
if (refreshed != 1) {
return false;
}
return true;
}
use of org.springframework.jdbc.core.PreparedStatementSetter in project buffer-slayer by tramchamploo.
the class BatchJdbcTemplate method update.
public MessageFuture<Integer> update(PreparedStatementCreator psc) throws DataAccessException {
if (psc instanceof SqlProvider) {
SqlProvider sqlProvider = (SqlProvider) psc;
String sql = sqlProvider.getSql();
Builder builder = Sql.builder().sql(sql);
if (psc instanceof PreparedStatementSetter) {
PreparedStatementSetter pss = (PreparedStatementSetter) psc;
builder.preparedStatementSetter(pss);
}
return reporter.report(builder.build());
}
throw new UnsupportedOperationException("Must be instance of SqlProvider");
}
use of org.springframework.jdbc.core.PreparedStatementSetter in project spring-security by spring-projects.
the class JdbcOAuth2AuthorizedClientService method updateAuthorizedClient.
private void updateAuthorizedClient(OAuth2AuthorizedClient authorizedClient, Authentication principal) {
List<SqlParameterValue> parameters = this.authorizedClientParametersMapper.apply(new OAuth2AuthorizedClientHolder(authorizedClient, principal));
SqlParameterValue clientRegistrationIdParameter = parameters.remove(0);
SqlParameterValue principalNameParameter = parameters.remove(0);
parameters.add(clientRegistrationIdParameter);
parameters.add(principalNameParameter);
try (LobCreator lobCreator = this.lobHandler.getLobCreator()) {
PreparedStatementSetter pss = new LobCreatorArgumentPreparedStatementSetter(lobCreator, parameters.toArray());
this.jdbcOperations.update(UPDATE_AUTHORIZED_CLIENT_SQL, pss);
}
}
use of org.springframework.jdbc.core.PreparedStatementSetter in project spring-security by spring-projects.
the class JdbcUserDetailsManager method deleteGroup.
@Override
public void deleteGroup(String groupName) {
this.logger.debug("Deleting group '" + groupName + "'");
Assert.hasText(groupName, "groupName should have text");
int id = findGroupId(groupName);
PreparedStatementSetter groupIdPSS = (ps) -> ps.setInt(1, id);
getJdbcTemplate().update(this.deleteGroupMembersSql, groupIdPSS);
getJdbcTemplate().update(this.deleteGroupAuthoritiesSql, groupIdPSS);
getJdbcTemplate().update(this.deleteGroupSql, groupIdPSS);
}
use of org.springframework.jdbc.core.PreparedStatementSetter in project dhis2-core by dhis2.
the class JdbcDataAnalysisStore method getDeflatedDataValues.
private List<DeflatedDataValue> getDeflatedDataValues(DataElement dataElement, CategoryOptionCombo categoryOptionCombo, Collection<Period> periods, List<Long> organisationUnits, Map<Long, Integer> lowerBoundMap, Map<Long, Integer> upperBoundMap) {
String periodIds = TextUtils.getCommaDelimitedString(getIdentifiers(periods));
// @formatter:off
String sql = "select dv.dataelementid, dv.periodid, dv.sourceid, " + "dv.categoryoptioncomboid, dv.attributeoptioncomboid, dv.value, dv.storedby, dv.lastupdated, " + "dv.created, dv.comment, dv.followup, ou.name as sourcename, " + "? as dataelementname, pt.name as periodtypename, pe.startdate, pe.enddate, " + "? as categoryoptioncomboname " + "from datavalue dv " + "inner join period pe on dv.periodid = pe.periodid " + "inner join periodtype pt on pe.periodtypeid = pt.periodtypeid " + "inner join organisationunit ou on dv.sourceid = ou.organisationunitid " + "where dv.dataelementid = " + dataElement.getId() + " " + "and dv.categoryoptioncomboid = " + categoryOptionCombo.getId() + " " + "and dv.periodid in (" + periodIds + ") and (";
for (Long orgUnitUid : organisationUnits) {
sql += "(dv.sourceid = " + orgUnitUid + " " + "and (cast( dv.value as " + statementBuilder.getDoubleColumnType() + " ) < " + lowerBoundMap.get(orgUnitUid) + " " + "or cast(dv.value as " + statementBuilder.getDoubleColumnType() + ") > " + upperBoundMap.get(orgUnitUid) + ")) or ";
}
sql = TextUtils.removeLastOr(sql) + ") ";
sql += "and dv.deleted is false ";
PreparedStatementSetter pss = (ps) -> {
ps.setString(1, dataElement.getName());
ps.setString(2, categoryOptionCombo.getName());
};
return jdbcTemplate.query(sql, pss, new DeflatedDataValueNameMinMaxRowMapper(lowerBoundMap, upperBoundMap));
}
Aggregations