@Override
public void execute(Context context) throws SQLException {
- final long now = system.now();
-
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("SELECT u.id, u.created_at, u.updated_at FROM users u WHERE created_at_ms IS NULL");
massUpdate.update("UPDATE users SET created_at_ms=?, updated_at_ms=? WHERE id=?");
massUpdate.rowPluralName("users");
- massUpdate.execute(new MassUpdate.Handler() {
- @Override
- public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
- Long id = row.getLong(1);
- Date createdAt = row.getDate(2);
- Date updatedAt = row.getDate(3);
+ massUpdate.execute(new RowHandler(system.now()));
+ }
+
+ private static class RowHandler implements MassUpdate.Handler {
+
+ private final long now;
- if (createdAt == null) {
- update.setLong(1, now);
- } else {
- update.setLong(1, Math.min(now, createdAt.getTime()));
- }
- if (updatedAt == null) {
- update.setLong(2, now);
- } else {
- update.setLong(2, Math.min(now, updatedAt.getTime()));
- }
- update.setLong(3, id);
- return true;
+ private RowHandler(long now) {
+ this.now = now;
+ }
+
+ @Override
+ public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+ Long id = row.getLong(1);
+ Date createdAt = row.getDate(2);
+ Date updatedAt = row.getDate(3);
+
+ if (createdAt == null) {
+ update.setLong(1, now);
+ } else {
+ update.setLong(1, Math.min(now, createdAt.getTime()));
+ }
+ if (updatedAt == null) {
+ update.setLong(2, now);
+ } else {
+ update.setLong(2, Math.min(now, updatedAt.getTime()));
}
- });
+ update.setLong(3, id);
+ return true;
+ }
}
}
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
-import java.io.Serializable;
import java.io.StringReader;
import java.util.Collections;
import java.util.Comparator;
}
@VisibleForTesting
- static class DuplicationComparator implements Comparator<Duplication>, Serializable {
+ static class DuplicationComparator implements Comparator<Duplication> {
private final ComponentDto component;
}
}
- private static class BlockComparator implements Comparator<Block>, Serializable {
+ private static class BlockComparator implements Comparator<Block> {
@Override
public int compare(@Nullable Block b1,
@Nullable Block b2) {
});
String val = "('" + Joiner.on("', '").skipNulls().join(alertLevelsUppercase) + "')";
Metric metric = metricFinder.findByKey(CoreMetrics.ALERT_STATUS_KEY);
- MeasureFilterCondition.Operator operator = MeasureFilterCondition.Operator.fromCode("in");
- return new MeasureFilterCondition(metric, operator, val);
+ if (metric != null) {
+ MeasureFilterCondition.Operator operator = MeasureFilterCondition.Operator.fromCode("in");
+ return new MeasureFilterCondition(metric, operator, val);
+ }
+ return null;
}
private List<String> toList(@Nullable Object obj) {
.setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION))
.setSeverity(request.mandatoryParam(PARAM_SEVERITY))
.setStatus(RuleStatus.valueOf(request.mandatoryParam(PARAM_STATUS)))
- .setPreventReactivation(request.paramAsBoolean(PARAM_PREVENT_REACTIVATION));
+ .setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION));
String params = request.param(PARAMS);
if (!Strings.isNullOrEmpty(params)) {
newRule.setParameters(KeyValueFormat.parse(params));
.setName(request.mandatoryParam(PARAM_NAME))
.setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION))
.setSeverity(request.param(PARAM_SEVERITY))
- .setPreventReactivation(request.paramAsBoolean(PARAM_PREVENT_REACTIVATION));
+ .setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION));
writeResponse(response, service.create(newRule));
}
} catch (ReactivationException e) {