public class PCEnhancer extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
PCEnhancer.AuxiliaryEnhancer
Plugin interface for additional enhancement.
|
static class |
PCEnhancer.Flags
Run flags.
|
Modifier and Type | Field and Description |
---|---|
static int |
ENHANCE_AWARE |
static int |
ENHANCE_INTERFACE |
static int |
ENHANCE_NONE |
static int |
ENHANCE_PC |
static int |
ENHANCER_VERSION |
static String |
ISDETACHEDSTATEDEFINITIVE |
static String |
PRE |
Constructor and Description |
---|
PCEnhancer(MetaDataRepository repos,
serp.bytecode.BCClass type,
ClassMetaData meta)
Constructor.
|
PCEnhancer(OpenJPAConfiguration conf,
serp.bytecode.BCClass type,
ClassMetaData meta)
Constructor.
|
PCEnhancer(OpenJPAConfiguration conf,
serp.bytecode.BCClass type,
MetaDataRepository repos)
Deprecated.
|
PCEnhancer(OpenJPAConfiguration conf,
serp.bytecode.BCClass type,
MetaDataRepository repos,
ClassLoader loader)
Constructor.
|
PCEnhancer(OpenJPAConfiguration conf,
Class type)
Constructor.
|
PCEnhancer(OpenJPAConfiguration conf,
ClassMetaData meta)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
checkEnhancementLevel(Class<?> cls,
Log log)
This static public worker method detects and logs any Entities that may have been enhanced at build time by
a version of the enhancer that is older than the current version.
|
boolean |
getAddDefaultConstructor()
A boolean indicating whether the enhancer should add a no-args
constructor if one is not already present in the class.
|
PCEnhancer.AuxiliaryEnhancer[] |
getAuxiliaryEnhancers()
Gets the auxiliary enhancers registered as
services . |
BytecodeWriter |
getBytecodeWriter()
Return the current
BytecodeWriter to write to or null if none. |
boolean |
getCreateSubclass()
Whether the enhancer should make its arguments persistence-capable,
or generate a persistence-capable subclass.
|
File |
getDirectory()
The base build directory to generate code to.
|
boolean |
getEnforcePropertyRestrictions()
Whether to fail if the persistent type uses property access and
bytecode analysis shows that it may be violating OpenJPA's property
access restrictions.
|
serp.bytecode.BCClass |
getManagedTypeBytecode()
Return the bytecode representation of the managed class being
manipulated.
|
ClassMetaData |
getMetaData()
Return the metadata for the class being manipulated, or null if not
a persistent type.
|
serp.bytecode.BCClass |
getPCBytecode()
Return the bytecode representation of the persistence-capable class
being manipulated.
|
boolean |
getRedefine()
Whether the enhancer should mutate its arguments, or just run validation
and optional subclassing logic on them.
|
Class |
getType(ClassMetaData meta)
Return the concrete type for the given class, i.e. impl for managed
interfaces
|
boolean |
isAlreadyRedefined()
Whether the type that this instance is enhancing has already been
redefined.
|
boolean |
isAlreadySubclassed()
Whether the type that this instance is enhancing has already been
subclassed in this instance's environment classloader.
|
static boolean |
isPCSubclassName(String className)
Whether or not
className is the name for a
dynamically-created persistence-capable subclass. |
static void |
main(String[] args)
Usage: java org.apache.openjpa.enhance.PCEnhancer [option]*
<class name | .java file | .class file | .jdo file>+
Where the following options are recognized.
|
void |
record()
Write the generated bytecode.
|
int |
run()
Perform bytecode enhancements.
|
static boolean |
run(OpenJPAConfiguration conf,
String[] args,
Options opts)
Run the tool.
|
static boolean |
run(OpenJPAConfiguration conf,
String[] args,
PCEnhancer.Flags flags,
MetaDataRepository repos,
BytecodeWriter writer,
ClassLoader loader)
Enhance the given classes.
|
static boolean |
run(String[] args,
Options opts)
Run the tool.
|
void |
setAddDefaultConstructor(boolean addDefaultConstructor)
A boolean indicating whether the enhancer should add a no-args
constructor if one is not already present in the class.
|
void |
setBytecodeWriter(BytecodeWriter writer)
Set the
BytecodeWriter to write the bytecode to or null if none. |
void |
setCreateSubclass(boolean subclass)
Whether the enhancer should make its arguments persistence-capable,
or generate a persistence-capable subclass.
|
void |
setDirectory(File dir)
The base build directory to generate code to.
|
void |
setEnforcePropertyRestrictions(boolean fail)
Whether to fail if the persistent type uses property access and
bytecode analysis shows that it may be violating OpenJPA's property
access restrictions.
|
void |
setRedefine(boolean redefine)
Whether the enhancer should mutate its arguments, or just run validation
and optional subclassing logic on them.
|
static String |
toManagedTypeName(String className)
If
className is a dynamically-created persistence-capable
subclass name, returns the name of the class that it subclasses. |
public static final int ENHANCER_VERSION
public static final int ENHANCE_NONE
public static final int ENHANCE_AWARE
public static final int ENHANCE_INTERFACE
public static final int ENHANCE_PC
public static final String PRE
public static final String ISDETACHEDSTATEDEFINITIVE
public PCEnhancer(OpenJPAConfiguration conf, Class type)
type
from conf
's
repository.public PCEnhancer(OpenJPAConfiguration conf, ClassMetaData meta)
meta
by converting back to a class
and then loading from conf
's repository.@Deprecated public PCEnhancer(OpenJPAConfiguration conf, serp.bytecode.BCClass type, MetaDataRepository repos)
PCEnhancer(OpenJPAConfiguration, BCClass,
MetaDataRepository, ClassLoader)
instead.type
- the bytecode representation fo the type to
enhance; this can be created from any stream or filerepos
- a metadata repository to use for metadata access,
or null to create a new reporitory; the repository
from the given configuration isn't used by default
because the configuration might be an
implementation-specific subclass whose metadata
required more than just base metadata filespublic PCEnhancer(OpenJPAConfiguration conf, serp.bytecode.BCClass type, MetaDataRepository repos, ClassLoader loader)
type
- the bytecode representation fo the type to
enhance; this can be created from any stream or filerepos
- a metadata repository to use for metadata access,
or null to create a new reporitory; the repository
from the given configuration isn't used by default
because the configuration might be an
implementation-specific subclass whose metadata
required more than just base metadata filesloader
- the environment classloader to use for loading
classes and resources.public PCEnhancer(MetaDataRepository repos, serp.bytecode.BCClass type, ClassMetaData meta)
repos
- a metadata repository to use for metadata access,
or null to create a new reporitory; the repository
from the given configuration isn't used by default
because the configuration might be an
implementation-specific subclass whose metadata
required more than just base metadata filestype
- the bytecode representation fo the type to
enhance; this can be created from any stream or filemeta
- the metadata to use for processing this type.public PCEnhancer(OpenJPAConfiguration conf, serp.bytecode.BCClass type, ClassMetaData meta)
public static boolean isPCSubclassName(String className)
className
is the name for a
dynamically-created persistence-capable subclass.public static String toManagedTypeName(String className)
className
is a dynamically-created persistence-capable
subclass name, returns the name of the class that it subclasses.
Otherwise, returns className
.public serp.bytecode.BCClass getPCBytecode()
public serp.bytecode.BCClass getManagedTypeBytecode()
getPCBytecode()
,
except when running the enhancer to redefine and subclass
existing persistent types.public ClassMetaData getMetaData()
public boolean getAddDefaultConstructor()
public void setAddDefaultConstructor(boolean addDefaultConstructor)
public boolean getRedefine()
setCreateSubclass(true)
.public void setRedefine(boolean redefine)
setCreateSubclass(true)
.public boolean isAlreadyRedefined()
public boolean isAlreadySubclassed()
public boolean getCreateSubclass()
public void setCreateSubclass(boolean subclass)
public boolean getEnforcePropertyRestrictions()
public void setEnforcePropertyRestrictions(boolean fail)
public File getDirectory()
public void setDirectory(File dir)
public BytecodeWriter getBytecodeWriter()
BytecodeWriter
to write to or null if none.public void setBytecodeWriter(BytecodeWriter writer)
BytecodeWriter
to write the bytecode to or null if none.public int run()
ENHANCE_*
constantpublic void record() throws IOException
IOException
public PCEnhancer.AuxiliaryEnhancer[] getAuxiliaryEnhancers()
services
.public Class getType(ClassMetaData meta)
public static void main(String[] args)
Configuration
; optional.OpenJPAConfiguration
can be
set by using their names and supplying a value; for example:
public static boolean run(String[] args, Options opts)
public static boolean run(OpenJPAConfiguration conf, String[] args, Options opts) throws IOException
IOException
public static boolean run(OpenJPAConfiguration conf, String[] args, PCEnhancer.Flags flags, MetaDataRepository repos, BytecodeWriter writer, ClassLoader loader) throws IOException
IOException
public static boolean checkEnhancementLevel(Class<?> cls, Log log)
cls
- - A non-null Class implementing org.apache.openjpa.enhance.PersistenceCapable.log
- - A non-null org.apache.openjpa.lib.log.Log.-
- IllegalStateException if cls doesn't implement org.apache.openjpa.enhance.PersistenceCapable.Copyright © 2006–2022 Apache Software Foundation. All rights reserved.