#367 - Polishing.
Simplified the NamingStrategy by replacing parts of it with Table and Column annotations.
This commit is contained in:
@@ -38,6 +38,7 @@ import org.springframework.lang.Nullable;
|
||||
@Configuration
|
||||
@EnableJdbcRepositories
|
||||
public class AggregateConfiguration {
|
||||
|
||||
final AtomicInteger id = new AtomicInteger(0);
|
||||
|
||||
@Bean
|
||||
@@ -67,13 +68,9 @@ public class AggregateConfiguration {
|
||||
@Bean
|
||||
public NamingStrategy namingStrategy() {
|
||||
|
||||
Map<String, String> tableAliases = new HashMap<String, String>();
|
||||
tableAliases.put("manual", "handbuch");
|
||||
|
||||
Map<String, String> columnAliases = new HashMap<String, String>();
|
||||
columnAliases.put("lego_set.int_maximum_age", "max_age");
|
||||
columnAliases.put("lego_set.int_minimum_age", "min_age");
|
||||
columnAliases.put("handbuch.id", "handbuch_id");
|
||||
|
||||
Map<String, String> reverseColumnAliases = new HashMap<String, String>();
|
||||
reverseColumnAliases.put("manual", "handbuch_id");
|
||||
@@ -91,11 +88,6 @@ public class AggregateConfiguration {
|
||||
return columnAliases.computeIfAbsent(key, __ -> defaultName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableName(Class<?> type) {
|
||||
return tableAliases.computeIfAbsent(NamingStrategy.super.getTableName(type), key -> key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReverseColumnName(JdbcPersistentProperty property) {
|
||||
return reverseColumnAliases.computeIfAbsent(property.getName(),
|
||||
|
||||
@@ -18,6 +18,8 @@ package example.springdata.jdbc.basics.aggregate;
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.core.mapping.Column;
|
||||
import org.springframework.data.jdbc.core.mapping.Table;
|
||||
|
||||
/**
|
||||
* A manual instructing how to assemble a {@link LegoSet}.
|
||||
@@ -25,8 +27,10 @@ import org.springframework.data.annotation.Id;
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@Data
|
||||
@Table("handbuch")
|
||||
public class Manual {
|
||||
|
||||
@Column("handbuch_id")
|
||||
private @Id Long id;
|
||||
private String author, text;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user