Search in sources :

Example 6 with PreparedStatementSetter

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;
}
Also used : SQLException(java.sql.SQLException) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 7 with PreparedStatementSetter

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");
}
Also used : SqlProvider(org.springframework.jdbc.core.SqlProvider) Builder(io.github.tramchamploo.bufferslayer.Sql.Builder) BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) ParameterizedPreparedStatementSetter(org.springframework.jdbc.core.ParameterizedPreparedStatementSetter)

Example 8 with PreparedStatementSetter

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);
    }
}
Also used : SqlParameterValue(org.springframework.jdbc.core.SqlParameterValue) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) ArgumentPreparedStatementSetter(org.springframework.jdbc.core.ArgumentPreparedStatementSetter) LobCreator(org.springframework.jdbc.support.lob.LobCreator)

Example 9 with PreparedStatementSetter

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);
}
Also used : IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) ApplicationContextException(org.springframework.context.ApplicationContextException) LogMessage(org.springframework.core.log.LogMessage) UserCache(org.springframework.security.core.userdetails.UserCache) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DataSource(javax.sql.DataSource) UserDetails(org.springframework.security.core.userdetails.UserDetails) AuthenticationException(org.springframework.security.core.AuthenticationException) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) JdbcDaoImpl(org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl) Collection(java.util.Collection) AccessDeniedException(org.springframework.security.access.AccessDeniedException) GrantedAuthority(org.springframework.security.core.GrantedAuthority) NullUserCache(org.springframework.security.core.userdetails.cache.NullUserCache) List(java.util.List) SecurityContext(org.springframework.security.core.context.SecurityContext) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Authentication(org.springframework.security.core.Authentication) AuthorityUtils(org.springframework.security.core.authority.AuthorityUtils) Assert(org.springframework.util.Assert) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter)

Example 10 with PreparedStatementSetter

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));
}
Also used : IdentifiableObjectUtils.getIdentifiers(org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifiers) Date(java.util.Date) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) DataAnalysisStore(org.hisp.dhis.dataanalysis.DataAnalysisStore) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataElement(org.hisp.dhis.dataelement.DataElement) PaginatedList(org.hisp.dhis.commons.collection.PaginatedList) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) Repository(org.springframework.stereotype.Repository) TextUtils.getCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString) Period(org.hisp.dhis.period.Period) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) StatementBuilder(org.hisp.dhis.jdbc.StatementBuilder) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) DataAnalysisMeasures(org.hisp.dhis.dataanalysis.DataAnalysisMeasures) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DeflatedDataValueNameMinMaxRowMapper(org.hisp.dhis.system.objectmapper.DeflatedDataValueNameMinMaxRowMapper) DateUtils(org.hisp.dhis.util.DateUtils) TextUtils(org.hisp.dhis.commons.util.TextUtils) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) TextUtils.getCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString) DeflatedDataValueNameMinMaxRowMapper(org.hisp.dhis.system.objectmapper.DeflatedDataValueNameMinMaxRowMapper)

Aggregations

PreparedStatementSetter (org.springframework.jdbc.core.PreparedStatementSetter)22 SQLException (java.sql.SQLException)13 PreparedStatement (java.sql.PreparedStatement)12 List (java.util.List)5 Timestamp (java.sql.Timestamp)4 Date (java.util.Date)4 ArgumentPreparedStatementSetter (org.springframework.jdbc.core.ArgumentPreparedStatementSetter)4 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)3 Map (java.util.Map)3 SqlParameterValue (org.springframework.jdbc.core.SqlParameterValue)3 Lists (com.google.common.collect.Lists)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 DataSource (javax.sql.DataSource)2 SessionFactory (org.hibernate.SessionFactory)2 SortOrder (org.hisp.dhis.analytics.SortOrder)2 DataStatisticsEvent (org.hisp.dhis.datastatistics.DataStatisticsEvent)2