Skip to content

Commit ef49606

Browse files
committed
Remove @Autowired for SpelExpressionResultSanitizer. Allow for one to inject a custom sanitizer in the RelationMappingContext and JdbcMappingContext classes.
1 parent 2ce70d3 commit ef49606

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/JdbcMappingContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ protected RelationalPersistentProperty createPersistentProperty(Property propert
8282
BasicJdbcPersistentProperty persistentProperty = new BasicJdbcPersistentProperty(property, owner, simpleTypeHolder,
8383
this.getNamingStrategy());
8484
persistentProperty.setForceQuote(isForceQuote());
85+
persistentProperty.setSpelExpressionProcessor(getSpelExpressionProcessor());
8586
return persistentProperty;
8687
}
8788

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentProperty.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ public BasicRelationalPersistentProperty(Property property, PersistentEntity<?,
112112
.map(this::createSqlIdentifier) //
113113
.orElseGet(() -> createDerivedSqlIdentifier(namingStrategy.getKeyColumn(this))));
114114
}
115+
public SpelExpressionProcessor getSpelExpressionProcessor() {
116+
return spelExpressionProcessor;
117+
}
118+
119+
public void setSpelExpressionProcessor(SpelExpressionProcessor spelExpressionProcessor) {
120+
this.spelExpressionProcessor = spelExpressionProcessor;
121+
}
115122

116123
private SqlIdentifier createSqlIdentifier(String name) {
117124
return isForceQuote() ? SqlIdentifier.quoted(name) : SqlIdentifier.unquoted(name);

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class RelationalMappingContext
3636

3737
private final NamingStrategy namingStrategy;
3838
private boolean forceQuote = true;
39+
private SpelExpressionProcessor spelExpressionProcessor = new SpelExpressionProcessor();
3940

4041
/**
4142
* Creates a new {@link RelationalMappingContext}.
@@ -77,12 +78,21 @@ public void setForceQuote(boolean forceQuote) {
7778
this.forceQuote = forceQuote;
7879
}
7980

81+
public SpelExpressionProcessor getSpelExpressionProcessor() {
82+
return spelExpressionProcessor;
83+
}
84+
85+
public void setSpelExpressionProcessor(SpelExpressionProcessor spelExpressionProcessor) {
86+
this.spelExpressionProcessor = spelExpressionProcessor;
87+
}
88+
8089
@Override
8190
protected <T> RelationalPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
8291

8392
RelationalPersistentEntityImpl<T> entity = new RelationalPersistentEntityImpl<>(typeInformation,
8493
this.namingStrategy);
8594
entity.setForceQuote(isForceQuote());
95+
entity.setSpelExpressionProcessor(getSpelExpressionProcessor());
8696

8797
return entity;
8898
}
@@ -94,6 +104,7 @@ protected RelationalPersistentProperty createPersistentProperty(Property propert
94104
BasicRelationalPersistentProperty persistentProperty = new BasicRelationalPersistentProperty(property, owner,
95105
simpleTypeHolder, this.namingStrategy);
96106
persistentProperty.setForceQuote(isForceQuote());
107+
persistentProperty.setSpelExpressionProcessor(getSpelExpressionProcessor());
97108

98109
return persistentProperty;
99110
}

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalPersistentEntityImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class RelationalPersistentEntityImpl<T> extends BasicPersistentEntity<T, Relatio
6565
.map(this::createSqlIdentifier));
6666
}
6767

68+
public SpelExpressionProcessor getSpelExpressionProcessor() {
69+
return spelExpressionProcessor;
70+
}
71+
72+
public void setSpelExpressionProcessor(SpelExpressionProcessor spelExpressionProcessor) {
73+
this.spelExpressionProcessor = spelExpressionProcessor;
74+
}
75+
6876
private SqlIdentifier createSqlIdentifier(String name) {
6977
return isForceQuote() ? SqlIdentifier.quoted(name) : SqlIdentifier.unquoted(name);
7078
}

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/SpelExpressionProcessor.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
* and strips out any other characters.
1818
*
1919
* Custom sanitization (if desired) can be achieved by creating a class that implements
20-
* the {@link #SpelExpressionResultSanitizer} interface and configuring a spelExpressionResultSanitizer
21-
* Bean.
20+
* the {@link #SpelExpressionResultSanitizer} interface and then invoking the
21+
* {@link #setSpelExpressionResultSanitizer(SpelExpressionResultSanitizer)} method.
2222
*
2323
* @author Kurt Niemi
2424
* @since 3.1
2525
*/
2626
public class SpelExpressionProcessor {
27-
@Autowired(required = false)
2827
private SpelExpressionResultSanitizer spelExpressionResultSanitizer;
2928
private StandardEvaluationContext evalContext = new StandardEvaluationContext();
3029
private SpelExpressionParser parser = new SpelExpressionParser();
@@ -65,7 +64,7 @@ protected boolean isSpellExpression(String expression) {
6564

6665
return false;
6766
}
68-
private SpelExpressionResultSanitizer getSpelExpressionResultSanitizer() {
67+
public SpelExpressionResultSanitizer getSpelExpressionResultSanitizer() {
6968

7069
if (this.spelExpressionResultSanitizer == null) {
7170
this.spelExpressionResultSanitizer = new SpelExpressionResultSanitizer() {
@@ -79,4 +78,9 @@ public String sanitize(String result) {
7978
}
8079
return this.spelExpressionResultSanitizer;
8180
}
81+
82+
public void setSpelExpressionResultSanitizer(SpelExpressionResultSanitizer spelExpressionResultSanitizer) {
83+
this.spelExpressionResultSanitizer = spelExpressionResultSanitizer;
84+
}
85+
8286
}

0 commit comments

Comments
 (0)