Skip to content

Commit 0c77ac6

Browse files
committed
Polishing.
Add Javadoc. Reformat code. See: #359 Original pull request: #1385
1 parent aa07755 commit 0c77ac6

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraAdminOperations.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public interface CassandraAdminOperations extends CassandraOperations {
5555
void createTable(boolean ifNotExists, CqlIdentifier tableName, Class<?> entityClass,
5656
Map<String, Object> optionsByName);
5757

58-
5958
/**
6059
* Drops a table based on the given {@link Class entity type}. The name of the table is derived from either the simple
6160
* name of the {@link Class entity class} or name of the table specified with the {@link Table} mapping annotation.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/TableOption.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.Map;
1919

2020
import org.springframework.lang.Nullable;
21-
import org.springframework.util.StringUtils;
2221

2322
/**
2423
* Enumeration that represents all known table options. If a table option is not listed here, but is supported by
@@ -86,12 +85,22 @@ public enum TableOption implements Option {
8685
this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue);
8786
}
8887

88+
/**
89+
* Look up {@link TableOption} by name using case-insensitive lookups.
90+
*
91+
* @param optionName name of the option.
92+
* @return the option.
93+
* @throws IllegalArgumentException if the option cannot be determined.
94+
* @since 3.4.13
95+
*/
8996
public static TableOption valueOfIgnoreCase(String optionName) {
97+
9098
for (TableOption value : values()) {
9199
if (value.getName().equalsIgnoreCase(optionName)) {
92100
return value;
93101
}
94102
}
103+
95104
throw new IllegalArgumentException(String.format("Unable to recognize specified Table option '%s'", optionName));
96105
}
97106

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/TableSpecification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ protected T column(CqlIdentifier name, DataType type, Optional<PrimaryKeyType> o
296296

297297
this.columns.add(column);
298298

299-
if (optionalKeyType.isEmpty()) {
299+
if (!optionalKeyType.isPresent()) {
300300
this.nonKeyColumns.add(column);
301301
}
302302

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/CassandraAdminTemplateIntegrationTests.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
import java.time.LocalDate;
2121
import java.util.Collection;
22+
import java.util.HashMap;
2223
import java.util.Map;
2324

24-
import org.assertj.core.api.Assertions;
2525
import org.junit.jupiter.api.BeforeEach;
2626
import org.junit.jupiter.api.Test;
2727
import org.springframework.data.annotation.Id;
@@ -66,24 +66,23 @@ private KeyspaceMetadata getKeyspaceMetadata() {
6666
return getSession().getKeyspace().flatMap(metadata::getKeyspace).get();
6767
}
6868

69-
@Test
70-
void givenAdminTemplate_whenCreateTableWithOptions_ThenCreatedTableContainsTheseOptions() {
71-
cassandraAdminTemplate.createTable(
72-
true,
73-
CqlIdentifier.fromCql("someTable"),
74-
SomeTable.class,
75-
Map.of(
76-
TableOption.COMMENT.getName(), "This is comment for table",
77-
TableOption.BLOOM_FILTER_FP_CHANCE.getName(), "0.3"
78-
)
79-
);
80-
81-
TableMetadata someTable = getKeyspaceMetadata().getTables().values().stream().findFirst().orElse(null);
82-
83-
Assertions.assertThat(someTable).isNotNull();
84-
Assertions.assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.COMMENT.getName())))
69+
@Test // GH-359
70+
void shouldApplyTableOptions() {
71+
72+
Map<String, Object> options = new HashMap<>();
73+
74+
options.put(TableOption.COMMENT.getName(), "This is comment for table");
75+
options.put(TableOption.BLOOM_FILTER_FP_CHANCE.getName(), "0.3");
76+
77+
CqlIdentifier tableName = CqlIdentifier.fromCql("someTable");
78+
cassandraAdminTemplate.createTable(true, tableName, SomeTable.class, options);
79+
80+
TableMetadata someTable = getKeyspaceMetadata().getTables().get(tableName);
81+
82+
assertThat(someTable).isNotNull();
83+
assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.COMMENT.getName())))
8584
.isEqualTo("This is comment for table");
86-
Assertions.assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.BLOOM_FILTER_FP_CHANCE.getName())))
85+
assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.BLOOM_FILTER_FP_CHANCE.getName())))
8786
.isEqualTo(0.3);
8887
}
8988

@@ -117,8 +116,7 @@ void testDropTable() {
117116
@Table("someTable")
118117
private static class SomeTable {
119118

120-
@Id
121-
private String name;
119+
@Id private String name;
122120
private Integer number;
123121
private LocalDate createdAt;
124122
}

0 commit comments

Comments
 (0)