Skip to content

Commit

Permalink
SONAR-7676 PropertiesDao supports IS_EMPTY, TEXT_VALUE and CLOB_VALUE
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb committed Sep 9, 2016
1 parent b8c0bec commit 5265833
Show file tree
Hide file tree
Showing 66 changed files with 1,646 additions and 875 deletions.
Expand Up @@ -20,6 +20,7 @@
package org.sonar.ce.db;

import java.util.Map;
import org.sonar.api.utils.System2;
import org.sonar.core.properties.PropertiesDao;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
Expand All @@ -35,17 +36,17 @@
* </p>
*/
public class ReadOnlyPropertiesDao extends PropertiesDao {
public ReadOnlyPropertiesDao(MyBatis mybatis) {
super(mybatis);
public ReadOnlyPropertiesDao(MyBatis mybatis, System2 system2) {
super(mybatis, system2);
}

@Override
public void insertProperty(DbSession session, PropertyDto property) {
public void saveProperty(DbSession session, PropertyDto property) {
// do nothing
}

@Override
public void insertProperty(PropertyDto property) {
public void saveProperty(PropertyDto property) {
// do nothing
}

Expand Down Expand Up @@ -80,7 +81,7 @@ public void deleteGlobalProperty(String key) {
}

@Override
public void insertGlobalProperties(Map<String, String> properties) {
public void saveGlobalProperties(Map<String, String> properties) {
// do nothing
}

Expand Down
Expand Up @@ -121,7 +121,7 @@ public void real_start() throws IOException {

private void insertProperty(String key, String value) {
PropertyDto dto = new PropertyDto().setKey(key).setValue(value);
dbTester.getDbClient().propertiesDao().insertProperty(dbTester.getSession(), dto);
dbTester.getDbClient().propertiesDao().saveProperty(dbTester.getSession(), dto);
dbTester.commit();
}
}
Expand Up @@ -20,6 +20,7 @@
package org.sonar.ce.db;

import org.junit.Test;
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.property.PropertyDto;
Expand All @@ -32,18 +33,18 @@ public class ReadOnlyPropertiesDaoTest {
private DbSession dbSession = mock(DbSession.class);
private PropertyDto propertyDto = mock(PropertyDto.class);
private org.sonar.core.properties.PropertyDto oldPropertyDto = mock(org.sonar.core.properties.PropertyDto.class);
private ReadOnlyPropertiesDao underTest = new ReadOnlyPropertiesDao(myBatis);
private ReadOnlyPropertiesDao underTest = new ReadOnlyPropertiesDao(myBatis, System2.INSTANCE);

@Test
public void insertProperty() {
underTest.insertProperty(dbSession, propertyDto);
underTest.saveProperty(dbSession, propertyDto);

assertNoInteraction();
}

@Test
public void insertProperty1() {
underTest.insertProperty(propertyDto);
underTest.saveProperty(propertyDto);

assertNoInteraction();
}
Expand Down Expand Up @@ -98,7 +99,7 @@ public void deleteGlobalProperty1() {

@Test
public void insertGlobalProperties() {
underTest.insertGlobalProperties(null);
underTest.saveGlobalProperties(null);

assertNoInteraction();

Expand All @@ -112,12 +113,18 @@ public void renamePropertyKey() {

}

@Test
public void saveProperty() {
underTest.saveProperty(oldPropertyDto);

assertNoInteraction();
}

@Test
public void setProperty() {
underTest.setProperty(oldPropertyDto);

assertNoInteraction();

}

private void assertNoInteraction() {
Expand Down
Expand Up @@ -49,11 +49,7 @@ public String getString(String key) {
* are executed.
*/
public PersistentSettings saveProperty(DbSession dbSession, String key, @Nullable String value) {
if (value == null) {
dbClient.propertiesDao().deleteGlobalProperty(key, dbSession);
} else {
dbClient.propertiesDao().insertProperty(dbSession, new PropertyDto().setKey(key).setValue(value));
}
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(value));
// refresh the cache of settings
delegate.setProperty(key, value);

Expand Down
Expand Up @@ -55,7 +55,7 @@ public void start() {
}

private void save(String key, String value) {
dbClient.propertiesDao().insertProperty(new PropertyDto().setKey(key).setValue(value));
dbClient.propertiesDao().saveProperty(new PropertyDto().setKey(key).setValue(value));
}

@Override
Expand Down
Expand Up @@ -154,7 +154,7 @@ public void setDefault(@Nullable Long idToUseAsDefault) {
propertiesDao.deleteGlobalProperty(SONAR_QUALITYGATE_PROPERTY);
} else {
QualityGateDto newDefault = getNonNullQgate(idToUseAsDefault);
propertiesDao.insertProperty(new PropertyDto().setKey(SONAR_QUALITYGATE_PROPERTY).setValue(newDefault.getId().toString()));
propertiesDao.saveProperty(new PropertyDto().setKey(SONAR_QUALITYGATE_PROPERTY).setValue(newDefault.getId().toString()));
}
}

Expand Down Expand Up @@ -225,7 +225,7 @@ public void associateProject(Long qGateId, Long projectId) {
try {
getNonNullQgate(qGateId);
checkPermission(projectId, session);
propertiesDao.insertProperty(new PropertyDto().setKey(SONAR_QUALITYGATE_PROPERTY).setResourceId(projectId).setValue(qGateId.toString()));
propertiesDao.saveProperty(new PropertyDto().setKey(SONAR_QUALITYGATE_PROPERTY).setResourceId(projectId).setValue(qGateId.toString()));
} finally {
MyBatis.closeQuietly(session);
}
Expand Down
Expand Up @@ -95,7 +95,7 @@ private void doHandle(SelectWsRequest request) {
checkQualityGate(dbClient, request.getGateId());
ComponentDto project = getProject(dbSession, request.getProjectId(), request.getProjectKey());

dbClient.propertiesDao().insertProperty(dbSession, new PropertyDto()
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
.setKey(SONAR_QUALITYGATE_PROPERTY)
.setResourceId(project.getId())
.setValue(String.valueOf(request.getGateId())));
Expand Down
Expand Up @@ -91,9 +91,9 @@ public void handle(Request request, Response response) throws Exception {

private GenerateWsResponse doHandle(DbSession dbSession, GenerateRequest request) {
String serverId = generator.generate(request.getOrganization(), request.getIp());
dbClient.propertiesDao().insertProperty(dbSession, new PropertyDto().setKey(PERMANENT_SERVER_ID).setValue(serverId));
dbClient.propertiesDao().insertProperty(dbSession, new PropertyDto().setKey(ORGANISATION).setValue(request.getOrganization()));
dbClient.propertiesDao().insertProperty(dbSession, new PropertyDto().setKey(SERVER_ID_IP_ADDRESS).setValue(request.getIp()));
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(PERMANENT_SERVER_ID).setValue(serverId));
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(ORGANISATION).setValue(request.getOrganization()));
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SERVER_ID_IP_ADDRESS).setValue(request.getIp()));
dbSession.commit();
LOG.info("Generated new server ID={}", serverId);

Expand Down
Expand Up @@ -168,7 +168,7 @@ private void doHandle(DbSession dbSession, SetRequest request) {
validate(request);
PropertyDto property = toProperty(request, component);
value = property.getValue();
dbClient.propertiesDao().insertProperty(dbSession, property);
dbClient.propertiesDao().saveProperty(dbSession, property);
}

dbSession.commit();
Expand All @@ -187,13 +187,13 @@ private String doHandlePropertySet(DbSession dbSession, SetRequest request, @Nul
Long componentId = component.isPresent() ? component.get().getId() : null;

deleteSettings(dbSession, component, key);
dbClient.propertiesDao().insertProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys).setResourceId(componentId));
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys).setResourceId(componentId));

List<String> fieldValues = request.getFieldValues();
IntStream.of(fieldIds).boxed()
.flatMap(i -> readOneFieldValues(fieldValues.get(i - 1), request.getKey()).entrySet().stream()
.map(entry -> new KeyValue(key + "." + i + "." + entry.getKey(), entry.getValue())))
.forEach(keyValue -> dbClient.propertiesDao().insertProperty(dbSession, toFieldProperty(keyValue, componentId)));
.map(entry -> new KeyValue(key + "." + i + "." + entry.getKey(), entry.getValue())))
.forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentId)));

return inlinedFieldKeys;
}
Expand Down

0 comments on commit 5265833

Please sign in to comment.