List of usage examples for org.springframework.jdbc.core PreparedStatementSetter PreparedStatementSetter
PreparedStatementSetter
From source file:org.springframework.security.provisioning.JdbcUserDetailsManager.java
public void createGroup(final String groupName, final List<GrantedAuthority> authorities) { Assert.hasText(groupName, "groupName should have text"); Assert.notNull(authorities, "authorities cannot be null"); logger.debug("Creating new group '" + groupName + "' with authorities " + AuthorityUtils.authorityListToSet(authorities)); getJdbcTemplate().update(insertGroupSql, groupName); final int groupId = findGroupId(groupName); for (GrantedAuthority a : authorities) { final String authority = a.getAuthority(); getJdbcTemplate().update(insertGroupAuthoritySql, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, groupId);//from w ww.ja va 2 s .co m ps.setString(2, authority); } }); } }
From source file:org.springframework.security.provisioning.JdbcUserDetailsManager.java
public void deleteGroup(String groupName) { logger.debug("Deleting group '" + groupName + "'"); Assert.hasText(groupName, "groupName should have text"); final int id = findGroupId(groupName); PreparedStatementSetter groupIdPSS = new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, id);//from www. j a va 2 s . com } }; getJdbcTemplate().update(deleteGroupMembersSql, groupIdPSS); getJdbcTemplate().update(deleteGroupAuthoritiesSql, groupIdPSS); getJdbcTemplate().update(deleteGroupSql, groupIdPSS); }
From source file:org.springframework.security.provisioning.JdbcUserDetailsManager.java
public void addUserToGroup(final String username, final String groupName) { logger.debug("Adding user '" + username + "' to group '" + groupName + "'"); Assert.hasText(username, "username should have text"); Assert.hasText(groupName, "groupName should have text"); final int id = findGroupId(groupName); getJdbcTemplate().update(insertGroupMemberSql, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, id);//ww w . j a v a 2s . co m ps.setString(2, username); } }); userCache.removeUserFromCache(username); }
From source file:org.springframework.security.provisioning.JdbcUserDetailsManager.java
public void removeUserFromGroup(final String username, final String groupName) { logger.debug("Removing user '" + username + "' to group '" + groupName + "'"); Assert.hasText(username, "username should have text"); Assert.hasText(groupName, "groupName should have text"); final int id = findGroupId(groupName); getJdbcTemplate().update(deleteGroupMemberSql, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, id);/*from w w w . j a v a 2s . c o m*/ ps.setString(2, username); } }); userCache.removeUserFromCache(username); }
From source file:org.springframework.security.provisioning.JdbcUserDetailsManager.java
public void removeGroupAuthority(String groupName, final GrantedAuthority authority) { logger.debug("Removing authority '" + authority + "' from group '" + groupName + "'"); Assert.hasText(groupName, "groupName should have text"); Assert.notNull(authority, "authority cannot be null"); final int id = findGroupId(groupName); getJdbcTemplate().update(deleteGroupAuthoritySql, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, id);/* w ww . j a v a 2 s. c o m*/ ps.setString(2, authority.getAuthority()); } }); }
From source file:org.springframework.security.provisioning.JdbcUserDetailsManager.java
public void addGroupAuthority(final String groupName, final GrantedAuthority authority) { logger.debug("Adding authority '" + authority + "' to group '" + groupName + "'"); Assert.hasText(groupName, "groupName should have text"); Assert.notNull(authority, "authority cannot be null"); final int id = findGroupId(groupName); getJdbcTemplate().update(insertGroupAuthoritySql, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, id);// w w w . j a v a 2 s.co m ps.setString(2, authority.getAuthority()); } }); }
From source file:org.springframework.session.jdbc.JdbcOperationsSessionRepository.java
public void save(final JdbcSession session) { if (session.isNew()) { this.transactionOperations.execute(new TransactionCallbackWithoutResult() { protected void doInTransactionWithoutResult(TransactionStatus status) { JdbcOperationsSessionRepository.this.jdbcOperations.update( JdbcOperationsSessionRepository.this.createSessionQuery, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, session.getId()); ps.setLong(2, session.getCreationTime()); ps.setLong(3, session.getLastAccessedTime()); ps.setInt(4, session.getMaxInactiveIntervalInSeconds()); ps.setString(5, session.getPrincipalName()); }//from w w w . j a v a 2s . com }); if (!session.getAttributeNames().isEmpty()) { final List<String> attributeNames = new ArrayList<String>(session.getAttributeNames()); JdbcOperationsSessionRepository.this.jdbcOperations.batchUpdate( JdbcOperationsSessionRepository.this.createSessionAttributeQuery, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { String attributeName = attributeNames.get(i); ps.setString(1, session.getId()); ps.setString(2, attributeName); serialize(ps, 3, session.getAttribute(attributeName)); } public int getBatchSize() { return attributeNames.size(); } }); } } }); } else { this.transactionOperations.execute(new TransactionCallbackWithoutResult() { protected void doInTransactionWithoutResult(TransactionStatus status) { if (session.isChanged()) { JdbcOperationsSessionRepository.this.jdbcOperations.update( JdbcOperationsSessionRepository.this.updateSessionQuery, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setLong(1, session.getLastAccessedTime()); ps.setInt(2, session.getMaxInactiveIntervalInSeconds()); ps.setString(3, session.getPrincipalName()); ps.setString(4, session.getId()); } }); } Map<String, Object> delta = session.getDelta(); if (!delta.isEmpty()) { for (final Map.Entry<String, Object> entry : delta.entrySet()) { if (entry.getValue() == null) { JdbcOperationsSessionRepository.this.jdbcOperations.update( JdbcOperationsSessionRepository.this.deleteSessionAttributeQuery, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, session.getId()); ps.setString(2, entry.getKey()); } }); } else { int updatedCount = JdbcOperationsSessionRepository.this.jdbcOperations.update( JdbcOperationsSessionRepository.this.updateSessionAttributeQuery, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { serialize(ps, 1, entry.getValue()); ps.setString(2, session.getId()); ps.setString(3, entry.getKey()); } }); if (updatedCount == 0) { JdbcOperationsSessionRepository.this.jdbcOperations.update( JdbcOperationsSessionRepository.this.createSessionAttributeQuery, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, session.getId()); ps.setString(2, entry.getKey()); serialize(ps, 3, entry.getValue()); } }); } } } } } }); } session.clearChangeFlags(); }
From source file:org.springframework.session.jdbc.JdbcOperationsSessionRepository.java
public JdbcSession getSession(final String id) { final ExpiringSession session = this.transactionOperations .execute(new TransactionCallback<ExpiringSession>() { public ExpiringSession doInTransaction(TransactionStatus status) { List<ExpiringSession> sessions = JdbcOperationsSessionRepository.this.jdbcOperations.query( JdbcOperationsSessionRepository.this.getSessionQuery, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, id); }/* w w w . j av a 2 s . c om*/ }, JdbcOperationsSessionRepository.this.extractor); if (sessions.isEmpty()) { return null; } return sessions.get(0); } }); if (session != null) { if (session.isExpired()) { delete(id); } else { return new JdbcSession(session); } } return null; }
From source file:org.springframework.session.jdbc.JdbcOperationsSessionRepository.java
public Map<String, JdbcSession> findByIndexNameAndIndexValue(String indexName, final String indexValue) { if (!PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) { return Collections.emptyMap(); }//w w w.j a v a2 s.co m List<ExpiringSession> sessions = this.transactionOperations .execute(new TransactionCallback<List<ExpiringSession>>() { public List<ExpiringSession> doInTransaction(TransactionStatus status) { return JdbcOperationsSessionRepository.this.jdbcOperations.query( JdbcOperationsSessionRepository.this.listSessionsByPrincipalNameQuery, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, indexValue); } }, JdbcOperationsSessionRepository.this.extractor); } }); Map<String, JdbcSession> sessionMap = new HashMap<String, JdbcSession>(sessions.size()); for (ExpiringSession session : sessions) { sessionMap.put(session.getId(), new JdbcSession(session)); } return sessionMap; }
From source file:xc.mst.repo.RepositoryDAO.java
public void activateLinkedRecords(String name, final TLongArrayList linkedToIds) { if (linkedToIds.size() > 0) { TimingLogger.start("activateHeldHoldings"); StringBuilder sb = new StringBuilder("update " + getTableName(name, RepositoryDAO.RECORDS_TABLE) + " set status='" + Record.ACTIVE + "'" + " where record_id in (select from_record_id from links where to_record_id in ("); for (int i = 0; i < linkedToIds.size(); i++) { sb.append("?"); if (i + 1 < linkedToIds.size()) { sb.append(", "); }/*from w w w . j a v a 2s . c o m*/ } sb.append("))"); LOG.debug("sb.toString(): " + sb.toString()); int updateCount = jdbcTemplate.update(sb.toString(), new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { for (int i = 0; i < linkedToIds.size(); i++) { ps.setLong(i + 1, linkedToIds.get(i)); } } }); TimingLogger.stop("activateHeldHoldings"); } else { LOG.debug("linkedToIds is null or empty"); } }