diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-07-18 11:10:08 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-07-18 13:15:50 +0200 |
commit | 7cdbfc9e015093f8f2c58b43a106e6b347728bcf (patch) | |
tree | 1166f01640b49d9d142f7575fb1e27f60173401b /sonar-db/src/main | |
parent | 0dff22bda049bcb3f5fa8cb0bcb5d9ea8a80fe8c (diff) | |
download | sonarqube-7cdbfc9e015093f8f2c58b43a106e6b347728bcf.tar.gz sonarqube-7cdbfc9e015093f8f2c58b43a106e6b347728bcf.zip |
Fix Quality flaws
Diffstat (limited to 'sonar-db/src/main')
5 files changed, 28 insertions, 58 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/dialect/DialectUtils.java b/sonar-db/src/main/java/org/sonar/db/dialect/DialectUtils.java index dba39b9efe1..70d893afe43 100644 --- a/sonar-db/src/main/java/org/sonar/db/dialect/DialectUtils.java +++ b/sonar-db/src/main/java/org/sonar/db/dialect/DialectUtils.java @@ -23,7 +23,6 @@ import com.google.common.base.Predicate; import com.google.common.collect.Iterators; import java.util.NoSuchElementException; import javax.annotation.CheckForNull; -import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.utils.MessageException; @@ -45,22 +44,12 @@ public final class DialectUtils { @CheckForNull private static Dialect findByJdbcUrl(final String jdbcConnectionUrl) { - return findDialect(new Predicate<Dialect>() { - @Override - public boolean apply(@Nullable Dialect dialect) { - return dialect != null && dialect.matchesJdbcURL(StringUtils.trimToEmpty(jdbcConnectionUrl)); - } - }); + return findDialect(dialect -> dialect != null && dialect.matchesJdbcURL(StringUtils.trimToEmpty(jdbcConnectionUrl))); } @CheckForNull private static Dialect findById(final String dialectId) { - return findDialect(new Predicate<Dialect>() { - @Override - public boolean apply(@Nullable Dialect dialect) { - return dialect != null && dialect.getId().equals(dialectId); - } - }); + return findDialect(dialect -> dialect != null && dialect.getId().equals(dialectId)); } @CheckForNull diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeProfiler.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeProfiler.java index d0945ed8312..4ebfb3a81d0 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeProfiler.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeProfiler.java @@ -22,7 +22,6 @@ package org.sonar.db.purge; import com.google.common.annotations.VisibleForTesting; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -67,12 +66,7 @@ public class PurgeProfiler { public void dump(long totalTime, Logger logger) { List<Entry<String, Long>> data = new ArrayList<>(durations.entrySet()); - Collections.sort(data, new Comparator<Entry<String, Long>>() { - @Override - public int compare(Entry<String, Long> o1, Entry<String, Long> o2) { - return o2.getValue().compareTo(o1.getValue()); - } - }); + Collections.sort(data, (o1, o2) -> o2.getValue().compareTo(o1.getValue())); double percent = totalTime / 100.0; for (Entry<String, Long> entry : truncateList(data)) { StringBuilder sb = new StringBuilder(); diff --git a/sonar-db/src/main/java/org/sonar/db/version/v451/DeleteUnescapedActivities.java b/sonar-db/src/main/java/org/sonar/db/version/v451/DeleteUnescapedActivities.java index ec4e28b246a..ee49d09e644 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v451/DeleteUnescapedActivities.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v451/DeleteUnescapedActivities.java @@ -25,8 +25,6 @@ import org.apache.commons.lang.StringUtils; import org.sonar.db.Database; import org.sonar.db.version.BaseDataChange; import org.sonar.db.version.MassUpdate; -import org.sonar.db.version.Select; -import org.sonar.db.version.SqlStatement; /** * See http://jira.sonarsource.com/browse/SONAR-5758 @@ -44,16 +42,13 @@ public class DeleteUnescapedActivities extends BaseDataChange { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select id,data_field from activities where log_type='QPROFILE'"); massUpdate.update("delete from activities where id=?"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - String csv = row.getNullableString(2); - if (isUnescaped(csv)) { - update.setLong(1, row.getNullableLong(1)); - return true; - } - return false; + massUpdate.execute((row, update) -> { + String csv = row.getNullableString(2); + if (isUnescaped(csv)) { + update.setLong(1, row.getNullableLong(1)); + return true; } + return false; }); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java b/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java index bf45c9ee424..3827ac1e720 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java @@ -238,12 +238,9 @@ public class FeedFileSources extends BaseDataChange { @Override public void execute(Context context) throws SQLException { - RowReader<Long> simpleLongReader = new RowReader<Long>() { - @Override - public Long read(Row row) throws SQLException { - Long longValue = row.getNullableLong(1); - return longValue == null ? Long.valueOf(0L) : longValue; - } + RowReader<Long> simpleLongReader = row -> { + Long longValue = row.getNullableLong(1); + return longValue == null ? Long.valueOf(0L) : longValue; }; Long revisionMetricId = context.prepareSelect("SELECT id FROM metrics WHERE name = 'revisions_by_line'").get(simpleLongReader); Long authorMetricId = context.prepareSelect("SELECT id FROM metrics WHERE name = 'authors_by_line'").get(simpleLongReader); @@ -287,6 +284,6 @@ public class FeedFileSources extends BaseDataChange { } private static long zeroIfNull(@Nullable Long value) { - return value == null ? 0L : value.longValue(); + return value == null ? 0L : value; } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v50/FeedIssueLongDates.java b/sonar-db/src/main/java/org/sonar/db/version/v50/FeedIssueLongDates.java index e08fb395aae..c677eab27b8 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v50/FeedIssueLongDates.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v50/FeedIssueLongDates.java @@ -25,8 +25,6 @@ import org.sonar.api.utils.System2; import org.sonar.db.Database; import org.sonar.db.version.BaseDataChange; import org.sonar.db.version.MassUpdate; -import org.sonar.db.version.Select; -import org.sonar.db.version.SqlStatement; public class FeedIssueLongDates extends BaseDataChange { @@ -45,26 +43,23 @@ public class FeedIssueLongDates extends BaseDataChange { massUpdate.select("SELECT i.id, i.created_at, i.updated_at FROM issues i WHERE created_at_ms IS NULL"); massUpdate.update("UPDATE issues SET created_at_ms=?, updated_at_ms=? WHERE id=?"); massUpdate.rowPluralName("issues"); - massUpdate.execute(new MassUpdate.Handler() { - @Override - public boolean handle(Select.Row row, SqlStatement update) throws SQLException { - Long id = row.getNullableLong(1); - Date createdAt = row.getNullableDate(2); - Date updatedAt = row.getNullableDate(3); + massUpdate.execute((row, update) -> { + Long id = row.getNullableLong(1); + Date createdAt = row.getNullableDate(2); + Date updatedAt = row.getNullableDate(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; + 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; }); } |