mirror of https://github.com/apache/openjpa.git
Disable logging during brokerfactory de-serialization. Added type checking of plugin values.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1462268 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6853346d37
commit
d3c68ad3bb
|
@ -473,8 +473,14 @@ public abstract class AbstractBrokerFactory
|
||||||
// reset these transient fields to empty values
|
// reset these transient fields to empty values
|
||||||
_transactional = new ConcurrentHashMap<Object,Collection<Broker>>();
|
_transactional = new ConcurrentHashMap<Object,Collection<Broker>>();
|
||||||
_brokers = newBrokerSet();
|
_brokers = newBrokerSet();
|
||||||
|
|
||||||
|
// turn off logging while de-serializing BrokerFactory
|
||||||
|
String saveLogConfig = _conf.getLog();
|
||||||
|
_conf.setLog("none");
|
||||||
makeReadOnly();
|
makeReadOnly();
|
||||||
|
// re-enable any logging which was in effect
|
||||||
|
_conf.setLog(saveLogConfig);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
package org.apache.openjpa.lib.conf;
|
package org.apache.openjpa.lib.conf;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.openjpa.lib.log.Log;
|
||||||
import org.apache.openjpa.lib.util.Localizer;
|
import org.apache.openjpa.lib.util.Localizer;
|
||||||
|
import org.apache.openjpa.lib.util.ParseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A plugin {@link Value} consisting of plugin name and properties.
|
* A plugin {@link Value} consisting of plugin name and properties.
|
||||||
|
@ -101,6 +103,20 @@ public class PluginValue extends ObjectValue {
|
||||||
public Object instantiate(Class<?> type, Configuration conf, boolean fatal)
|
public Object instantiate(Class<?> type, Configuration conf, boolean fatal)
|
||||||
{
|
{
|
||||||
Object obj = newInstance(_name, type, conf, fatal);
|
Object obj = newInstance(_name, type, conf, fatal);
|
||||||
|
|
||||||
|
// ensure plugin value is compatible with plugin type
|
||||||
|
if (obj != null && !type.isAssignableFrom(obj.getClass())) {
|
||||||
|
Log log = (conf == null) ? null : conf.getConfigurationLog();
|
||||||
|
String msg = getIncompatiblePluginMessage(obj, type);
|
||||||
|
if (log != null && log.isErrorEnabled()) {
|
||||||
|
log.error(msg);
|
||||||
|
}
|
||||||
|
if (fatal) {
|
||||||
|
throw new ParseException(msg);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Configurations.configureInstance(obj, conf, _props,
|
Configurations.configureInstance(obj, conf, _props,
|
||||||
(fatal) ? getProperty() : null);
|
(fatal) ? getProperty() : null);
|
||||||
if (_singleton)
|
if (_singleton)
|
||||||
|
@ -108,7 +124,15 @@ public class PluginValue extends ObjectValue {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private String getIncompatiblePluginMessage(Object obj, Class<?> type) {
|
||||||
|
return _loc.get("incompatible-plugin",
|
||||||
|
new Object[]{ _name,
|
||||||
|
obj == null ? null : obj.getClass().getName(),
|
||||||
|
type == null ? null : type.getName()
|
||||||
|
}).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Configure the given object.
|
* Configure the given object.
|
||||||
*/
|
*/
|
||||||
public Object configure(Object obj, Configuration conf, boolean fatal) {
|
public Object configure(Object obj, Configuration conf, boolean fatal) {
|
||||||
|
|
|
@ -117,3 +117,7 @@ veto-change: Can not modify "{0}" because the property is not dynamic and the \
|
||||||
jndi-lookup-failed: JNDI lookup for "{0}" with key "{1}" returned null.
|
jndi-lookup-failed: JNDI lookup for "{0}" with key "{1}" returned null.
|
||||||
multiple-load-key: Equivalent property keys "{0}" and "{1}" are specified in \
|
multiple-load-key: Equivalent property keys "{0}" and "{1}" are specified in \
|
||||||
configuration.
|
configuration.
|
||||||
|
incompatible-plugin: The plugin "{0}" of value type "{1}" is not compatible with \
|
||||||
|
the expected plugin type "{2}". Update the configuration property with a value that \
|
||||||
|
is compatible with the plugin.
|
||||||
|
|
|
@ -260,7 +260,7 @@ public class DistributedJDBCConfigurationImpl extends JDBCConfigurationImpl
|
||||||
|
|
||||||
public QueryTargetPolicy getQueryTargetPolicyInstance() {
|
public QueryTargetPolicy getQueryTargetPolicyInstance() {
|
||||||
if (queryTargetPolicyPlugin.get() == null) {
|
if (queryTargetPolicyPlugin.get() == null) {
|
||||||
queryTargetPolicyPlugin.instantiate(ReplicationPolicy.class,
|
queryTargetPolicyPlugin.instantiate(QueryTargetPolicy.class,
|
||||||
this, true);
|
this, true);
|
||||||
}
|
}
|
||||||
return (QueryTargetPolicy) queryTargetPolicyPlugin.get();
|
return (QueryTargetPolicy) queryTargetPolicyPlugin.get();
|
||||||
|
|
Loading…
Reference in New Issue