mirror of https://github.com/apache/openjpa.git
Make the inability to instantiate an auxiliary enhancer non-fatal. Also cache
auxiliary enhancers statically to speed up enhancement. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@454184 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dcf691a727
commit
d490f545c4
|
@ -109,6 +109,22 @@ public class PCEnhancer {
|
||||||
|
|
||||||
private static final Localizer _loc = Localizer.forPackage
|
private static final Localizer _loc = Localizer.forPackage
|
||||||
(PCEnhancer.class);
|
(PCEnhancer.class);
|
||||||
|
private static final AuxiliaryEnhancer[] _auxEnhancers;
|
||||||
|
static {
|
||||||
|
Class[] classes = Services.getImplementorClasses(
|
||||||
|
AuxiliaryEnhancer.class,
|
||||||
|
AuxiliaryEnhancer.class.getClassLoader());
|
||||||
|
List auxEnhancers = new ArrayList(classes.length);
|
||||||
|
for (int i = 0; i < classes.length; i++) {
|
||||||
|
try {
|
||||||
|
auxEnhancers.add(classes[i].newInstance());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// aux enhancer may rely on non-existant spec classes, etc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_auxEnhancers = (AuxiliaryEnhancer[]) auxEnhancers.toArray
|
||||||
|
(new AuxiliaryEnhancer[auxEnhancers.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
private final BCClass _pc;
|
private final BCClass _pc;
|
||||||
private final MetaDataRepository _repos;
|
private final MetaDataRepository _repos;
|
||||||
|
@ -118,7 +134,6 @@ public class PCEnhancer {
|
||||||
|
|
||||||
private boolean _defCons = true;
|
private boolean _defCons = true;
|
||||||
private boolean _fail = false;
|
private boolean _fail = false;
|
||||||
private AuxiliaryEnhancer[] _auxEnhancers = null;
|
|
||||||
private File _dir = null;
|
private File _dir = null;
|
||||||
private BytecodeWriter _writer = null;
|
private BytecodeWriter _writer = null;
|
||||||
private Map _backingFields = null;
|
private Map _backingFields = null;
|
||||||
|
@ -2639,35 +2654,17 @@ public class PCEnhancer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the auxiliary enhancers registered as {@link Services services}.
|
* Gets the auxiliary enhancers registered as {@link Services services}.
|
||||||
* Multi-call safe -- the first call locates the auxiliary enhancers,
|
|
||||||
* subsequent calls merely returns the existing set.
|
|
||||||
*
|
|
||||||
* @return array of auxiliary enhancers. empty array if none is registered.
|
|
||||||
*/
|
*/
|
||||||
public AuxiliaryEnhancer[] getAuxiliaryEnhancers() {
|
public AuxiliaryEnhancer[] getAuxiliaryEnhancers() {
|
||||||
if (_auxEnhancers == null) {
|
return _auxEnhancers;
|
||||||
try {
|
|
||||||
Class[] classes = Services.getImplementorClasses(
|
|
||||||
AuxiliaryEnhancer.class,
|
|
||||||
AuxiliaryEnhancer.class.getClassLoader());
|
|
||||||
_auxEnhancers = new AuxiliaryEnhancer[classes.length];
|
|
||||||
for (int i = 0; i < _auxEnhancers.length; i++)
|
|
||||||
_auxEnhancers[i] = (AuxiliaryEnhancer) classes[i].
|
|
||||||
newInstance();
|
|
||||||
} catch (Throwable t) {
|
|
||||||
throw new GeneralException(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _auxEnhancers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow any registered auxiliary code generators to run.
|
* Allow any registered auxiliary code generators to run.
|
||||||
*/
|
*/
|
||||||
private void runAuxiliaryEnhancers() {
|
private void runAuxiliaryEnhancers() {
|
||||||
AuxiliaryEnhancer[] auxEnhancers = getAuxiliaryEnhancers();
|
for (int i = 0; i < _auxEnhancers.length; i++)
|
||||||
for (int i = 0; i < auxEnhancers.length; i++)
|
_auxEnhancers[i].run(_pc, _meta);
|
||||||
auxEnhancers[i].run(_pc, _meta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2677,9 +2674,8 @@ public class PCEnhancer {
|
||||||
* @return true if any of the auxiliary enhancers skips the given method
|
* @return true if any of the auxiliary enhancers skips the given method
|
||||||
*/
|
*/
|
||||||
private boolean skipEnhance(BCMethod method) {
|
private boolean skipEnhance(BCMethod method) {
|
||||||
AuxiliaryEnhancer[] auxEnhancers = getAuxiliaryEnhancers();
|
for (int i = 0; i < _auxEnhancers.length; i++)
|
||||||
for (int i = 0; i < auxEnhancers.length; i++)
|
if (_auxEnhancers[i].skipEnhance(method))
|
||||||
if (auxEnhancers[i].skipEnhance(method))
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@ needs-runtime-enhance: "{0}" requires runtime enhancement: {1}
|
||||||
runtime-enhance-pcclasses: You have enabled runtime enhancement, but have not \
|
runtime-enhance-pcclasses: You have enabled runtime enhancement, but have not \
|
||||||
specified the set of persistent classes. OpenJPA must look for metadata for \
|
specified the set of persistent classes. OpenJPA must look for metadata for \
|
||||||
every loaded class, which might increase class load times significantly.
|
every loaded class, which might increase class load times significantly.
|
||||||
running-all-classes: No targets were given. Running on all classes listed in \
|
running-all-classes: No targets were given. Running on all classes in your \
|
||||||
org.apache.openjpa.PersistentClasses, or all metadata files in classpath directories if \
|
persistent classes list, or all metadata files in classpath directories if \
|
||||||
the property is not specified.
|
you have not listed your persistent classes.
|
||||||
detach-custom-ser: Type "{0}" is set to detach on serialize, but implements \
|
detach-custom-ser: Type "{0}" is set to detach on serialize, but implements \
|
||||||
a custom readObject and/or writeObject method. You cannot use custom \
|
a custom readObject and/or writeObject method. You cannot use custom \
|
||||||
serialization with detachment.
|
serialization with detachment.
|
||||||
|
|
|
@ -124,8 +124,7 @@ public class Services {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
try {
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
|
|
Loading…
Reference in New Issue