Skip to content

Move default implementation to NamingStrategy #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jdbc</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jdbc</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -26,15 +26,15 @@
<java-module-name>spring.data.jdbc</java-module-name>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>

<assertj-core.version>3.6.2</assertj-core.version>
<degraph-check.version>0.1.4</degraph-check.version>
<hsqldb.version>2.2.8</hsqldb.version>
<mybatis.version>3.4.4</mybatis.version>
<mybatis-spring.version>1.3.1</mybatis-spring.version>
<mysql.version>1.5.1</mysql.version>
<mysql-connector-java.version>5.1.41</mysql-connector-java.version>
<postgresql.version>42.0.0</postgresql.version>
</properties>
<assertj-core.version>3.6.2</assertj-core.version>
<degraph-check.version>0.1.4</degraph-check.version>
<hsqldb.version>2.2.8</hsqldb.version>
<mybatis.version>3.4.4</mybatis.version>
<mybatis-spring.version>1.3.1</mybatis-spring.version>
<mysql.version>1.5.1</mysql.version>
<mysql-connector-java.version>5.1.41</mysql-connector-java.version>
<postgresql.version>42.0.0</postgresql.version>
</properties>

<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,8 @@
* a different strategy on the fly.
*
* @author Greg Turnquist
* @author Michael Simons
* @deprecated Use {@link NamingStrategy} for a default implementation and implement methods as needed
*/
public class DefaultNamingStrategy implements NamingStrategy {

/**
* No schema at all!
*/
@Override
public String getSchema() {
return "";
}

/**
* Look up the {@link Class}'s simple name.
*/
@Override
public String getTableName(Class<?> type) {
return type.getSimpleName();
}


/**
* Look up the {@link JdbcPersistentProperty}'s name.
*/
@Override
public String getColumnName(JdbcPersistentProperty property) {
return property.getName();
}

@Override
public String getReverseColumnName(JdbcPersistentProperty property) {
return property.getOwner().getTableName();
}

@Override
public String getKeyColumn(JdbcPersistentProperty property) {
return getReverseColumnName(property) + "_key";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,60 @@
package org.springframework.data.jdbc.mapping.model;

/**
* 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}.
*
* NOTE: Can also be used as an adapter. Create a lambda or an anonymous subclass and
* override any settings to implement a different strategy on the fly.
*
* @author Greg Turnquist
* @author Michael Simons
*/
public interface NamingStrategy {

String getSchema();
/**
* Defaults to no schema.
*
* @return No schema
*/
default String getSchema() {
return "";
}

String getTableName(Class<?> type);
/**
* Look up the {@link Class}'s simple name.
*/
default String getTableName(Class<?> type) {
return type.getSimpleName();
}

String getColumnName(JdbcPersistentProperty property);
/**
* Look up the {@link JdbcPersistentProperty}'s name.
*/
default String getColumnName(JdbcPersistentProperty property) {
return property.getName();
}

default String getQualifiedTableName(Class<?> type) {
return this.getSchema() + (this.getSchema().equals("") ? "" : ".") + this.getTableName(type);
}

/**
* For a reference A -> B this is the name in the table for B which references A.
* For a reference A -&gt; B this is the name in the table for B which references A.
*
* @param property The property who's column name in the owner table is required
* @return a column name.
*/
String getReverseColumnName(JdbcPersistentProperty property);
default String getReverseColumnName(JdbcPersistentProperty property) {
return property.getOwner().getTableName();
}

/**
* For a map valued reference A -> Map&gt;X,B&lt; this is the name of the column in the tabel for B holding the key of the map.
* @return
*/
String getKeyColumn(JdbcPersistentProperty property);
default String getKeyColumn(JdbcPersistentProperty property){
return getReverseColumnName(property) + "_key";
}

}