Skip to content

Commit

Permalink
Refactor submodule hierarchies (#140)
Browse files Browse the repository at this point in the history
- add two modules
    - spring-jdbc-plus-commons: original features of spring-jdbc-plus
    - spring-data-jdbc-plus-support: common spring-data-jdbc features for sql, repository module
  • Loading branch information
chanhyeong authored Apr 8, 2024
1 parent 3e1d8a6 commit 1d64049
Show file tree
Hide file tree
Showing 48 changed files with 201 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import lombok.Value;
import lombok.With;

import com.navercorp.spring.data.jdbc.plus.sql.annotation.SqlTableAlias;
import com.navercorp.spring.jdbc.plus.commons.annotations.SqlTableAlias;

/**
* @author Myeonghyeon Lee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import lombok.Builder;
import lombok.Value;

import com.navercorp.spring.data.jdbc.plus.sql.annotation.SqlTableAlias;
import com.navercorp.spring.data.jdbc.plus.sql.guide.board.Board.Label;
import com.navercorp.spring.data.jdbc.plus.sql.guide.board.Board.Post;
import com.navercorp.spring.jdbc.plus.commons.annotations.SqlTableAlias;

/**
* @author Myeonghyeon Lee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import lombok.Builder;
import lombok.Getter;

import com.navercorp.spring.data.jdbc.plus.sql.annotation.SqlFunction;
import com.navercorp.spring.jdbc.plus.commons.annotations.SqlFunction;

/**
* @author Myeonghyeon Lee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import lombok.Value;
import lombok.With;

import com.navercorp.spring.data.jdbc.plus.sql.annotation.SqlTableAlias;
import com.navercorp.spring.jdbc.plus.commons.annotations.SqlTableAlias;

/**
* @author Myeonghyeon Lee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import lombok.Builder;
import lombok.Value;

import com.navercorp.spring.data.jdbc.plus.sql.annotation.SqlTableAlias;
import com.navercorp.spring.jdbc.plus.commons.annotations.SqlTableAlias;

/**
* @author Myeonghyeon Lee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import lombok.Builder;
import lombok.Getter;

import com.navercorp.spring.data.jdbc.plus.sql.annotation.SqlFunction;
import com.navercorp.spring.jdbc.plus.commons.annotations.SqlFunction;

/**
* @author Myeonghyeon Lee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.navercorp.spring.data.jdbc.plus.sql.guide.board

import com.navercorp.spring.data.jdbc.plus.sql.annotation.SqlTableAlias
import com.navercorp.spring.jdbc.plus.commons.annotations.SqlTableAlias
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Column
import org.springframework.data.relational.core.mapping.Embedded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.navercorp.spring.data.jdbc.plus.sql.guide.board

import com.navercorp.spring.data.jdbc.plus.sql.annotation.SqlTableAlias
import com.navercorp.spring.jdbc.plus.commons.annotations.SqlTableAlias
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Column
import org.springframework.data.relational.core.mapping.MappedCollection
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
rootProject.name = "spring-jdbc-plus"

include "spring-jdbc-plus-commons"
include "spring-jdbc-plus-support"
include "spring-data-jdbc-plus-support"
include "spring-data-jdbc-plus-sql"
include "spring-data-jdbc-plus-repository"
include "spring-boot-autoconfigure-data-jdbc-plus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import reactor.core.publisher.Flux;

import com.navercorp.spring.data.jdbc.plus.sql.config.JdbcPlusSqlConfiguration;
import com.navercorp.spring.data.jdbc.plus.sql.convert.SqlProvider;
import com.navercorp.spring.data.jdbc.plus.support.convert.SqlProvider;
import com.navercorp.spring.data.jdbc.plus.sql.parametersource.SqlParameterSourceFactory;
import com.navercorp.spring.data.jdbc.plus.sql.provider.EntityJdbcProvider;
import com.navercorp.spring.data.jdbc.plus.sql.support.template.JdbcReactiveTemplate;
Expand Down
5 changes: 2 additions & 3 deletions spring-data-jdbc-plus-sql/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
compileJava.dependsOn(processResources)

dependencies {
api(project(":spring-jdbc-plus-commons"))
api(project(":spring-jdbc-plus-support"))
api("org.springframework.data:spring-data-jdbc")
api("org.springframework.data:spring-data-relational")
api("org.springframework.data:spring-data-commons")
api(project(":spring-data-jdbc-plus-support"))

compileOnly("org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}")
compileOnly("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;

import com.navercorp.spring.data.jdbc.plus.sql.convert.AggregateResultJdbcConverter;
import com.navercorp.spring.data.jdbc.plus.sql.convert.SqlProvider;
import com.navercorp.spring.data.jdbc.plus.support.convert.SqlProvider;
import com.navercorp.spring.data.jdbc.plus.sql.parametersource.DefaultSqlParameterSourceFactory;
import com.navercorp.spring.data.jdbc.plus.sql.parametersource.SqlParameterSourceFactory;
import com.navercorp.spring.data.jdbc.plus.sql.provider.EntityJdbcProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import com.navercorp.spring.data.jdbc.plus.support.convert.PropertyPathUtils;

/**
* The type Aggregate result jdbc converter.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.springframework.data.relational.core.mapping.AggregatePath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;

import com.navercorp.spring.data.jdbc.plus.support.convert.PropertyPathUtils;

/**
* {@link PropertyValueProvider} obtaining values from a ResultSetAccessor. For a given id property it provides
* the value in the resultset under which other entities refer back to it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.springframework.data.relational.core.mapping.AggregatePath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;

import com.navercorp.spring.data.jdbc.plus.support.convert.PropertyPathUtils;

/**
* {@link PropertyValueProvider} obtaining values from a ResultSetAccessor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
package com.navercorp.spring.data.jdbc.plus.sql.parametersource;

import java.util.Objects;
import java.util.Set;

import org.springframework.data.relational.core.sql.SqlIdentifier;

import com.navercorp.spring.data.jdbc.plus.support.parametersource.MutableSqlIdentifierParameterSource;
import com.navercorp.spring.jdbc.plus.support.parametersource.converter.IterableExpandPadding;
import com.navercorp.spring.jdbc.plus.support.parametersource.converter.JdbcParameterSourceConverter;
import com.navercorp.spring.jdbc.plus.support.parametersource.fallback.FallbackParameterSource;
Expand All @@ -29,7 +33,8 @@
*
* @author Myeonghyeon Lee
*/
class ConvertibleSqlIdentifierParameterSource extends SqlIdentifierParameterSource {
class ConvertibleSqlIdentifierParameterSource implements MutableSqlIdentifierParameterSource {
private final MutableSqlIdentifierParameterSource delegate;
private final JdbcParameterSourceConverter converter;
private final FallbackParameterSource fallbackParameterSource;

Expand All @@ -47,7 +52,7 @@ class ConvertibleSqlIdentifierParameterSource extends SqlIdentifierParameterSour
JdbcParameterSourceConverter converter,
FallbackParameterSource fallbackParameterSource
) {
super();
this.delegate = MutableSqlIdentifierParameterSource.create();
this.converter = Objects.requireNonNull(converter, "Converter must not be null.");
this.fallbackParameterSource = fallbackParameterSource;
}
Expand All @@ -56,7 +61,7 @@ class ConvertibleSqlIdentifierParameterSource extends SqlIdentifierParameterSour
public Object getValue(String paramName) throws IllegalArgumentException {
Object value = null;
try {
value = super.getValue(paramName);
value = delegate.getValue(paramName);
} catch (IllegalArgumentException e) {
if (!this.isFallback(paramName)) {
throw e;
Expand All @@ -79,6 +84,46 @@ public Object getValue(String paramName) throws IllegalArgumentException {
return value;
}

@Override
public Set<SqlIdentifier> getIdentifiers() {
return delegate.getIdentifiers();
}

@Override
public void addValue(SqlIdentifier name, Object value) {
delegate.addValue(name, value);
}

@Override
public void addValue(SqlIdentifier identifier, Object value, int sqlType) {
delegate.addValue(identifier, value, sqlType);
}

@Override
public void addAll(MutableSqlIdentifierParameterSource others) {
delegate.addAll(others);
}

@Override
public boolean hasValue(String paramName) {
return delegate.hasValue(paramName);
}

@Override
public int getSqlType(String paramName) {
return delegate.getSqlType(paramName);
}

@Override
public String getTypeName(String paramName) {
return delegate.getTypeName(paramName);
}

@Override
public String[] getParameterNames() {
return delegate.getParameterNames();
}

/**
* Sets padding iterable boundaries.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

import com.navercorp.spring.data.jdbc.plus.support.parametersource.MutableSqlIdentifierParameterSource;

/**
* The type Default sql parameter source factory.
*
Expand Down Expand Up @@ -62,7 +64,7 @@ public MapSqlParameterSource mapParameterSource(Map<String, ?> map) {

@Override
public SqlParameterSource entityParameterSource(Object entity) {
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource();
MutableSqlIdentifierParameterSource parameterSource = MutableSqlIdentifierParameterSource.create();
RelationalPersistentEntity<?> persistentEntity =
this.mappingContext.getRequiredPersistentEntity(entity.getClass());
this.parameterSourceApplier.addParameterSource(parameterSource, entity, persistentEntity, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

import com.navercorp.spring.data.jdbc.plus.support.parametersource.MutableSqlIdentifierParameterSource;
import com.navercorp.spring.jdbc.plus.support.parametersource.ConvertibleParameterSourceFactory;

/**
Expand Down Expand Up @@ -72,7 +73,7 @@ public MapSqlParameterSource mapParameterSource(Map<String, ?> map) {

@Override
public SqlParameterSource entityParameterSource(Object entity) {
SqlIdentifierParameterSource parameterSource = new ConvertibleSqlIdentifierParameterSource(
MutableSqlIdentifierParameterSource parameterSource = new ConvertibleSqlIdentifierParameterSource(
this.delegate.getConverter(), this.delegate.getFallback());
RelationalPersistentEntity<?> persistentEntity =
this.mappingContext.getRequiredPersistentEntity(entity.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.lang.Nullable;

import com.navercorp.spring.data.jdbc.plus.support.parametersource.MutableSqlIdentifierParameterSource;

/**
* The type Entity sql parameter source applier.
*
Expand Down Expand Up @@ -60,7 +62,7 @@ class EntitySqlParameterSourceApplier {
*/
// DefaultDataAccessStrategy#getParameterSource
void addParameterSource(
SqlIdentifierParameterSource parameterSource,
MutableSqlIdentifierParameterSource parameterSource,
Object instance,
RelationalPersistentEntity<?> persistentEntity,
String prefix
Expand Down Expand Up @@ -94,7 +96,7 @@ void addParameterSource(

// DefaultDataAccessStrategy#addConvertedPropertyValue
private void addConvertedPropertyValue(
SqlIdentifierParameterSource parameterSource,
MutableSqlIdentifierParameterSource parameterSource,
RelationalPersistentProperty property,
Object value,
SqlIdentifier name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

import com.navercorp.spring.data.jdbc.plus.sql.convert.AggregateResultSetExtractor;
import com.navercorp.spring.data.jdbc.plus.sql.convert.SqlProvider;
import com.navercorp.spring.data.jdbc.plus.support.convert.SqlProvider;
import com.navercorp.spring.data.jdbc.plus.sql.parametersource.EntityConvertibleSqlParameterSourceFactory;
import com.navercorp.spring.data.jdbc.plus.sql.parametersource.SqlParameterSourceFactory;
import com.navercorp.spring.jdbc.plus.support.parametersource.CompositeSqlParameterSource;
import com.navercorp.spring.jdbc.plus.support.parametersource.ConvertibleParameterSourceFactory;

/**
* The type Entity jdbc provider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.navercorp.spring.data.jdbc.plus.sql.support;

import com.navercorp.spring.data.jdbc.plus.sql.convert.SqlProvider;
import com.navercorp.spring.data.jdbc.plus.support.convert.SqlProvider;

/**
* The interface Sql aware.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.navercorp.spring.data.jdbc.plus.sql.support;

import com.navercorp.spring.data.jdbc.plus.sql.convert.SqlProvider;
import com.navercorp.spring.data.jdbc.plus.support.convert.SqlProvider;

/**
* The type Sql generator support.
Expand Down
19 changes: 19 additions & 0 deletions spring-data-jdbc-plus-support/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
compileJava.dependsOn(processResources)

dependencies {
api(project(":spring-jdbc-plus-commons"))

api("org.springframework.data:spring-data-commons")
api("org.springframework.data:spring-data-jdbc")
api("org.springframework.data:spring-data-relational")

testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testImplementation("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.assertj:assertj-core:3.23.1")
testImplementation("org.mockito:mockito-junit-jupiter")

testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testRuntimeOnly("org.junit.platform:junit-platform-commons")
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.navercorp.spring.data.jdbc.plus.sql.convert;
package com.navercorp.spring.data.jdbc.plus.support.convert;

import javax.annotation.Nullable;

Expand All @@ -36,7 +36,7 @@ public class PropertyPathUtils {
* @param path
* @return
*/
static SqlIdentifier getColumnAlias(AggregatePath path) {
public static SqlIdentifier getColumnAlias(AggregatePath path) {
return getColumnAlias(path, path.getColumnInfo().name());
}

Expand All @@ -47,7 +47,7 @@ static SqlIdentifier getColumnAlias(AggregatePath path) {
* @param columnName
* @return
*/
static SqlIdentifier getColumnAlias(AggregatePath path, SqlIdentifier columnName) {
public static SqlIdentifier getColumnAlias(AggregatePath path, SqlIdentifier columnName) {
AggregatePath tableOwner = getTableOwningAncestor(path);
if (tableOwner.isRoot()) {
return columnName;
Expand All @@ -64,7 +64,7 @@ static SqlIdentifier getColumnAlias(AggregatePath path, SqlIdentifier columnName
* @param path
* @return
*/
static SqlIdentifier getReverseColumnAlias(AggregatePath path) {
public static SqlIdentifier getReverseColumnAlias(AggregatePath path) {
return getReverseColumnAlias(path, path.getTableInfo().reverseColumnInfo().name());
}

Expand All @@ -75,7 +75,7 @@ static SqlIdentifier getReverseColumnAlias(AggregatePath path) {
* @param reverseColumnName
* @return
*/
static SqlIdentifier getReverseColumnAlias(
public static SqlIdentifier getReverseColumnAlias(
AggregatePath path,
SqlIdentifier reverseColumnName
) {
Expand All @@ -93,7 +93,7 @@ static SqlIdentifier getReverseColumnAlias(
* @return
*/
@Nullable
static SqlIdentifier getTableAlias(AggregatePath path) {
public static SqlIdentifier getTableAlias(AggregatePath path) {
AggregatePath tableOwner = getTableOwningAncestor(path);
return getTableAliasFromTableOwner(tableOwner);
}
Expand Down
Loading

0 comments on commit 1d64049

Please sign in to comment.