return getMapper(dbSession).selectByComponentUuidAndKey(componentUuid, key);
}
- public int deleteByComponentUuidAndKey(DbSession dbSession, String componentUuid, String key) {
- return getMapper(dbSession).deleteByComponentUuidAndKey(componentUuid, key);
+ public int deleteByComponentUuid(DbSession dbSession, String componentUuid) {
+ return getMapper(dbSession).deleteByComponentUuidAndKey(componentUuid);
}
/**
void replaceValue(@Param("componentUuid") String componentUuid, @Param("key") String key, @Param("oldValue") String oldValue, @Param("newValue") String newValue,
@Param("updatedAt") Long updatedAt);
- int deleteByComponentUuidAndKey(@Param("componentUuid") String componentUuid, @Param("key") String key);
+ int deleteByComponentUuidAndKey(@Param("componentUuid") String componentUuid);
Set<String> selectDbKeys(@Param("key") String key, @Param("value") String value);
}
DELETE FROM internal_component_props
<where>
component_uuid = #{componentUuid, jdbcType=VARCHAR}
- AND kee = #{key, jdbcType=VARCHAR}
</where>
</delete>
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.permission.template.PermissionTemplateDbTester;
import org.sonar.db.plugin.PluginDbTester;
+import org.sonar.db.property.InternalComponentPropertyDbTester;
import org.sonar.db.property.PropertyDbTester;
import org.sonar.db.qualitygate.QualityGateDbTester;
import org.sonar.db.qualityprofile.QualityProfileDbTester;
private final WebhookDbTester webhookDbTester;
private final WebhookDeliveryDbTester webhookDeliveryDbTester;
private final AlmDbTester almDbTester;
+ private final InternalComponentPropertyDbTester internalComponentPropertyTester;
private DbTester(System2 system2, @Nullable String schemaPath, MyBatisConfExtension... confExtensions) {
super(TestDb.create(schemaPath, confExtensions));
this.webhookDbTester = new WebhookDbTester(this);
this.webhookDeliveryDbTester = new WebhookDeliveryDbTester(this);
this.almDbTester = new AlmDbTester(this);
+ this.internalComponentPropertyTester = new InternalComponentPropertyDbTester(this);
}
public static DbTester create() {
return almDbTester;
}
+ public InternalComponentPropertyDbTester internalComponentProperties() {
+ return internalComponentPropertyTester;
+ }
+
@Override
protected void after() {
if (session != null) {
}
@Test
- public void delete_by_component_uuid_and_key_deletes_property() {
- saveDto();
+ public void delete_by_component_uuid_deletes_all_properties_with_given_componentUuid() {
+ underTest.insertOrUpdate(dbSession, SOME_COMPONENT, SOME_KEY, SOME_VALUE);
+ underTest.insertOrUpdate(dbSession, SOME_COMPONENT, "other_key", "foo");
+ underTest.insertOrUpdate(dbSession, "other_component", SOME_KEY, SOME_VALUE);
- assertThat(underTest.deleteByComponentUuidAndKey(dbSession, SOME_COMPONENT, SOME_KEY)).isEqualTo(1);
+ assertThat(underTest.deleteByComponentUuid(dbSession, SOME_COMPONENT)).isEqualTo(2);
assertThat(underTest.selectByComponentUuidAndKey(dbSession, SOME_COMPONENT, SOME_KEY)).isEmpty();
+ assertThat(underTest.selectByComponentUuidAndKey(dbSession, "other_component", SOME_KEY)).isNotEmpty();
}
@Test
public void delete_by_component_uuid_and_key_does_nothing_if_property_doesnt_exist() {
saveDto();
- assertThat(underTest.deleteByComponentUuidAndKey(dbSession, SOME_COMPONENT, "other_key")).isEqualTo(0);
- assertThat(underTest.deleteByComponentUuidAndKey(dbSession, "other_component", SOME_KEY)).isEqualTo(0);
+ assertThat(underTest.deleteByComponentUuid(dbSession, "other_component")).isEqualTo(0);
assertThat(underTest.selectByComponentUuidAndKey(dbSession, SOME_COMPONENT, SOME_KEY)).isNotEmpty();
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.property;
+
+import java.util.Optional;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+
+public class InternalComponentPropertyDbTester {
+ private final DbTester db;
+ private final DbClient dbClient;
+ private final DbSession dbSession;
+
+ public InternalComponentPropertyDbTester(DbTester db) {
+ this.db = db;
+ this.dbClient = db.getDbClient();
+ this.dbSession = db.getSession();
+ }
+
+ public void insertProperty(String componentUuid, String key, String value) {
+ dbClient.internalComponentPropertiesDao().insertOrUpdate(dbSession, componentUuid, key, value);
+ db.commit();
+ }
+
+ public Optional<InternalComponentPropertyDto> getProperty(String componentUuid, String key) {
+ return dbClient.internalComponentPropertiesDao().selectByComponentUuidAndKey(dbSession, componentUuid, key);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.property;
+
+/**
+ * List of internal component property keys
+ */
+public class InternalComponentProperties {
+
+ public static final String PORTFOLIO_REFRESH_STATE = "portfolio.refresh.state";
+
+ private InternalComponentProperties() {
+ // Static constants only
+ }
+}