Skip to content

Commit

Permalink
DATAJDBC-218 - Polishing.
Browse files Browse the repository at this point in the history
Added line breaks for better readability.
Added braces to if/else statements.
Used StringUtils instead of .equals("").

Original pull request: #83.
  • Loading branch information
schauder committed Sep 18, 2018
1 parent 0a86f3a commit 335a7cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;

/**
* Meta data about a property to be used by repository implementations.
Expand All @@ -46,6 +47,7 @@ class BasicRelationalPersistentProperty extends AnnotationBasedPersistentPropert
private static final Map<Class<?>, Class<?>> javaToDbType = new LinkedHashMap<>();

static {

javaToDbType.put(Enum.class, String.class);
javaToDbType.put(ZonedDateTime.class, String.class);
javaToDbType.put(Temporal.class, Date.class);
Expand All @@ -72,8 +74,11 @@ public BasicRelationalPersistentProperty(Property property, PersistentEntity<?,

this.context = context;
this.columnName = Lazy.of(() -> Optional.ofNullable(findAnnotation(Column.class)).map(Column::value));
this.keyColumnName = Lazy.of(() -> Optional.ofNullable(
findAnnotation(Column.class)).map(Column::keyColumn).filter(keyColumn -> !keyColumn.equals("")));
this.keyColumnName = Lazy.of(() -> Optional.ofNullable( //
findAnnotation(Column.class)) //
.map(Column::keyColumn) //
.filter(StringUtils::hasText) //
);
}

/*
Expand Down Expand Up @@ -120,10 +125,12 @@ public String getReverseColumnName() {

@Override
public String getKeyColumn() {
if (isQualified())

if (isQualified()) {
return keyColumnName.get().orElseGet(() -> context.getNamingStrategy().getKeyColumn(this));
else
} else {
return null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ public void detectsAnnotatedColumnName() {
@Test // DATAJDBC-218
public void detectsAnnotatedColumnAndKeyName() {

RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
RelationalPersistentProperty listProperty = context //
.getRequiredPersistentEntity(DummyEntity.class) //
.getRequiredPersistentProperty("someList");

assertThat(entity.getRequiredPersistentProperty("someList").getColumnName())
.isEqualTo("dummy_column_name");
assertThat(entity.getRequiredPersistentProperty("someList").getKeyColumn())
.isEqualTo("dummy_key_column_name");
assertThat(listProperty.getColumnName()).isEqualTo("dummy_column_name");
assertThat(listProperty.getKeyColumn()).isEqualTo("dummy_key_column_name");
}

private void checkTargetType(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity,
Expand All @@ -113,8 +113,7 @@ private static class DummyEntity {
private final ZonedDateTime zonedDateTime;
private final UUID uuid;

@Column(value="dummy_column_name", keyColumn="dummy_key_column_name")
private List<Integer> someList;
@Column(value = "dummy_column_name", keyColumn = "dummy_key_column_name") private List<Integer> someList;

// DATACMNS-106
private @Column("dummy_name") String name;
Expand Down

0 comments on commit 335a7cb

Please sign in to comment.