This is an automated email from the ASF dual-hosted git repository.

ascherbakov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 465cc44  IGNITE-12582 Add Spring EL support in Spring Data. - Fixes 
#7411.
465cc44 is described below

commit 465cc444d0bf69f230a7c6c9e429ff69851cba62
Author: Sergey Chernolyas <[email protected]>
AuthorDate: Thu Feb 13 11:36:21 2020 +0300

    IGNITE-12582 Add Spring EL support in Spring Data. - Fixes #7411.
    
    Signed-off-by: Aleksei Scherbakov <[email protected]>
---
 .../support/IgniteRepositoryFactory.java           |  55 +++++++++-
 .../support/IgniteRepositoryFactoryBean.java       |   6 +-
 .../IgniteSpringDataCrudSelfExpressionTest.java    | 112 +++++++++++++++++++++
 .../springdata/misc/ApplicationConfiguration.java  |  12 +++
 .../misc/CacheNamesBean.java}                      |  31 +++---
 .../misc/PersonExpressionRepository.java}          |  18 ++--
 .../testsuites/IgniteSpringData2TestSuite.java     |   4 +-
 .../support/IgniteRepositoryFactory.java           |  55 +++++++++-
 .../support/IgniteRepositoryFactoryBean.java       |   6 +-
 .../IgniteSpringDataCrudSelfExpressionTest.java    | 112 +++++++++++++++++++++
 .../springdata/misc/ApplicationConfiguration.java  |  12 +++
 .../ignite/springdata/misc/CacheNamesBean.java}    |  30 +++---
 .../misc/PersonExpressionRepository.java}          |  18 ++--
 .../testsuites/IgniteSpringData22TestSuite.java    |   4 +-
 14 files changed, 409 insertions(+), 66 deletions(-)

diff --git 
a/modules/spring-data-2.0/src/main/java/org/apache/ignite/springdata20/repository/support/IgniteRepositoryFactory.java
 
b/modules/spring-data-2.0/src/main/java/org/apache/ignite/springdata20/repository/support/IgniteRepositoryFactory.java
index 09c8735..f1ce9e3 100644
--- 
a/modules/spring-data-2.0/src/main/java/org/apache/ignite/springdata20/repository/support/IgniteRepositoryFactory.java
+++ 
b/modules/spring-data-2.0/src/main/java/org/apache/ignite/springdata20/repository/support/IgniteRepositoryFactory.java
@@ -28,6 +28,11 @@ import 
org.apache.ignite.springdata20.repository.config.RepositoryConfig;
 import org.apache.ignite.springdata20.repository.query.IgniteQuery;
 import org.apache.ignite.springdata20.repository.query.IgniteQueryGenerator;
 import org.apache.ignite.springdata20.repository.query.IgniteRepositoryQuery;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.beans.factory.config.BeanExpressionContext;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.expression.StandardBeanExpressionResolver;
 import org.springframework.data.repository.core.EntityInformation;
 import org.springframework.data.repository.core.RepositoryInformation;
 import org.springframework.data.repository.core.RepositoryMetadata;
