Use additional contextual classloaders when deserializing lob data.

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@499137 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
A. Abram White 2007-01-23 21:10:21 +00:00
parent 5dddb15cb3
commit 81c9a795ca
2 changed files with 33 additions and 4 deletions

View File

@ -658,8 +658,7 @@ public class StateManagerImpl
boolean loaded) { boolean loaded) {
int idx = _meta.getExtraFieldDataIndex(field); int idx = _meta.getExtraFieldDataIndex(field);
if (idx == -1) if (idx == -1)
throw new InternalException(String.valueOf(_meta.getField throw new InternalException(String.valueOf(_meta.getField(field)));
(field)));
Object old = (_fieldImpl == null) ? null : _fieldImpl[idx]; Object old = (_fieldImpl == null) ? null : _fieldImpl[idx];
if (data != null) { if (data != null) {

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Serializable; import java.io.Serializable;
@ -28,6 +29,7 @@ import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.kernel.StoreContext; import org.apache.openjpa.kernel.StoreContext;
import org.apache.openjpa.lib.log.Log; 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.MultiClassLoader;
/** /**
* Helper class to serialize and deserialize persistent objects, * Helper class to serialize and deserialize persistent objects,
@ -74,7 +76,7 @@ public class Serialization {
public static Object deserialize(InputStream in, StoreContext ctx) { public static Object deserialize(InputStream in, StoreContext ctx) {
try { try {
if (ctx == null) if (ctx == null)
return new ObjectInputStream(in).readObject(); return new ClassResolvingObjectInputStream(in).readObject();
return new PersistentObjectInputStream(in, ctx).readObject(); return new PersistentObjectInputStream(in, ctx).readObject();
} catch (Exception e) { } catch (Exception e) {
throw new StoreException(e); throw new StoreException(e);
@ -106,11 +108,34 @@ public class Serialization {
} }
} }
private static class ClassResolvingObjectInputStream
extends ObjectInputStream {
public ClassResolvingObjectInputStream(InputStream delegate)
throws IOException {
super(delegate);
}
protected Class resolveClass(ObjectStreamClass desc)
throws IOException, ClassNotFoundException {
MultiClassLoader loader = new MultiClassLoader();
addContextClassLoaders(loader);
loader.addClassLoader(getClass().getClassLoader());
loader.addClassLoader(MultiClassLoader.SYSTEM_LOADER);
return Class.forName(desc.getName(), true, loader);
}
protected void addContextClassLoaders(MultiClassLoader loader) {
loader.addClassLoader(Thread.currentThread().
getContextClassLoader());
}
}
/** /**
* Object input stream that replaces oids with their objects. * Object input stream that replaces oids with their objects.
*/ */
private static class PersistentObjectInputStream private static class PersistentObjectInputStream
extends ObjectInputStream { extends ClassResolvingObjectInputStream {
private final StoreContext _ctx; private final StoreContext _ctx;
@ -126,6 +151,11 @@ public class Serialization {
enableResolveObject(true); enableResolveObject(true);
} }
protected void addContextClassLoaders(MultiClassLoader loader) {
super.addContextClassLoaders(loader);
loader.addClassLoader(_ctx.getClassLoader());
}
protected Object resolveObject(Object obj) { protected Object resolveObject(Object obj) {
if (!(obj instanceof ObjectIdMarker)) if (!(obj instanceof ObjectIdMarker))
return obj; return obj;