Skip to content

Commit 81c7af1

Browse files
PR feedback
1 parent 94f2948 commit 81c7af1

File tree

5 files changed

+17
-30
lines changed

5 files changed

+17
-30
lines changed

backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/storage/SonarLintDatabase.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.jooq.impl.DSL;
3333
import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger;
3434

35+
import static org.sonarsource.sonarlint.core.commons.storage.generated.Tables.AI_CODEFIX_SETTINGS;
36+
3537
public final class SonarLintDatabase {
3638
private static final SonarLintLogger LOG = SonarLintLogger.get();
3739

@@ -103,10 +105,10 @@ public void shutdown() {
103105
}
104106
}
105107

106-
public void cleanupNonExistingConnections(Set<String> connectionIds) {
107-
connectionIds.forEach(connectionId -> {
108-
// TODO: remove connection and related records from the database
109-
});
108+
public void cleanupNonExistingConnections(Set<String> existingConnectionIds) {
109+
dsl.deleteFrom(AI_CODEFIX_SETTINGS)
110+
.where(AI_CODEFIX_SETTINGS.CONNECTION_ID.notIn(existingConnectionIds))
111+
.execute();
110112
}
111113
}
112114

backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/storage/generated/tables/AiCodeFixSettingsTable.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626
package org.sonarsource.sonarlint.core.commons.storage.generated.tables;
2727

