use of org.springframework.jdbc.core.PreparedStatementSetter in project spring-integration by spring-projects.
the class JdbcMessageStoreTests method testExpireMessageGroupOnCreateOnly.
@Test
public void testExpireMessageGroupOnCreateOnly() throws Exception {
final String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.addMessagesToGroup(groupId, message);
final CountDownLatch groupRemovalLatch = new CountDownLatch(1);
messageStore.registerMessageGroupExpiryCallback((messageGroupStore, group) -> {
messageGroupStore.removeMessageGroup(group.getGroupId());
groupRemovalLatch.countDown();
});
messageStore.expireMessageGroups(2000);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(1, group.size());
messageStore.addMessagesToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
JdbcTemplate template = new JdbcTemplate(this.dataSource);
template.afterPropertiesSet();
template.update("UPDATE INT_MESSAGE_GROUP set CREATED_DATE=? where GROUP_KEY=? and REGION=?", (PreparedStatementSetter) ps -> {
ps.setTimestamp(1, new Timestamp(System.currentTimeMillis() - 10000));
ps.setString(2, UUIDConverter.getUUID(groupId).toString());
ps.setString(3, "DEFAULT");
});
messageStore.expireMessageGroups(2000);
group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertTrue(groupRemovalLatch.await(10, TimeUnit.SECONDS));
}
use of org.springframework.jdbc.core.PreparedStatementSetter in project musiccabinet by hakko.
the class JdbcTagDao method setTopTags.
@Override
public void setTopTags(final List<String> topTags) {
assert (topTags != null && topTags.size() > 0);
jdbcTemplate.update("truncate library.toptag");
String sql = "insert into library.toptag (tag_id)" + " select id from music.tag where tag_name in (" + getParameters(topTags.size()) + ")";
jdbcTemplate.update(sql, new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps) throws SQLException {
int index = 1;
for (String topTag : topTags) {
ps.setString(index++, topTag);
}
}
});
}
use of org.springframework.jdbc.core.PreparedStatementSetter in project dhis2-core by dhis2.
the class HibernateDataStatisticsEventStore method getDataStatisticsEventCount.
@Override
public Map<DataStatisticsEventType, Double> getDataStatisticsEventCount(Date startDate, Date endDate) {
Map<DataStatisticsEventType, Double> eventTypeCountMap = new HashMap<>();
final String sql = "select eventtype as eventtype, count(eventtype) as numberofviews " + "from datastatisticsevent " + "where timestamp between ? and ? " + "group by eventtype;";
PreparedStatementSetter pss = (ps) -> {
int i = 1;
ps.setDate(i++, asSqlDate(startDate));
ps.setDate(i++, asSqlDate(endDate));
};
jdbcTemplate.query(sql, pss, (rs, i) -> {
eventTypeCountMap.put(DataStatisticsEventType.valueOf(rs.getString("eventtype")), rs.getDouble("numberofviews"));
return eventTypeCountMap;
});
final String totalSql = "select count(eventtype) as total " + "from datastatisticsevent " + "where timestamp between ? and ?;";
jdbcTemplate.query(totalSql, pss, (resultSet, i) -> {
return eventTypeCountMap.put(DataStatisticsEventType.TOTAL_VIEW, resultSet.getDouble("total"));
});
return eventTypeCountMap;
}
use of org.springframework.jdbc.core.PreparedStatementSetter in project dhis2-core by dhis2.
the class HibernateDataStatisticsEventStore method getFavoritesData.
@Override
public List<FavoriteStatistics> getFavoritesData(DataStatisticsEventType eventType, int pageSize, SortOrder sortOrder, String username) {
Assert.notNull(eventType, "Data statistics event type cannot be null");
Assert.notNull(sortOrder, "Sort order cannot be null");
String sql = "select c.uid, views, c.name, c.created from ( " + "select favoriteuid as uid, count(favoriteuid) as views " + "from datastatisticsevent where eventtype = '" + eventType.name() + "' ";
if (username != null) {
sql += "and username = ? ";
}
sql += "group by uid) as events " + "inner join " + escapeSql(eventType.getTable()) + " c on c.uid = events.uid " + "order by events.views " + escapeSql(sortOrder.getValue()) + " " + "limit ?;";
PreparedStatementSetter pss = (ps) -> {
int i = 1;
if (username != null) {
ps.setString(i++, username);
}
ps.setInt(i++, pageSize);
};
return jdbcTemplate.query(sql, pss, (rs, i) -> {
FavoriteStatistics stats = new FavoriteStatistics();
stats.setPosition(i + 1);
stats.setId(rs.getString("uid"));
stats.setName(rs.getString("name"));
stats.setCreated(rs.getDate("created"));
stats.setViews(rs.getInt("views"));
return stats;
});
}
use of org.springframework.jdbc.core.PreparedStatementSetter in project spring-security by spring-projects.
the class JdbcOAuth2AuthorizedClientService method insertAuthorizedClient.
private void insertAuthorizedClient(OAuth2AuthorizedClient authorizedClient, Authentication principal) {
List<SqlParameterValue> parameters = this.authorizedClientParametersMapper.apply(new OAuth2AuthorizedClientHolder(authorizedClient, principal));
try (LobCreator lobCreator = this.lobHandler.getLobCreator()) {
PreparedStatementSetter pss = new LobCreatorArgumentPreparedStatementSetter(lobCreator, parameters.toArray());
this.jdbcOperations.update(SAVE_AUTHORIZED_CLIENT_SQL, pss);
}
}
Aggregations