DATAJDBC-218 - Add support for key column in @Column annotation.

Original pull request: #83.
This commit is contained in:
Florian Lüdiger
2018-08-07 17:24:12 +02:00
committed by Jens Schauder
parent 1c15215735
commit 0a86f3a43b
3 changed files with 30 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ import org.springframework.util.ClassUtils;
*
* @author Jens Schauder
* @author Greg Turnquist
* @author Florian Lüdiger
*/
class BasicRelationalPersistentProperty extends AnnotationBasedPersistentProperty<RelationalPersistentProperty>
implements RelationalPersistentProperty {
@@ -52,6 +53,7 @@ class BasicRelationalPersistentProperty extends AnnotationBasedPersistentPropert
private final RelationalMappingContext context;
private final Lazy<Optional<String>> columnName;
private final Lazy<Optional<String>> keyColumnName;
/**
* Creates a new {@link AnnotationBasedPersistentProperty}.
@@ -70,6 +72,8 @@ class BasicRelationalPersistentProperty extends AnnotationBasedPersistentPropert
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("")));
}
/*
@@ -116,7 +120,10 @@ class BasicRelationalPersistentProperty extends AnnotationBasedPersistentPropert
@Override
public String getKeyColumn() {
return isQualified() ? context.getNamingStrategy().getKeyColumn(this) : null;
if (isQualified())
return keyColumnName.get().orElseGet(() -> context.getNamingStrategy().getKeyColumn(this));
else
return null;
}
@Override

View File

@@ -25,6 +25,7 @@ import java.lang.annotation.Target;
* The annotation to configure the mapping from an attribute to a database column.
*
* @author Kazuki Shimizu
* @author Florian Lüdiger
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@@ -35,4 +36,9 @@ public @interface Column {
* The mapping column name.
*/
String value();
/**
* The column name for key columns of List or Map collections.
*/
String keyColumn() default "";
}