28-
import java.sql.Timestamp;
2928
import org.jooq.Record;
3029
import org.jooq.TableField;
3130
import org.jooq.impl.DSL;
@@ -37,13 +36,11 @@ public final class AiCodeFixSettingsTable extends TableImpl<Record> {
3736

3837
public static final AiCodeFixSettingsTable AI_CODEFIX_SETTINGS = new AiCodeFixSettingsTable();
3938

40-
public final TableField<Record, Integer> ID = createField(DSL.name("ID"), SQLDataType.INTEGER.nullable(false), this, "");
4139
public final TableField<Record, String> CONNECTION_ID = createField(DSL.name("CONNECTION_ID"), SQLDataType.VARCHAR.length(255), this, "");
4240
public final TableField<Record, String[]> SUPPORTED_RULES = createField(DSL.name("SUPPORTED_RULES"), SQLDataType.VARCHAR(64).getArrayDataType(), this, "");
4341
public final TableField<Record, Boolean> ORGANIZATION_ELIGIBLE = createField(DSL.name("ORGANIZATION_ELIGIBLE"), SQLDataType.BOOLEAN, this, "");
4442
public final TableField<Record, String> ENABLEMENT = createField(DSL.name("ENABLEMENT"), SQLDataType.VARCHAR.length(64), this, "");
4543
public final TableField<Record, String[]> ENABLED_PROJECT_KEYS = createField(DSL.name("ENABLED_PROJECT_KEYS"), SQLDataType.VARCHAR(400).getArrayDataType(), this, "");
46-
public final TableField<Record, Timestamp> UPDATED_AT = createField(DSL.name("UPDATED_AT"), SQLDataType.TIMESTAMP, this, "");
4744

4845
private AiCodeFixSettingsTable() {
4946
super(DSL.name("AI_CODEFIX_SETTINGS"));

backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/storage/repository/AiCodeFixRepository.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
*/
2020
package org.sonarsource.sonarlint.core.commons.storage.repository;
2121

22-
import java.sql.Timestamp;
23-
import java.time.Instant;
2422
import java.util.Optional;
2523
import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger;
2624
import org.sonarsource.sonarlint.core.commons.storage.SonarLintDatabase;
@@ -58,9 +56,6 @@ public Optional<AiCodeFix> get(String connectionId) {
5856
}
5957

6058
public void upsert(AiCodeFix entity) {
61-
var now = Timestamp.from(Instant.now());
62-
// use connection ID from Connection Table when it will be created
63-
int rowId = entity.connectionId().hashCode();
6459

6560
var dsl = database.dsl();
6661
try {
@@ -69,25 +64,20 @@ public void upsert(AiCodeFix entity) {
6964
.set(AI_CODEFIX_SETTINGS.ORGANIZATION_ELIGIBLE, entity.organizationEligible())
7065
.set(AI_CODEFIX_SETTINGS.ENABLEMENT, entity.enablement().name())
7166
.set(AI_CODEFIX_SETTINGS.ENABLED_PROJECT_KEYS, entity.enabledProjectKeys())
72-
.set(AI_CODEFIX_SETTINGS.UPDATED_AT, now)
7367
.where(AI_CODEFIX_SETTINGS.CONNECTION_ID.eq(entity.connectionId()))
7468
.execute();
7569
if (updated == 0) {
7670
dsl.insertInto(AI_CODEFIX_SETTINGS,
77-
AI_CODEFIX_SETTINGS.ID,
7871
AI_CODEFIX_SETTINGS.CONNECTION_ID,
7972
AI_CODEFIX_SETTINGS.SUPPORTED_RULES,
8073
AI_CODEFIX_SETTINGS.ORGANIZATION_ELIGIBLE,
8174
AI_CODEFIX_SETTINGS.ENABLEMENT,
82-
AI_CODEFIX_SETTINGS.ENABLED_PROJECT_KEYS,
83-
AI_CODEFIX_SETTINGS.UPDATED_AT)
84-
.values(rowId,
85-
entity.connectionId(),
75+
AI_CODEFIX_SETTINGS.ENABLED_PROJECT_KEYS)
76+
.values(entity.connectionId(),
8677
entity.supportedRules(),
8778
entity.organizationEligible(),
8879
entity.enablement().name(),
89-
entity.enabledProjectKeys(),
90-
now)
80+
entity.enabledProjectKeys())
9181
.execute();
9282
}
9383
} catch (RuntimeException ex) {
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
-- Flyway migration: create AI_CODEFIX_SETTINGS table for H2
22
-- Initial schema includes per-connection scoping via connection_id
33
CREATE TABLE IF NOT EXISTS AI_CODEFIX_SETTINGS (
4-
id INT NOT NULL,
5-
connection_id VARCHAR(255),
4+
connection_id VARCHAR(255) NOT NULL PRIMARY KEY,
65
supported_rules VARCHAR(200) ARRAY,
76
organization_eligible BOOLEAN,
87
enablement VARCHAR(64),
98
enabled_project_keys VARCHAR(400) ARRAY,
10-
updated_at TIMESTAMP,
11-
CONSTRAINT pk_ai_codefix_settings PRIMARY KEY (id)
9+
CONSTRAINT pk_ai_codefix_settings PRIMARY KEY (connection_id)
1210
);
1311

14-
-- Index to speed up lookups by connection_id
15-
CREATE INDEX IF NOT EXISTS idx_ai_codefix_settings_connection_id
16-
ON AI_CODEFIX_SETTINGS (connection_id);
17-
1812

backend/core/src/main/java/org/sonarsource/sonarlint/core/storage/SonarLintDatabaseService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
import jakarta.annotation.PreDestroy;
2424
import org.sonarsource.sonarlint.core.commons.storage.SonarLintDatabase;
2525
import org.sonarsource.sonarlint.core.repository.connection.ConnectionConfigurationRepository;
26+
import org.springframework.context.annotation.Lazy;
27+
import org.springframework.stereotype.Component;
2628

29+
@Component
30+
@Lazy(false)
2731
public class SonarLintDatabaseService {
2832

2933
private final SonarLintDatabase database;
@@ -40,8 +44,8 @@ public SonarLintDatabase getDatabase() {
4044

4145
@PostConstruct
4246
public void postConstruct() {
43-
var connectionIds = connectionConfigurationRepository.getConnectionsById().keySet();
44-
database.cleanupNonExistingConnections(connectionIds);
47+
var existingConnectionIds = connectionConfigurationRepository.getConnectionsById().keySet();
48+
database.cleanupNonExistingConnections(existingConnectionIds);
4549
}
4650

4751
@PreDestroy

0 commit comments

Comments
 (0)