|
|
|
@ -42,17 +42,21 @@ import org.springframework.util.Assert; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Jens Schauder |
|
|
|
* @author Jens Schauder |
|
|
|
* @author Chirag Tailor |
|
|
|
* @author Chirag Tailor |
|
|
|
|
|
|
|
* @author Mikhail Polivakha |
|
|
|
* @since 2.4 |
|
|
|
* @since 2.4 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class SqlParametersFactory { |
|
|
|
public class SqlParametersFactory { |
|
|
|
private final RelationalMappingContext context; |
|
|
|
private final RelationalMappingContext context; |
|
|
|
private final JdbcConverter converter; |
|
|
|
private final JdbcConverter converter; |
|
|
|
private final Dialect dialect; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter, Dialect dialect) { |
|
|
|
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter, Dialect dialect) { |
|
|
|
|
|
|
|
this(context, converter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter) { |
|
|
|
this.context = context; |
|
|
|
this.context = context; |
|
|
|
this.converter = converter; |
|
|
|
this.converter = converter; |
|
|
|
this.dialect = dialect; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -72,7 +76,7 @@ public class SqlParametersFactory { |
|
|
|
|
|
|
|
|
|
|
|
RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(domainType); |
|
|
|
RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(domainType); |
|
|
|
SqlIdentifierParameterSource parameterSource = getParameterSource(instance, persistentEntity, "", |
|
|
|
SqlIdentifierParameterSource parameterSource = getParameterSource(instance, persistentEntity, "", |
|
|
|
PersistentProperty::isIdProperty, dialect.getIdentifierProcessing()); |
|
|
|
PersistentProperty::isIdProperty); |
|
|
|
|
|
|
|
|
|
|
|
identifier.forEach((name, value, type) -> addConvertedPropertyValue(parameterSource, name, value, type)); |
|
|
|
identifier.forEach((name, value, type) -> addConvertedPropertyValue(parameterSource, name, value, type)); |
|
|
|
|
|
|
|
|
|
|
|
@ -96,7 +100,7 @@ public class SqlParametersFactory { |
|
|
|
<T> SqlIdentifierParameterSource forUpdate(T instance, Class<T> domainType) { |
|
|
|
<T> SqlIdentifierParameterSource forUpdate(T instance, Class<T> domainType) { |
|
|
|
|
|
|
|
|
|
|
|
return getParameterSource(instance, getRequiredPersistentEntity(domainType), "", |
|
|
|
return getParameterSource(instance, getRequiredPersistentEntity(domainType), "", |
|
|
|
RelationalPersistentProperty::isInsertOnly, dialect.getIdentifierProcessing()); |
|
|
|
RelationalPersistentProperty::isInsertOnly); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -110,7 +114,7 @@ public class SqlParametersFactory { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
<T> SqlIdentifierParameterSource forQueryById(Object id, Class<T> domainType, SqlIdentifier name) { |
|
|
|
<T> SqlIdentifierParameterSource forQueryById(Object id, Class<T> domainType, SqlIdentifier name) { |
|
|
|
|
|
|
|
|
|
|
|
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing()); |
|
|
|
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(); |
|
|
|
|
|
|
|
|
|
|
|
addConvertedPropertyValue( //
|
|
|
|
addConvertedPropertyValue( //
|
|
|
|
parameterSource, //
|
|
|
|
parameterSource, //
|
|
|
|
@ -131,7 +135,7 @@ public class SqlParametersFactory { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
<T> SqlIdentifierParameterSource forQueryByIds(Iterable<?> ids, Class<T> domainType) { |
|
|
|
<T> SqlIdentifierParameterSource forQueryByIds(Iterable<?> ids, Class<T> domainType) { |
|
|
|
|
|
|
|
|
|
|
|
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing()); |
|
|
|
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(); |
|
|
|
|
|
|
|
|
|
|
|
addConvertedPropertyValuesAsList(parameterSource, getRequiredPersistentEntity(domainType).getRequiredIdProperty(), |
|
|
|
addConvertedPropertyValuesAsList(parameterSource, getRequiredPersistentEntity(domainType).getRequiredIdProperty(), |
|
|
|
ids); |
|
|
|
ids); |
|
|
|
@ -148,7 +152,7 @@ public class SqlParametersFactory { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
SqlIdentifierParameterSource forQueryByIdentifier(Identifier identifier) { |
|
|
|
SqlIdentifierParameterSource forQueryByIdentifier(Identifier identifier) { |
|
|
|
|
|
|
|
|
|
|
|
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(dialect.getIdentifierProcessing()); |
|
|
|
SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(); |
|
|
|
|
|
|
|
|
|
|
|
identifier.toMap() |
|
|
|
identifier.toMap() |
|
|
|
.forEach((name, value) -> addConvertedPropertyValue(parameterSource, name, value, value.getClass())); |
|
|
|
.forEach((name, value) -> addConvertedPropertyValue(parameterSource, name, value, value.getClass())); |
|
|
|
@ -228,9 +232,9 @@ public class SqlParametersFactory { |
|
|
|
|
|
|
|
|
|
|
|
private <S, T> SqlIdentifierParameterSource getParameterSource(@Nullable S instance, |
|
|
|
private <S, T> SqlIdentifierParameterSource getParameterSource(@Nullable S instance, |
|
|
|
RelationalPersistentEntity<S> persistentEntity, String prefix, |
|
|
|
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) |
|
|
|
PersistentPropertyAccessor<S> propertyAccessor = instance != null ? persistentEntity.getPropertyAccessor(instance) |
|
|
|
: NoValuePropertyAccessor.instance(); |
|
|
|
: NoValuePropertyAccessor.instance(); |
|
|
|
@ -249,8 +253,7 @@ public class SqlParametersFactory { |
|
|
|
Object value = propertyAccessor.getProperty(property); |
|
|
|
Object value = propertyAccessor.getProperty(property); |
|
|
|
RelationalPersistentEntity<?> embeddedEntity = context.getPersistentEntity(property.getType()); |
|
|
|
RelationalPersistentEntity<?> embeddedEntity = context.getPersistentEntity(property.getType()); |
|
|
|
SqlIdentifierParameterSource additionalParameters = getParameterSource((T) value, |
|
|
|
SqlIdentifierParameterSource additionalParameters = getParameterSource((T) value, |
|
|
|
(RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty, |
|
|
|
(RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty); |
|
|
|
identifierProcessing); |
|
|
|
|
|
|
|
parameters.addAll(additionalParameters); |
|
|
|
parameters.addAll(additionalParameters); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|