DATAJDBC-106 - Polishing.

Formatting and Javadoc.

Original pull request: #65
This commit is contained in:
Jens Schauder
2018-05-17 16:05:45 +02:00
parent cd7403907a
commit 46a07ac9f7
4 changed files with 45 additions and 41 deletions

View File

@@ -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 {

View File

@@ -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) {

View File

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