Skip to content

Commit 2d250bb

Browse files
committed
Polishing.
Add Javadoc. Reformat code. See: #359 Original pull request: #1385
1 parent 1d3a485 commit 2d250bb

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

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

-1
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

+10-1
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 4.1.1
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/test/java/org/springframework/data/cassandra/core/CassandraAdminTemplateIntegrationTests.java

+15-20
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Collection;
2222
import java.util.Map;
2323

24-
import org.assertj.core.api.Assertions;
2524
import org.junit.jupiter.api.BeforeEach;
2625
import org.junit.jupiter.api.Test;
2726
import org.springframework.data.annotation.Id;
@@ -66,24 +65,21 @@ private KeyspaceMetadata getKeyspaceMetadata() {
6665
return getSession().getKeyspace().flatMap(metadata::getKeyspace).get();
6766
}
6867

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())))
68+
@Test // GH-359
69+
void shouldApplyTableOptions() {
70+
71+
Map<String, Object> options = Map.of(TableOption.COMMENT.getName(), "This is comment for table", //
72+
TableOption.BLOOM_FILTER_FP_CHANCE.getName(), "0.3");
73+
74+
CqlIdentifier tableName = CqlIdentifier.fromCql("someTable");
75+
cassandraAdminTemplate.createTable(true, tableName, SomeTable.class, options);
76+
77+
TableMetadata someTable = getKeyspaceMetadata().getTables().get(tableName);
78+
79+
assertThat(someTable).isNotNull();
80+
assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.COMMENT.getName())))
8581
.isEqualTo("This is comment for table");
86-
Assertions.assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.BLOOM_FILTER_FP_CHANCE.getName())))
82+
assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.BLOOM_FILTER_FP_CHANCE.getName())))
8783
.isEqualTo(0.3);
8884
}
8985

@@ -117,8 +113,7 @@ void testDropTable() {
117113
@Table("someTable")
118114
private static class SomeTable {
119115

120-
@Id
121-
private String name;
116+
@Id private String name;
122117
private Integer number;
123118
private LocalDate createdAt;
124119
}

0 commit comments

Comments
 (0)