Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,8 @@ private ReadingContext(PersistentPropertyPathExtension rootPath, ResultSetAccess
this.path = new PersistentPropertyPathExtension(getMappingContext(), this.entity);
this.identifier = identifier;
this.key = key;
this.propertyValueProvider = new JdbcPropertyValueProvider(identifierProcessing, path, accessor);
this.backReferencePropertyValueProvider = new JdbcBackReferencePropertyValueProvider(identifierProcessing, path,
accessor);
this.propertyValueProvider = new JdbcPropertyValueProvider(path, accessor);
this.backReferencePropertyValueProvider = new JdbcBackReferencePropertyValueProvider(path, accessor);
this.accessor = accessor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,7 @@ private RowMapper<?> getMapEntityRowMapper(PersistentPropertyPathExtension path,
SqlIdentifier keyColumn = path.getQualifierColumn();
Assert.notNull(keyColumn, () -> "KeyColumn must not be null for " + path);

return new MapEntityRowMapper<>(path, converter, identifier, keyColumn, getIdentifierProcessing());
}

private IdentifierProcessing getIdentifierProcessing() {
return sqlGeneratorSource.getDialect().getIdentifierProcessing();
return new MapEntityRowMapper<>(path, converter, identifier, keyColumn);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Object[] execute(String sql, SqlParameterSource[] sqlParameterSources) {
Map<String, Object> keys = keyList.get(i);
if (keys.size() > 1) {
if (idColumn != null) {
ids[i] = keys.get(idColumn.getReference(dialect.getIdentifierProcessing()));
ids[i] = keys.get(idColumn.getReference());
}
} else {
ids[i] = keys.entrySet().stream().findFirst() //
Expand All @@ -93,7 +93,7 @@ public Object[] execute(String sql, SqlParameterSource[] sqlParameterSources) {
private String[] getKeyColumnNames() {

return Optional.ofNullable(idColumn)
.map(idColumn -> new String[] { idColumn.getReference(dialect.getIdentifierProcessing()) })
.map(idColumn -> new String[] { idColumn.getReference() })
.orElse(new String[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public Object execute(String sql, SqlParameterSource sqlParameterSource) {
return null;
}

return keys.get(idColumn.getReference(dialect.getIdentifierProcessing()));
return keys.get(idColumn.getReference());
}
}

private String[] getKeyColumnNames() {
return Optional.ofNullable(idColumn)
.map(idColumn -> new String[] { idColumn.getReference(dialect.getIdentifierProcessing()) })
.map(idColumn -> new String[] { idColumn.getReference() })
.orElse(new String[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,30 @@
* the value in the resultset under which other entities refer back to it.
*
* @author Jens Schauder
* @author Mikhail Polivakha
* @since 2.0
*/
class JdbcBackReferencePropertyValueProvider implements PropertyValueProvider<RelationalPersistentProperty> {

private final IdentifierProcessing identifierProcessing;
private final PersistentPropertyPathExtension basePath;
private final ResultSetAccessor resultSet;

/**
* @param identifierProcessing used for converting the
* {@link org.springframework.data.relational.core.sql.SqlIdentifier} from a property to a column label
* @param basePath path from the aggregate root relative to which all properties get resolved.
* @param resultSet the {@link ResultSetAccessor} from which to obtain the actual values.
*/
JdbcBackReferencePropertyValueProvider(IdentifierProcessing identifierProcessing,
PersistentPropertyPathExtension basePath, ResultSetAccessor resultSet) {
JdbcBackReferencePropertyValueProvider(PersistentPropertyPathExtension basePath, ResultSetAccessor resultSet) {

this.resultSet = resultSet;
this.basePath = basePath;
this.identifierProcessing = identifierProcessing;
}

@Override
public <T> T getPropertyValue(RelationalPersistentProperty property) {
return (T) resultSet
.getObject(basePath.extendBy(property).getReverseColumnNameAlias().getReference(identifierProcessing));
return (T) resultSet.getObject(basePath.extendBy(property).getReverseColumnNameAlias().getReference());
}

public JdbcBackReferencePropertyValueProvider extendBy(RelationalPersistentProperty property) {
return new JdbcBackReferencePropertyValueProvider(identifierProcessing, basePath.extendBy(property), resultSet);
return new JdbcBackReferencePropertyValueProvider(basePath.extendBy(property), resultSet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,18 @@
*/
class JdbcPropertyValueProvider implements PropertyValueProvider<RelationalPersistentProperty> {

private final IdentifierProcessing identifierProcessing;
private final PersistentPropertyPathExtension basePath;
private final ResultSetAccessor resultSet;

/**
* @param identifierProcessing used for converting the
* {@link org.springframework.data.relational.core.sql.SqlIdentifier} from a property to a column label
* @param basePath path from the aggregate root relative to which all properties get resolved.
* @param resultSet the {@link ResultSetAccessor} from which to obtain the actual values.
*/
JdbcPropertyValueProvider(IdentifierProcessing identifierProcessing, PersistentPropertyPathExtension basePath,
JdbcPropertyValueProvider(PersistentPropertyPathExtension basePath,
ResultSetAccessor resultSet) {

this.resultSet = resultSet;
this.basePath = basePath;
this.identifierProcessing = identifierProcessing;
}

@Override
Expand All @@ -62,10 +58,10 @@ public boolean hasProperty(RelationalPersistentProperty property) {
}

private String getColumnName(RelationalPersistentProperty property) {
return basePath.extendBy(property).getColumnAlias().getReference(identifierProcessing);
return basePath.extendBy(property).getColumnAlias().getReference();
}

public JdbcPropertyValueProvider extendBy(RelationalPersistentProperty property) {
return new JdbcPropertyValueProvider(identifierProcessing, basePath.extendBy(property), resultSet);
return new JdbcPropertyValueProvider(basePath.extendBy(property), resultSet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,26 @@
* {@link Map.Entry} is delegated to a {@link RowMapper} provided in the constructor.
*
* @author Jens Schauder
* @author Mikhail Polivakha
*/
class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> {

private final PersistentPropertyPathExtension path;
private final JdbcConverter converter;
private final Identifier identifier;
private final SqlIdentifier keyColumn;
private final IdentifierProcessing identifierProcessing;

MapEntityRowMapper(PersistentPropertyPathExtension path, JdbcConverter converter, Identifier identifier,
SqlIdentifier keyColumn, IdentifierProcessing identifierProcessing) {

MapEntityRowMapper(PersistentPropertyPathExtension path, JdbcConverter converter, Identifier identifier, SqlIdentifier keyColumn) {
this.path = path;
this.converter = converter;
this.identifier = identifier;
this.keyColumn = keyColumn;
this.identifierProcessing = identifierProcessing;
}

@Override
public Map.Entry<Object, T> mapRow(ResultSet rs, int rowNum) throws SQLException {

Object key = rs.getObject(keyColumn.getReference(identifierProcessing));
Object key = rs.getObject(keyColumn.getReference());
return new HashMap.SimpleEntry<>(key, mapEntity(rs, key));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ private Column getVersionColumn() {
}

private String renderReference(SqlIdentifier identifier) {
return identifier.getReference(renderContext.getIdentifierProcessing());
return identifier.getReference();
}

private List<OrderByField> extractOrderByFields(Sort sort) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@
* {@link SqlIdentifier} instead of {@link String} for names.
*
* @author Jens Schauder
* @author Mikhail Polivakha
* @since 2.0
*/
class SqlIdentifierParameterSource extends AbstractSqlParameterSource {

private final IdentifierProcessing identifierProcessing;
private final Set<SqlIdentifier> identifiers = new HashSet<>();
private final Map<String, Object> namesToValues = new HashMap<>();
private final Set<SqlIdentifier> identifiers;
private final Map<String, Object> namesToValues;

SqlIdentifierParameterSource(IdentifierProcessing identifierProcessing) {
this.identifierProcessing = identifierProcessing;
SqlIdentifierParameterSource() {
this.identifiers = new HashSet<>();
this.namesToValues = new HashMap<>();
}

@Override
Expand Down Expand Up @@ -68,7 +69,7 @@ void addValue(SqlIdentifier name, Object value) {
void addValue(SqlIdentifier identifier, Object value, int sqlType) {

identifiers.add(identifier);
String name = identifier.getReference(identifierProcessing);
String name = identifier.getReference();
namesToValues.put(name, value);
registerSqlType(name, sqlType);
}
Expand All @@ -77,7 +78,7 @@ void addAll(SqlIdentifierParameterSource others) {

for (SqlIdentifier identifier : others.getIdentifiers()) {

String name = identifier.getReference(identifierProcessing);
String name = identifier.getReference();
addValue(identifier, others.getValue(name), others.getSqlType(name));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@
*
* @author Jens Schauder
* @author Chirag Tailor
* @author Mikhail Polivakha
* @since 2.4
*/
public class SqlParametersFactory {
private final RelationalMappingContext context;
private final JdbcConverter converter;
private final Dialect dialect;

@Deprecated
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter, Dialect dialect) {
this(context, converter);
}

public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter) {
this.context = context;
this.converter = converter;
this.dialect = dialect;
}

/**
Expand All @@ -72,7 +76,7 @@ <T> SqlIdentifierParameterSource forInsert(T instance, Class<T> domainType, Iden

RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(domainType);
SqlIdentifierParameterSource parameterSource = getParameterSource(instance, persistentEntity, "",
PersistentProperty::isIdProperty, dialect.getIdentifierProcessing());
PersistentProperty::isIdProperty);

identifier.forEach((name, value, type) -> addConvertedPropertyValue(parameterSource, name, value, type));

Expand All @@ -95,8 +99,7 @@ <T> SqlIdentifierParameterSource forInsert(T instance, Class<T> domainType, Iden
*/
<T> SqlIdentifierParameterSource forUpdate(T instance, Class<T> domainType) {

return getParameterSource(instance, getRequiredPersistentEntity(domainType), "", Predicates.includeAll(),
dialect.getIdentifierProcessing());
return getParameterSource(instance, getRequiredPersistentEntity(domainType), "", Predicates.includeAll());
}

/**
Expand All @@ -110,7 +113,7 @@ <T> SqlIdentifierParameterSource forUpdate(T instance, Class<T> domainType) {
*/
<T> SqlIdentifierParameterSource forQueryById(Object id, Class<T> domainType, SqlIdentifier name) {

SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing());
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource();

addConvertedPropertyValue( //
parameterSource, //
Expand All @@ -131,7 +134,7 @@ <T> SqlIdentifierParameterSource forQueryById(Object id, Class<T> domainType, Sq
*/
<T> SqlIdentifierParameterSource forQueryByIds(Iterable<?> ids, Class<T> domainType) {

SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing());
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource();

addConvertedPropertyValuesAsList(parameterSource, getRequiredPersistentEntity(domainType).getRequiredIdProperty(),
ids);
Expand All @@ -148,7 +151,7 @@ <T> SqlIdentifierParameterSource forQueryByIds(Iterable<?> ids, Class<T> domainT
*/
SqlIdentifierParameterSource forQueryByIdentifier(Identifier identifier) {

SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing());
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource();

identifier.toMap()
.forEach((name, value) -> addConvertedPropertyValue(parameterSource, name, value, value.getClass()));
Expand Down Expand Up @@ -228,9 +231,9 @@ private <S> RelationalPersistentEntity<S> getRequiredPersistentEntity(Class<S> d

private <S, T> SqlIdentifierParameterSource getParameterSource(@Nullable S instance,
RelationalPersistentEntity<S> persistentEntity, String prefix,
Predicate<RelationalPersistentProperty> skipProperty, IdentifierProcessing identifierProcessing) {
Predicate<RelationalPersistentProperty> skipProperty) {

SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource(identifierProcessing);
SqlIdentifierParameterSource parameters = new SqlIdentifierParameterSource();

PersistentPropertyAccessor<S> propertyAccessor = instance != null ? persistentEntity.getPropertyAccessor(instance)
: NoValuePropertyAccessor.instance();
Expand All @@ -249,8 +252,7 @@ private <S, T> SqlIdentifierParameterSource getParameterSource(@Nullable S insta
Object value = propertyAccessor.getProperty(property);
RelationalPersistentEntity<?> embeddedEntity = context.getPersistentEntity(property.getType());
SqlIdentifierParameterSource additionalParameters = getParameterSource((T) value,
(RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty,
identifierProcessing);
(RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty);
parameters.addAll(additionalParameters);
} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
* @author Milan Milanov
* @author Myeonghyeon Lee
* @author Chirag Tailor
* @author Mikhail Polivakha
*/
public class MyBatisDataAccessStrategy implements DataAccessStrategy {

private static final Log LOG = LogFactory.getLog(MyBatisDataAccessStrategy.class);
private static final String VERSION_SQL_PARAMETER_NAME_OLD = "___oldOptimisticLockingVersion";

private final SqlSession sqlSession;
private final IdentifierProcessing identifierProcessing;
private NamespaceStrategy namespaceStrategy = NamespaceStrategy.DEFAULT_INSTANCE;

/**
Expand All @@ -92,15 +92,14 @@ public static DataAccessStrategy createCombinedAccessStrategy(RelationalMappingC
// cycle. In order to create it, we need something that allows to defer closing the cycle until all the elements are
// created. That is the purpose of the DelegatingAccessStrategy.
DelegatingDataAccessStrategy delegatingDataAccessStrategy = new DelegatingDataAccessStrategy();
MyBatisDataAccessStrategy myBatisDataAccessStrategy = new MyBatisDataAccessStrategy(sqlSession,
dialect.getIdentifierProcessing());
MyBatisDataAccessStrategy myBatisDataAccessStrategy = new MyBatisDataAccessStrategy(sqlSession, dialect.getIdentifierProcessing());
myBatisDataAccessStrategy.setNamespaceStrategy(namespaceStrategy);

CascadingDataAccessStrategy cascadingDataAccessStrategy = new CascadingDataAccessStrategy(
asList(myBatisDataAccessStrategy, delegatingDataAccessStrategy));

SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(context, converter, dialect);
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter, dialect);
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter);
InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(operations,
new BatchJdbcOperations(operations.getJdbcOperations()), dialect);
DefaultDataAccessStrategy defaultDataAccessStrategy = new DefaultDataAccessStrategy( //
Expand All @@ -127,13 +126,17 @@ public static DataAccessStrategy createCombinedAccessStrategy(RelationalMappingC
* to create such a {@link DataAccessStrategy}.
*
* @param sqlSession Must be non {@literal null}.
* @param identifierProcessing the {@link IdentifierProcessing} applied to {@link SqlIdentifier} instances in order to
* turn them into {@link String}
*
* @deprecated because identifierProcessing now will not be considered in the process of applying it to {@link SqlIdentifier},
* use {@link MyBatisDataAccessStrategy(SqlSession)} constructor instead
*/
@Deprecated
public MyBatisDataAccessStrategy(SqlSession sqlSession, IdentifierProcessing identifierProcessing) {
this(sqlSession);
}

public MyBatisDataAccessStrategy(SqlSession sqlSession) {
this.sqlSession = sqlSession;
this.identifierProcessing = identifierProcessing;
}

/**
Expand Down Expand Up @@ -328,12 +331,6 @@ public long count(Class<?> domainType) {
return sqlSession().selectOne(statement, parameter);
}

private Map<String, Object> convertToParameterMap(Map<SqlIdentifier, Object> additionalParameters) {

return additionalParameters.entrySet().stream() //
.collect(Collectors.toMap(e -> e.getKey().toSql(identifierProcessing), Map.Entry::getValue));
}

private String namespace(Class<?> domainType) {
return this.namespaceStrategy.getNamespace(domainType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public JdbcAggregateTemplate jdbcAggregateTemplate(ApplicationContext applicatio
public DataAccessStrategy dataAccessStrategyBean(NamedParameterJdbcOperations operations, JdbcConverter jdbcConverter,
JdbcMappingContext context, Dialect dialect) {
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context, jdbcConverter, dialect), context,
jdbcConverter, operations, new SqlParametersFactory(context, jdbcConverter, dialect),
jdbcConverter, operations, new SqlParametersFactory(context, jdbcConverter),
new InsertStrategyFactory(operations, new BatchJdbcOperations(operations.getJdbcOperations()), dialect));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ public void afterPropertiesSet() {

SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(this.mappingContext, this.converter,
this.dialect);
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(this.mappingContext, this.converter,
this.dialect);
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(this.mappingContext, this.converter);
InsertStrategyFactory insertStrategyFactory = new InsertStrategyFactory(this.operations,
new BatchJdbcOperations(this.operations.getJdbcOperations()), this.dialect);
return new DefaultDataAccessStrategy(sqlGeneratorSource, this.mappingContext, this.converter,
Expand Down
Loading