You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2015/07/06 04:30:24 UTC
[02/50] incubator-ignite git commit: # ignite-gg-10416 Fixed exclude
nested beans with missing classes.
# ignite-gg-10416 Fixed exclude nested beans with missing classes.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/99b82841
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/99b82841
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/99b82841
Branch: refs/heads/ignite-959-x
Commit: 99b82841e31d48580f5320d8d46e905b284f27e9
Parents: ce31bae
Author: Andrey <an...@gridgain.com>
Authored: Thu Jun 18 16:21:58 2015 +0700
Committer: Andrey <an...@gridgain.com>
Committed: Thu Jun 18 16:21:58 2015 +0700
----------------------------------------------------------------------
.../util/spring/IgniteSpringHelperImpl.java | 59 +++++++++------
.../IgniteStartExcludesConfigurationTest.java | 80 ++++++++++++++++++++
.../org/apache/ignite/spring/sprint-exclude.xml | 57 ++++++++++++++
3 files changed, 172 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/99b82841/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java b/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
index e9f88ad..df53ca7 100644
--- a/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
+++ b/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
@@ -423,37 +423,38 @@ public class IgniteSpringHelperImpl implements IgniteSpringHelper {
BeanFactoryPostProcessor postProc = new BeanFactoryPostProcessor() {
/**
- * @param beanFactory The bean factory used by the application context.
- * @param beanName Bean name.
* @param def Registered BeanDefinition.
* @throws BeansException in case of errors.
*/
- private void processBeanDefinition(ConfigurableListableBeanFactory beanFactory, String beanName,
- BeanDefinition def) throws BeansException {
- if (def.getBeanClassName() != null) {
- try {
- Class.forName(def.getBeanClassName());
+ private void processNested(BeanDefinition def) throws BeansException {
+ MutablePropertyValues vals = def.getPropertyValues();
+
+ for (PropertyValue val : new ArrayList<>(vals.getPropertyValueList())) {
+ for (String excludedProp : excludedProps) {
+ if (val.getName().equals(excludedProp)) {
+ vals.removePropertyValue(val);
+
+ return;
+ }
+ }
- MutablePropertyValues vals = def.getPropertyValues();
+ if (val.getValue() instanceof Collection) {
+ Collection<?> nestedVals = (Collection) val.getValue();
- for (PropertyValue val : new ArrayList<>(vals.getPropertyValueList())) {
- for (String excludedProp : excludedProps) {
- if (val.getName().equals(excludedProp)) {
- vals.removePropertyValue(val);
+ for (Object item : new ArrayList<>(nestedVals))
+ if (item instanceof BeanDefinitionHolder) {
+ BeanDefinitionHolder holder = (BeanDefinitionHolder)item;
- return;
+ try {
+ if (holder.getBeanDefinition().getBeanClassName() != null)
+ Class.forName(holder.getBeanDefinition().getBeanClassName());
+
+ processNested(holder.getBeanDefinition());
+ }
+ catch (ClassNotFoundException ignored) {
+ nestedVals.remove(item);
}
}
-
- if (val.getValue() instanceof Iterable)
- for (Object beanDef : (Iterable)val.getValue())
- if (beanDef instanceof BeanDefinitionHolder)
- processBeanDefinition(beanFactory, beanName,
- ((BeanDefinitionHolder)beanDef).getBeanDefinition());
- }
- }
- catch (ClassNotFoundException ignored) {
- ((BeanDefinitionRegistry) beanFactory).removeBeanDefinition(beanName);
}
}
}
@@ -462,7 +463,17 @@ public class IgniteSpringHelperImpl implements IgniteSpringHelper {
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
for (String beanName : beanFactory.getBeanDefinitionNames())
- processBeanDefinition(beanFactory, beanName, beanFactory.getBeanDefinition(beanName));
+ try {
+ BeanDefinition def = beanFactory.getBeanDefinition(beanName);
+
+ if (def.getBeanClassName() != null)
+ Class.forName(def.getBeanClassName());
+
+ processNested(def);
+ }
+ catch (ClassNotFoundException ignored) {
+ ((BeanDefinitionRegistry)beanFactory).removeBeanDefinition(beanName);
+ }
}
};
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/99b82841/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java b/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java
new file mode 100644
index 0000000..f1332e0
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.spring;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.spring.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.net.*;
+import java.util.*;
+
+import static org.apache.ignite.internal.IgniteComponentType.*;
+
+/**
+ * Checks exclude properties in spring, exclude beans with not existing classes.
+ */
+public class IgniteStartExcludesConfigurationTest extends GridCommonAbstractTest {
+ /** Tests spring exclude properties. */
+ public void testExcludes() throws Exception {
+ URL cfgLocation = U.resolveIgniteUrl(
+ "modules/spring/src/test/java/org/apache/ignite/spring/sprint-exclude.xml");
+
+ IgniteSpringHelper spring = SPRING.create(false);
+
+ Collection<IgniteConfiguration> cfgs = spring.loadConfigurations(cfgLocation, "typeMetadata").get1();
+
+ assert cfgs != null && cfgs.size() == 1;
+
+ IgniteConfiguration cfg = cfgs.iterator().next();
+
+ assert cfg.getCacheConfiguration().length == 1;
+
+ assert cfg.getCacheConfiguration()[0].getTypeMetadata() == null;
+
+ cfgs = spring.loadConfigurations(cfgLocation, "keyType").get1();
+
+ assert cfgs != null && cfgs.size() == 1;
+
+ cfg = cfgs.iterator().next();
+
+ assert cfg.getCacheConfiguration().length == 1;
+
+ Collection<CacheTypeMetadata> typeMetadatas = cfg.getCacheConfiguration()[0].getTypeMetadata();
+
+ assert typeMetadatas.size() == 1;
+
+ assert typeMetadatas.iterator().next().getKeyType() == null;
+
+ cfgs = spring.loadConfigurations(cfgLocation).get1();
+
+ assert cfgs != null && cfgs.size() == 1;
+
+ cfg = cfgs.iterator().next();
+
+ assert cfg.getCacheConfiguration().length == 1;
+
+ typeMetadatas = cfg.getCacheConfiguration()[0].getTypeMetadata();
+
+ assert typeMetadatas.size() == 1;
+
+ assert "java.lang.Integer".equals(typeMetadatas.iterator().next().getKeyType());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/99b82841/modules/spring/src/test/java/org/apache/ignite/spring/sprint-exclude.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/sprint-exclude.xml b/modules/spring/src/test/java/org/apache/ignite/spring/sprint-exclude.xml
new file mode 100644
index 0000000..494f786
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/spring/sprint-exclude.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!--
+ GridGain Spring configuration file to startup grid cache.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd">
+ <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+ <!-- Cache configurations (all properties are optional). -->
+ <property name="cacheConfiguration">
+ <list>
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <!-- Configure type metadata to enable queries. -->
+ <property name="typeMetadata">
+ <list>
+ <bean class="org.apache.ignite.cache.CacheTypeMetadata">
+ <property name="keyType" value="java.lang.Integer"/>
+ <property name="valueType" value="Organization"/>
+ <property name="ascendingFields">
+ <map>
+ <entry key="name" value="java.lang.String"/>
+ </map>
+ </property>
+ </bean>
+ <bean class="org.apache.ignite.cache.CacheTypeMetadata2"/>
+ </list>
+ </property>
+ </bean>
+ </list>
+ </property>
+ </bean>
+
+ <bean id="grid.cfg.failed" class="org.apache.ignite.configuration.IgniteConfiguration2"/>
+</beans>