Polishing.
Add Javadoc. Reformat code. See: #359 Original pull request: #1385
This commit is contained in:
@@ -55,7 +55,6 @@ public interface CassandraAdminOperations extends CassandraOperations {
|
||||
void createTable(boolean ifNotExists, CqlIdentifier tableName, Class<?> entityClass,
|
||||
Map<String, Object> optionsByName);
|
||||
|
||||
|
||||
/**
|
||||
* Drops a table based on the given {@link Class entity type}. The name of the table is derived from either the simple
|
||||
* name of the {@link Class entity class} or name of the table specified with the {@link Table} mapping annotation.
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up {@link TableOption} by name using case-insensitive lookups.
|
||||
*
|
||||
* @param optionName name of the option.
|
||||
* @return the option.
|
||||
* @throws IllegalArgumentException if the option cannot be determined.
|
||||
* @since 4.1.1
|
||||
*/
|
||||
public static TableOption valueOfIgnoreCase(String optionName) {
|
||||
|
||||
for (TableOption value : values()) {
|
||||
if (value.getName().equalsIgnoreCase(optionName)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(String.format("Unable to recognize specified Table option '%s'", optionName));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
@@ -66,24 +65,21 @@ class CassandraAdminTemplateIntegrationTests extends AbstractKeyspaceCreatingInt
|
||||
return getSession().getKeyspace().flatMap(metadata::getKeyspace).get();
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenAdminTemplate_whenCreateTableWithOptions_ThenCreatedTableContainsTheseOptions() {
|
||||
cassandraAdminTemplate.createTable(
|
||||
true,
|
||||
CqlIdentifier.fromCql("someTable"),
|
||||
SomeTable.class,
|
||||
Map.of(
|
||||
TableOption.COMMENT.getName(), "This is comment for table",
|
||||
TableOption.BLOOM_FILTER_FP_CHANCE.getName(), "0.3"
|
||||
)
|
||||
);
|
||||
@Test // GH-359
|
||||
void shouldApplyTableOptions() {
|
||||
|
||||
TableMetadata someTable = getKeyspaceMetadata().getTables().values().stream().findFirst().orElse(null);
|
||||
Map<String, Object> options = Map.of(TableOption.COMMENT.getName(), "This is comment for table", //
|
||||
TableOption.BLOOM_FILTER_FP_CHANCE.getName(), "0.3");
|
||||
|
||||
Assertions.assertThat(someTable).isNotNull();
|
||||
Assertions.assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.COMMENT.getName())))
|
||||
CqlIdentifier tableName = CqlIdentifier.fromCql("someTable");
|
||||
cassandraAdminTemplate.createTable(true, tableName, SomeTable.class, options);
|
||||
|
||||
TableMetadata someTable = getKeyspaceMetadata().getTables().get(tableName);
|
||||
|
||||
assertThat(someTable).isNotNull();
|
||||
assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.COMMENT.getName())))
|
||||
.isEqualTo("This is comment for table");
|
||||
Assertions.assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.BLOOM_FILTER_FP_CHANCE.getName())))
|
||||
assertThat(someTable.getOptions().get(CqlIdentifier.fromCql(TableOption.BLOOM_FILTER_FP_CHANCE.getName())))
|
||||
.isEqualTo(0.3);
|
||||
}
|
||||
|
||||
@@ -117,8 +113,7 @@ class CassandraAdminTemplateIntegrationTests extends AbstractKeyspaceCreatingInt
|
||||
@Table("someTable")
|
||||
private static class SomeTable {
|
||||
|
||||
@Id
|
||||
private String name;
|
||||
@Id private String name;
|
||||
private Integer number;
|
||||
private LocalDate createdAt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user