Skip to content

Commit b8933dc

Browse files
author
Jeremy Bauer
committed
Disable logging during brokerfactory de-serialization. Added type checking of plugin values.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.2.x@1462076 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8495f9e commit b8933dc

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,14 @@ protected Object readResolve()
472472
// reset these transient fields to empty values
473473
_transactional = new ConcurrentHashMap<Object,Collection<Broker>>();
474474
_brokers = newBrokerSet();
475-
475+
476+
// turn off logging while de-serializing BrokerFactory
477+
String saveLogConfig = _conf.getLog();
478+
_conf.setLog("none");
476479
makeReadOnly();
480+
// re-enable any logging which was in effect
481+
_conf.setLog(saveLogConfig);
482+
477483
return this;
478484
}
479485

openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
package org.apache.openjpa.lib.conf;
2020

2121
import org.apache.commons.lang.StringUtils;
22+
import org.apache.openjpa.lib.log.Log;
2223
import org.apache.openjpa.lib.util.Localizer;
24+
import org.apache.openjpa.lib.util.ParseException;
2325

2426
/**
2527
* A plugin {@link Value} consisting of plugin name and properties.
@@ -101,14 +103,36 @@ public void setProperties(String props) {
101103
public Object instantiate(Class<?> type, Configuration conf, boolean fatal)
102104
{
103105
Object obj = newInstance(_name, type, conf, fatal);
106+
107+
// ensure plugin value is compatible with plugin type
108+
if (obj != null && !type.isAssignableFrom(obj.getClass())) {
109+
Log log = (conf == null) ? null : conf.getConfigurationLog();
110+
String msg = getIncompatiblePluginMessage(obj, type);
111+
if (log != null && log.isErrorEnabled()) {
112+
log.error(msg);
113+
}
114+
if (fatal) {
115+
throw new ParseException(msg);
116+
}
117+
return null;
118+
}
119+
104120
Configurations.configureInstance(obj, conf, _props,
105121
(fatal) ? getProperty() : null);
106122
if (_singleton)
107123
set(obj, true);
108124
return obj;
109125
}
110126

111-
/**
127+
private String getIncompatiblePluginMessage(Object obj, Class<?> type) {
128+
return _loc.get("incompatible-plugin",
129+
new Object[]{ _name,
130+
obj == null ? null : obj.getClass().getName(),
131+
type == null ? null : type.getName()
132+
}).toString();
133+
}
134+
135+
/**
112136
* Configure the given object.
113137
*/
114138
public Object configure(Object obj, Configuration conf, boolean fatal) {

openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,6 @@ veto-change: Can not modify "{0}" because the property is not dynamic and the \
117117
jndi-lookup-failed: JNDI lookup for "{0}" with key "{1}" returned null.
118118
multiple-load-key: Equivalent property keys "{0}" and "{1}" are specified in \
119119
configuration.
120+
incompatible-plugin: The plugin "{0}" of value type "{1}" is not compatible with \
121+
the expected plugin type "{2}". Update the configuration property with a value that \
122+
is compatible with the plugin.

openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public void setReplicationPolicy(String policy) {
260260

261261
public QueryTargetPolicy getQueryTargetPolicyInstance() {
262262
if (queryTargetPolicyPlugin.get() == null) {
263-
queryTargetPolicyPlugin.instantiate(ReplicationPolicy.class,
263+
queryTargetPolicyPlugin.instantiate(QueryTargetPolicy.class,
264264
this, true);
265265
}
266266
return (QueryTargetPolicy) queryTargetPolicyPlugin.get();

0 commit comments

Comments
 (0)