@@ -45,6 +50,18 @@ public class IgniteRepositoryFactory extends 
RepositoryFactorySupport {
     /** Ignite instance */
     private Ignite ignite;
 
+    /** Spring application context */
+    private ApplicationContext ctx;
+
+    /** Spring application bean factory */
+    private DefaultListableBeanFactory beanFactory;
+
+    /** Spring application expression resolver */
+    private StandardBeanExpressionResolver resolver = new 
StandardBeanExpressionResolver();
+
+    /** Spring application bean expression context */
+    private BeanExpressionContext beanExpressionContext;
+
     /** Mapping of a repository to a cache. */
     private final Map<Class<?>, String> repoToCache = new HashMap<>();
 
@@ -53,8 +70,14 @@ public class IgniteRepositoryFactory extends 
RepositoryFactorySupport {
      *
      * @param ignite
      */
-    public IgniteRepositoryFactory(Ignite ignite) {
+    public IgniteRepositoryFactory(Ignite ignite, ApplicationContext ctx) {
         this.ignite = ignite;
+
+        this.ctx = ctx;
+
+        this.beanFactory = new 
DefaultListableBeanFactory(ctx.getAutowireCapableBeanFactory());
+
+        this.beanExpressionContext = new BeanExpressionContext(beanFactory, 
null);
     }
 
     /**
@@ -63,8 +86,14 @@ public class IgniteRepositoryFactory extends 
RepositoryFactorySupport {
      *
      * @param cfg Ignite configuration.
      */
-    public IgniteRepositoryFactory(IgniteConfiguration cfg) {
+    public IgniteRepositoryFactory(IgniteConfiguration cfg, ApplicationContext 
ctx) {
         this.ignite = Ignition.start(cfg);
+
+        this.ctx = ctx;
+
+        this.beanFactory = new 
DefaultListableBeanFactory(ctx.getAutowireCapableBeanFactory());
+
+        this.beanExpressionContext = new BeanExpressionContext(beanFactory, 
null);
     }
 
     /**
@@ -73,8 +102,14 @@ public class IgniteRepositoryFactory extends 
RepositoryFactorySupport {
      *
      * @param springCfgPath A path to Ignite configuration.
      */
-    public IgniteRepositoryFactory(String springCfgPath) {
+    public IgniteRepositoryFactory(String springCfgPath, ApplicationContext 
ctx) {
         this.ignite = Ignition.start(springCfgPath);
+
+        this.ctx = ctx;
+
+        this.beanFactory = new 
DefaultListableBeanFactory(ctx.getAutowireCapableBeanFactory());
+
+        this.beanExpressionContext = new BeanExpressionContext(beanFactory, 
null);
     }
 
     /** {@inheritDoc} */
@@ -108,11 +143,23 @@ public class IgniteRepositoryFactory extends 
RepositoryFactorySupport {
         Assert.hasText(annotation.cacheName(), "Set a name of an Apache Ignite 
cache using @RepositoryConfig " +
             "annotation to map this repository to the underlying cache.");
 
-        repoToCache.put(repoItf, annotation.cacheName());
+        String cacheName = evaluateExpression(annotation.cacheName());
+
+        repoToCache.put(repoItf, cacheName);
 
         return super.getRepositoryMetadata(repoItf);
     }
 
+    /**
+     *  evaluate the SpEL expression
+     *
+     * @param spelExpression SpEL expression
+     * @return the result of execution of the SpEL expression
+     */
+    @NotNull private String evaluateExpression(String spelExpression) {
+        return (String)resolver.evaluate(spelExpression, 
beanExpressionContext);
+    }
+
     /** {@inheritDoc} */
     @Override protected Object getTargetRepository(RepositoryInformation 
metadata) {
         return getTargetRepositoryViaReflection(metadata,
diff --git 
a/modules/spring-data-2.0/src/main/java/org/apache/ignite/springdata20/repository/support/IgniteRepositoryFactoryBean.java
 
b/modules/spring-data-2.0/src/main/java/org/apache/ignite/springdata20/repository/support/IgniteRepositoryFactoryBean.java
index 36c3b65..a4be424 100644
--- 
a/modules/spring-data-2.0/src/main/java/org/apache/ignite/springdata20/repository/support/IgniteRepositoryFactoryBean.java
+++ 
b/modules/spring-data-2.0/src/main/java/org/apache/ignite/springdata20/repository/support/IgniteRepositoryFactoryBean.java
@@ -66,19 +66,19 @@ public class IgniteRepositoryFactoryBean<T extends 
Repository<S, ID>, S, ID exte
         try {
             Ignite ignite = (Ignite)ctx.getBean("igniteInstance");
 
-            return new IgniteRepositoryFactory(ignite);
+            return new IgniteRepositoryFactory(ignite, ctx );
         }
         catch (BeansException ex) {
             try {
                 IgniteConfiguration cfg = 
(IgniteConfiguration)ctx.getBean("igniteCfg");
 
-                return new IgniteRepositoryFactory(cfg);
+                return new IgniteRepositoryFactory(cfg, ctx) ;
             }
             catch (BeansException ex2) {
                 try {
                     String path = (String)ctx.getBean("igniteSpringCfgPath");
 
-                    return new IgniteRepositoryFactory(path);
+                    return new IgniteRepositoryFactory(path, ctx );
                 }
                 catch (BeansException ex3) {
                     throw new IgniteException("Failed to initialize Ignite 
repository factory. Ignite instance or" +
diff --git 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCrudSelfExpressionTest.java
 
b/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCrudSelfExpressionTest.java
new file mode 100644
index 0000000..c572ef0
--- /dev/null
+++ 
b/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCrudSelfExpressionTest.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.springdata;
+
+import org.apache.ignite.springdata.misc.ApplicationConfiguration;
+import org.apache.ignite.springdata.misc.Person;
+import org.apache.ignite.springdata.misc.PersonExpressionRepository;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import 
org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+/**
+ * Test with using repository which is configured by Spring EL
+ */
+public class IgniteSpringDataCrudSelfExpressionTest extends 
GridCommonAbstractTest {
+    /** Repository. */
+    private static PersonExpressionRepository repo;
+
+    /** Context. */
+    private static AnnotationConfigApplicationContext ctx;
+
+    /** Number of entries to store */
+    private static int CACHE_SIZE = 1000;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        ctx = new AnnotationConfigApplicationContext();
+
+        ctx.register(ApplicationConfiguration.class);
+
+        ctx.refresh();
+
+        repo = ctx.getBean(PersonExpressionRepository.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        fillInRepository();
+
+        assertEquals(CACHE_SIZE, repo.count());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        repo.deleteAll();
+
+        assertEquals(0, repo.count());
+
+        super.afterTest();
+    }
+
+    /**
+     *
+     */
+    private void fillInRepository() {
+        for (int i = 0; i < CACHE_SIZE - 5; i++) {
+            repo.save(i, new Person("person" + Integer.toHexString(i),
+                "lastName" + Integer.toHexString((i + 16) % 256)));
+        }
+
+        repo.save((int) repo.count(), new Person("uniquePerson", 
"uniqueLastName"));
+        repo.save((int) repo.count(), new Person("nonUniquePerson", 
"nonUniqueLastName"));
+        repo.save((int) repo.count(), new Person("nonUniquePerson", 
"nonUniqueLastName"));
+        repo.save((int) repo.count(), new Person("nonUniquePerson", 
"nonUniqueLastName"));
+        repo.save((int) repo.count(), new Person("nonUniquePerson", 
"nonUniqueLastName"));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        ctx.destroy();
+    }
+
+    @Test
+    public void testPutGet() {
+        Person person = new Person("some_name", "some_surname");
+
+        int id = CACHE_SIZE + 1;
+
+        assertEquals(person, repo.save(id, person));
+
+        assertTrue(repo.existsById(id));
+
+        assertEquals(person, repo.findById(id).get());
+
+        try {
+            repo.save(person);
+
+            fail("Managed to save a Person without ID");
+        }
+        catch (UnsupportedOperationException e) {
+            //excepted
+        }
+    }
+}
diff --git 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java
 
b/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java
index 1a7c01e..e700c9d 100644
--- 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java
+++ 
b/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java
@@ -35,6 +35,18 @@ import 
org.apache.ignite.springdata20.repository.config.EnableIgniteRepositories
 public class ApplicationConfiguration {
 
     /**
+     * The bean with cache names
+     */
+    @Bean
+    public CacheNamesBean cacheNames() {
+        CacheNamesBean bean = new CacheNamesBean();
+
+        bean.setPersonCacheName("PersonCache");
+
+        return bean;
+    }
+
+    /**
      * Ignite instance bean.
      */
     @Bean
diff --git 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
 
b/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/misc/CacheNamesBean.java
similarity index 64%
copy from 
modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
copy to 
modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/misc/CacheNamesBean.java
index 4b7d7f3..ae041ff 100644
--- 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
+++ 
b/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/misc/CacheNamesBean.java
@@ -15,20 +15,25 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.testsuites;
-
-import org.apache.ignite.springdata.IgniteSpringDataCrudSelfTest;
-import org.apache.ignite.springdata.IgniteSpringDataQueriesSelfTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
+package org.apache.ignite.springdata.misc;
 
 /**
- * Ignite Spring Data 2.0 test suite.
+ * The bean with cache names
  */
-@RunWith(Suite.class)
[email protected]({
-    IgniteSpringDataCrudSelfTest.class,
-    IgniteSpringDataQueriesSelfTest.class
-})
-public class IgniteSpringData2TestSuite {
+public class CacheNamesBean {
+
+    private String personCacheName;
+
+    /**
+     * Get name of cache for persons
+     *
+     * @return name of cache
+     */
+    public String getPersonCacheName() {
+        return personCacheName;
+    }
+
+    public void setPersonCacheName(String personCacheName) {
+        this.personCacheName = personCacheName;
+    }
 }
diff --git 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
 
b/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/misc/PersonExpressionRepository.java
similarity index 64%
copy from 
modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
copy to 
modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/misc/PersonExpressionRepository.java
index 4b7d7f3..d8b89c5 100644
--- 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
+++ 
b/modules/spring-data-2.0/src/test/java/org/apache/ignite/springdata/misc/PersonExpressionRepository.java
@@ -15,20 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.testsuites;
+package org.apache.ignite.springdata.misc;
 
-import org.apache.ignite.springdata.IgniteSpringDataCrudSelfTest;
-import org.apache.ignite.springdata.IgniteSpringDataQueriesSelfTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
+import org.apache.ignite.springdata20.repository.IgniteRepository;
+import org.apache.ignite.springdata20.repository.config.RepositoryConfig;
 
 /**
- * Ignite Spring Data 2.0 test suite.
+ *
  */
-@RunWith(Suite.class)
[email protected]({
-    IgniteSpringDataCrudSelfTest.class,
-    IgniteSpringDataQueriesSelfTest.class
-})
-public class IgniteSpringData2TestSuite {
+@RepositoryConfig(cacheName = "@cacheNames.personCacheName")
+public interface PersonExpressionRepository  extends IgniteRepository<Person, 
Integer> {
 }
diff --git 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
 
b/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
index 4b7d7f3..fdfbbb8 100644
--- 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
+++ 
b/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.testsuites;
 
+import org.apache.ignite.springdata.IgniteSpringDataCrudSelfExpressionTest;
 import org.apache.ignite.springdata.IgniteSpringDataCrudSelfTest;
 import org.apache.ignite.springdata.IgniteSpringDataQueriesSelfTest;
 import org.junit.runner.RunWith;
@@ -28,7 +29,8 @@ import org.junit.runners.Suite;
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
     IgniteSpringDataCrudSelfTest.class,
-    IgniteSpringDataQueriesSelfTest.class
+    IgniteSpringDataQueriesSelfTest.class,
+    IgniteSpringDataCrudSelfExpressionTest.class
 })
 public class IgniteSpringData2TestSuite {
 }
diff --git 
a/modules/spring-data-2.2/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactory.java
 
b/modules/spring-data-2.2/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactory.java
index 63897fd..6625ebc 100644
--- 
a/modules/spring-data-2.2/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactory.java
+++ 
b/modules/spring-data-2.2/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactory.java
@@ -28,6 +28,11 @@ import 
org.apache.ignite.springdata22.repository.config.RepositoryConfig;
 import org.apache.ignite.springdata22.repository.query.IgniteQuery;
 import org.apache.ignite.springdata22.repository.query.IgniteQueryGenerator;
 import org.apache.ignite.springdata22.repository.query.IgniteRepositoryQuery;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.beans.factory.config.BeanExpressionContext;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.expression.StandardBeanExpressionResolver;
 import org.springframework.data.repository.core.EntityInformation;
 import org.springframework.data.repository.core.RepositoryInformation;
 import org.springframework.data.repository.core.RepositoryMetadata;
@@ -45,6 +50,18 @@ public class IgniteRepositoryFactory extends 
RepositoryFactorySupport {
     /** Ignite instance */
     private Ignite ignite;
 
+    /** Spring application context */
+    private ApplicationContext ctx;
+
+    /** Spring application bean factory */
+    private DefaultListableBeanFactory beanFactory;
+
+    /** Spring application expression resolver */
+    private StandardBeanExpressionResolver resolver = new 
StandardBeanExpressionResolver();
+
+    /** Spring application bean expression context */
+    private BeanExpressionContext beanExpressionContext;
+
     /** Mapping of a repository to a cache. */
     private final Map<Class<?>, String> repoToCache = new HashMap<>();
 
@@ -53,8 +70,14 @@ public class IgniteRepositoryFactory extends 
RepositoryFactorySupport {
      *
      * @param ignite
      */
-    public IgniteRepositoryFactory(Ignite ignite) {
+    public IgniteRepositoryFactory(Ignite ignite, ApplicationContext ctx) {
         this.ignite = ignite;
+
+        this.ctx = ctx;
+
+        this.beanFactory = new 
DefaultListableBeanFactory(ctx.getAutowireCapableBeanFactory());
+
+        this.beanExpressionContext = new BeanExpressionContext(beanFactory, 
null);
     }
 
     /**
@@ -63,8 +86,14 @@ public class IgniteRepositoryFactory extends 
RepositoryFactorySupport {
      *
      * @param cfg Ignite configuration.
      */
-    public IgniteRepositoryFactory(IgniteConfiguration cfg) {
+    public IgniteRepositoryFactory(IgniteConfiguration cfg, ApplicationContext 
ctx) {
         this.ignite = Ignition.start(cfg);
+
+        this.ctx = ctx;
+
+        this.beanFactory = new 
DefaultListableBeanFactory(ctx.getAutowireCapableBeanFactory());
+
+        this.beanExpressionContext = new BeanExpressionContext(beanFactory, 
null);
     }
 
     /**
@@ -73,8 +102,14 @@ public class IgniteRepositoryFactory extends 
RepositoryFactorySupport {
      *
      * @param springCfgPath A path to Ignite configuration.
      */
-    public IgniteRepositoryFactory(String springCfgPath) {
+    public IgniteRepositoryFactory(String springCfgPath, ApplicationContext 
ctx) {
         this.ignite = Ignition.start(springCfgPath);
+
+        this.ctx = ctx;
+
+        this.beanFactory = new 
DefaultListableBeanFactory(ctx.getAutowireCapableBeanFactory());
+
+        this.beanExpressionContext = new BeanExpressionContext(beanFactory, 
null);
     }
 
     /** {@inheritDoc} */
@@ -108,11 +143,23 @@ public class IgniteRepositoryFactory extends 
RepositoryFactorySupport {
         Assert.hasText(annotation.cacheName(), "Set a name of an Apache Ignite 
cache using @RepositoryConfig " +
             "annotation to map this repository to the underlying cache.");
 
-        repoToCache.put(repoItf, annotation.cacheName());
+        String cacheName = evaluateExpression(annotation.cacheName());
+
+        repoToCache.put(repoItf, cacheName);
 
         return super.getRepositoryMetadata(repoItf);
     }
 
+    /**
+     *  evaluate the SpEL expression
+     *
+     * @param spelExpression SpEL expression
+     * @return the result of execution of the SpEL expression
+     */
+    @NotNull private String evaluateExpression(String spelExpression) {
+        return (String)resolver.evaluate(spelExpression, 
beanExpressionContext);
+    }
+
     /** {@inheritDoc} */
     @Override protected Object getTargetRepository(RepositoryInformation 
metadata) {
         return getTargetRepositoryViaReflection(metadata,
diff --git 
a/modules/spring-data-2.2/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactoryBean.java
 
b/modules/spring-data-2.2/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactoryBean.java
index aea817d..57809c4 100644
--- 
a/modules/spring-data-2.2/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactoryBean.java
+++ 
b/modules/spring-data-2.2/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactoryBean.java
@@ -66,19 +66,19 @@ public class IgniteRepositoryFactoryBean<T extends 
Repository<S, ID>, S, ID exte
         try {
             Ignite ignite = (Ignite)ctx.getBean("igniteInstance");
 
-            return new IgniteRepositoryFactory(ignite);
+            return new IgniteRepositoryFactory(ignite, ctx );
         }
         catch (BeansException ex) {
             try {
                 IgniteConfiguration cfg = 
(IgniteConfiguration)ctx.getBean("igniteCfg");
 
-                return new IgniteRepositoryFactory(cfg);
+                return new IgniteRepositoryFactory(cfg, ctx );
             }
             catch (BeansException ex2) {
                 try {
                     String path = (String)ctx.getBean("igniteSpringCfgPath");
 
-                    return new IgniteRepositoryFactory(path);
+                    return new IgniteRepositoryFactory(path, ctx );
                 }
                 catch (BeansException ex3) {
                     throw new IgniteException("Failed to initialize Ignite 
repository factory. Ignite instance or" +
diff --git 
a/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCrudSelfExpressionTest.java
 
b/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCrudSelfExpressionTest.java
new file mode 100644
index 0000000..c572ef0
--- /dev/null
+++ 
b/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCrudSelfExpressionTest.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.springdata;
+
+import org.apache.ignite.springdata.misc.ApplicationConfiguration;
+import org.apache.ignite.springdata.misc.Person;
+import org.apache.ignite.springdata.misc.PersonExpressionRepository;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import 
org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+/**
+ * Test with using repository which is configured by Spring EL
+ */
+public class IgniteSpringDataCrudSelfExpressionTest extends 
GridCommonAbstractTest {
+    /** Repository. */
+    private static PersonExpressionRepository repo;
+
+    /** Context. */
+    private static AnnotationConfigApplicationContext ctx;
+
+    /** Number of entries to store */
+    private static int CACHE_SIZE = 1000;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        ctx = new AnnotationConfigApplicationContext();
+
+        ctx.register(ApplicationConfiguration.class);
+
+        ctx.refresh();
+
+        repo = ctx.getBean(PersonExpressionRepository.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        fillInRepository();
+
+        assertEquals(CACHE_SIZE, repo.count());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        repo.deleteAll();
+
+        assertEquals(0, repo.count());
+
+        super.afterTest();
+    }
+
+    /**
+     *
+     */
+    private void fillInRepository() {
+        for (int i = 0; i < CACHE_SIZE - 5; i++) {
+            repo.save(i, new Person("person" + Integer.toHexString(i),
+                "lastName" + Integer.toHexString((i + 16) % 256)));
+        }
+
+        repo.save((int) repo.count(), new Person("uniquePerson", 
"uniqueLastName"));
+        repo.save((int) repo.count(), new Person("nonUniquePerson", 
"nonUniqueLastName"));
+        repo.save((int) repo.count(), new Person("nonUniquePerson", 
"nonUniqueLastName"));
+        repo.save((int) repo.count(), new Person("nonUniquePerson", 
"nonUniqueLastName"));
+        repo.save((int) repo.count(), new Person("nonUniquePerson", 
"nonUniqueLastName"));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        ctx.destroy();
+    }
+
+    @Test
+    public void testPutGet() {
+        Person person = new Person("some_name", "some_surname");
+
+        int id = CACHE_SIZE + 1;
+
+        assertEquals(person, repo.save(id, person));
+
+        assertTrue(repo.existsById(id));
+
+        assertEquals(person, repo.findById(id).get());
+
+        try {
+            repo.save(person);
+
+            fail("Managed to save a Person without ID");
+        }
+        catch (UnsupportedOperationException e) {
+            //excepted
+        }
+    }
+}
diff --git 
a/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java
 
b/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java
index 795767f..0088d27 100644
--- 
a/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java
+++ 
b/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/misc/ApplicationConfiguration.java
@@ -35,6 +35,18 @@ import 
org.apache.ignite.springdata22.repository.config.EnableIgniteRepositories
 public class ApplicationConfiguration {
 
     /**
+     * The bean with cache names
+     */
+    @Bean
+    public CacheNamesBean cacheNames() {
+        CacheNamesBean bean = new CacheNamesBean();
+
+        bean.setPersonCacheName("PersonCache");
+
+        return bean;
+    }
+
+    /**
      * Ignite instance bean.
      */
     @Bean
diff --git 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
 
b/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/misc/CacheNamesBean.java
similarity index 64%
copy from 
modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
copy to 
modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/misc/CacheNamesBean.java
index 4b7d7f3..464a6c1 100644
--- 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
+++ 
b/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/misc/CacheNamesBean.java
@@ -15,20 +15,24 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.testsuites;
-
-import org.apache.ignite.springdata.IgniteSpringDataCrudSelfTest;
-import org.apache.ignite.springdata.IgniteSpringDataQueriesSelfTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
+package org.apache.ignite.springdata.misc;
 
 /**
- * Ignite Spring Data 2.0 test suite.
+ * The bean with cache names
  */
-@RunWith(Suite.class)
[email protected]({
-    IgniteSpringDataCrudSelfTest.class,
-    IgniteSpringDataQueriesSelfTest.class
-})
-public class IgniteSpringData2TestSuite {
+public class CacheNamesBean {
+
+    private String personCacheName;
+
+    /**
+     *  Get name of cache for persons
+     * @return name of cache
+     */
+    public String getPersonCacheName() {
+        return personCacheName;
+    }
+
+    public void setPersonCacheName(String personCacheName) {
+        this.personCacheName = personCacheName;
+    }
 }
diff --git 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
 
b/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/misc/PersonExpressionRepository.java
similarity index 64%
copy from 
modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
copy to 
modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/misc/PersonExpressionRepository.java
index 4b7d7f3..5917cfa 100644
--- 
a/modules/spring-data-2.0/src/test/java/org/apache/ignite/testsuites/IgniteSpringData2TestSuite.java
+++ 
b/modules/spring-data-2.2/src/test/java/org/apache/ignite/springdata/misc/PersonExpressionRepository.java
@@ -15,20 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.testsuites;
+package org.apache.ignite.springdata.misc;
 
-import org.apache.ignite.springdata.IgniteSpringDataCrudSelfTest;
-import org.apache.ignite.springdata.IgniteSpringDataQueriesSelfTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
+import org.apache.ignite.springdata22.repository.IgniteRepository;
+import org.apache.ignite.springdata22.repository.config.RepositoryConfig;
 
 /**
- * Ignite Spring Data 2.0 test suite.
+ *
  */
-@RunWith(Suite.class)
[email protected]({
-    IgniteSpringDataCrudSelfTest.class,
-    IgniteSpringDataQueriesSelfTest.class
-})
-public class IgniteSpringData2TestSuite {
+@RepositoryConfig(cacheName = "@cacheNames.personCacheName")
+public interface PersonExpressionRepository extends IgniteRepository<Person, 
Integer> {
 }
diff --git 
a/modules/spring-data-2.2/src/test/java/org/apache/ignite/testsuites/IgniteSpringData22TestSuite.java
 
b/modules/spring-data-2.2/src/test/java/org/apache/ignite/testsuites/IgniteSpringData22TestSuite.java
index 560df42..0e896f6 100644
--- 
a/modules/spring-data-2.2/src/test/java/org/apache/ignite/testsuites/IgniteSpringData22TestSuite.java
+++ 
b/modules/spring-data-2.2/src/test/java/org/apache/ignite/testsuites/IgniteSpringData22TestSuite.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.testsuites;
 
+import org.apache.ignite.springdata.IgniteSpringDataCrudSelfExpressionTest;
 import org.apache.ignite.springdata.IgniteSpringDataCrudSelfTest;
 import org.apache.ignite.springdata.IgniteSpringDataQueriesSelfTest;
 import org.junit.runner.RunWith;
@@ -28,7 +29,8 @@ import org.junit.runners.Suite;
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
     IgniteSpringDataCrudSelfTest.class,
-    IgniteSpringDataQueriesSelfTest.class
+    IgniteSpringDataQueriesSelfTest.class,
+    IgniteSpringDataCrudSelfExpressionTest.class
 })
 public class IgniteSpringData22TestSuite {
 }

Reply via email to