DATAJDBC-106 - Polishing.
Formatting and Javadoc. Original pull request: #65
This commit is contained in:
@@ -22,13 +22,13 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* The annotation to configure a mapping database column.
|
||||
* The annotation to configure the mapping from an attribute to a database column.
|
||||
*
|
||||
* @author Kazuki Shimizu
|
||||
* @since 1.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD, ElementType.METHOD})
|
||||
@Target({ ElementType.FIELD, ElementType.METHOD })
|
||||
@Documented
|
||||
public @interface Column {
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.mapping.model;
|
||||
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
|
||||
/**
|
||||
* Interface and default implementation of a naming strategy. Defaults to no schema, table name based on {@link Class}
|
||||
* and column name based on {@link JdbcPersistentProperty}.
|
||||
@@ -28,6 +28,8 @@ import java.util.Optional;
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @author Michael Simons
|
||||
* @author Kazuki Shimizu
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface NamingStrategy {
|
||||
@@ -52,20 +54,22 @@ public interface NamingStrategy {
|
||||
* Look up the {@link Class}'s simple name or {@link Table#value()}.
|
||||
*/
|
||||
default String getTableName(Class<?> type) {
|
||||
|
||||
Table table = AnnotatedElementUtils.findMergedAnnotation(type, Table.class);
|
||||
return Optional.ofNullable(table)//
|
||||
.map(Table::value)//
|
||||
.orElse(type.getSimpleName());
|
||||
.map(Table::value)//
|
||||
.orElse(type.getSimpleName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the {@link JdbcPersistentProperty}'s name or {@link Column#value()}.
|
||||
*/
|
||||
default String getColumnName(JdbcPersistentProperty property) {
|
||||
|
||||
Column column = property.findAnnotation(Column.class);
|
||||
return Optional.ofNullable(column)//
|
||||
.map(Column::value)//
|
||||
.orElse(property.getName());
|
||||
.map(Column::value)//
|
||||
.orElse(property.getName());
|
||||
}
|
||||
|
||||
default String getQualifiedTableName(Class<?> type) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* The annotation to configure a mapping database table.
|
||||
* The annotation to configure the mapping from a class to a database table.
|
||||
*
|
||||
* @author Kazuki Shimizu
|
||||
* @since 1.0
|
||||
|
||||
Reference in New Issue
Block a user