Skip to content

Commit

Permalink
SONAR-5471 ability to have DEFAULT values on INT columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof committed Dec 13, 2016
1 parent a01c99b commit c71cfdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Expand Up @@ -20,6 +20,7 @@
package org.sonar.db.version;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.db.dialect.Dialect;
import org.sonar.db.dialect.H2;
import org.sonar.db.dialect.MsSql;
Expand All @@ -32,7 +33,7 @@
public class IntegerColumnDef extends AbstractColumnDef {

private IntegerColumnDef(Builder builder) {
super(builder.columnName, builder.isNullable, null);
super(builder.columnName, builder.isNullable, builder.defaultValue);
}

public static Builder newIntegerColumnDefBuilder() {
Expand All @@ -57,8 +58,9 @@ public String generateSqlType(Dialect dialect) {
public static class Builder {
@CheckForNull
private String columnName;

private boolean isNullable = true;
@CheckForNull
private Integer defaultValue = null;

public Builder setColumnName(String columnName) {
this.columnName = validateColumnName(columnName);
Expand All @@ -70,6 +72,11 @@ public Builder setIsNullable(boolean isNullable) {
return this;
}

public Builder setDefaultValue(@Nullable Integer i) {
this.defaultValue = i;
return this;
}

public IntegerColumnDef build() {
validateColumnName(columnName);
return new IntegerColumnDef(this);
Expand Down
Expand Up @@ -76,7 +76,12 @@ public void builder_setColumnName_sets_name_field_of_IntegerColumnDef() {
}

@Test
public void getDefaultValue_always_returns_null() {
public void builder_setDefaultValue_sets_default_value_field_of_IntegerColumnDef() {
assertThat(newIntegerColumnDefBuilder().setColumnName("a").setDefaultValue(42).build().getDefaultValue()).isEqualTo(42);
}

@Test
public void default_value_is_null_by_default() {
assertThat(newIntegerColumnDefBuilder().setColumnName("a").build().getDefaultValue()).isNull();
}

Expand Down

0 comments on commit c71cfdb

Please sign in to comment.