smoldachev commented on a change in pull request #7381: It is needed to set
used cache for Spring Data dynamically
URL: https://github.com/apache/ignite/pull/7381#discussion_r376263674
##########
File path:
modules/spring-data-2.0/src/main/java/org/apache/ignite/springdata20/repository/support/IgniteRepositoryFactory.java
##########
@@ -107,11 +118,38 @@ public IgniteRepositoryFactory(String springCfgPath) {
Assert.hasText(annotation.cacheName(), "Set a name of an Apache Ignite
cache using @RepositoryConfig " +
"annotation to map this repository to the underlying cache.");
+ String cacheName = null;
+ if (!looksLikeExpression(annotation.cacheName())) {
+ cacheName = annotation.cacheName();
+ }
+ else {
+ SpelExpressionParser parser = new SpelExpressionParser();
+ Expression expression =
parser.parseExpression(annotation.cacheName());
+ StandardEvaluationContext ec = new StandardEvaluationContext();
+ ec.setBeanResolver(new
BeanFactoryResolver(ctx.getAutowireCapableBeanFactory()));
+ cacheName = (String)expression.getValue(ec);
+ }
+ repoToCache.put(repoItf, cacheName);
repoToCache.put(repoItf, annotation.cacheName());
return super.getRepositoryMetadata(repoItf);
}
+ /**
+ * The method tryes to identify SpEL extression
+ * @see <a
href="https://docs.spring.io/spring/docs/5.0.16.RELEASE/spring-framework-reference/core.html#expressions">SpEL</a>
+ * @param expression
+ * @return
+ */
+
+ private boolean looksLikeExpression(String expression) {
Review comment:
Maybe rename to: isSpelExpression ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services