Save This Page
Home » apache-openjpa-1.1.0-source » org.apache.openjpa » enhance » [javadoc | source]
org.apache.openjpa.enhance
public class: PCEnhancer [javadoc | source]
java.lang.Object
   org.apache.openjpa.enhance.PCEnhancer
Bytecode enhancer used to enhance persistent classes from metadata. The enhancer must be invoked on all persistence-capable and persistence aware classes.
Nested Class Summary:
public static class  PCEnhancer.Flags  Run flags. 
public static interface  PCEnhancer.AuxiliaryEnhancer  Plugin interface for additional enhancement. 
Field Summary
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     
Constructor:
 public PCEnhancer(OpenJPAConfiguration conf,
    Class type) 
    Constructor. Supply configuration and type to enhance. This will look up the metadata for type from conf's repository.
 public PCEnhancer(OpenJPAConfiguration conf,
    ClassMetaData meta) 
    Constructor. Supply configuration and type to enhance. This will look up the metadata for meta by converting back to a class and then loading from conf's repository.
 public PCEnhancer(OpenJPAConfiguration conf,
    BCClass type,
    MetaDataRepository repos) 
    Constructor. Supply configuration.
    Parameters:
    type - the bytecode representation fo the type to enhance; this can be created from any stream or file
    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 files
 public PCEnhancer(MetaDataRepository repos,
    BCClass type,
    ClassMetaData meta) 
    Constructor. Supply repository. The repository's configuration will be used, and the metadata passed in will be used as-is without doing any additional lookups. This is useful when running the enhancer during metadata load.
    Parameters:
    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 files
    type - the bytecode representation fo the type to enhance; this can be created from any stream or file
    meta - the metadata to use for processing this type.
    since: 1.1.0 -
 public PCEnhancer(OpenJPAConfiguration conf,
    BCClass type,
    ClassMetaData meta) 
    Constructor. Supply configuration, type, and metadata.
 public PCEnhancer(OpenJPAConfiguration conf,
    BCClass type,
    MetaDataRepository repos,
    ClassLoader loader) 
    Constructor. Supply configuration.
    Parameters:
    type - the bytecode representation fo the type to enhance; this can be created from any stream or file
    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 files
    loader - the environment classloader to use for loading classes and resources.
Method from org.apache.openjpa.enhance.PCEnhancer Summary:
getAddDefaultConstructor,   getAssignedField,   getAuxiliaryEnhancers,   getBytecodeWriter,   getCreateSubclass,   getDirectory,   getEnforcePropertyRestrictions,   getManagedTypeBytecode,   getMetaData,   getPCBytecode,   getRedefine,   getReturnedField,   getType,   isAlreadyRedefined,   isAlreadySubclassed,   isPCSubclassName,   main,   record,   run,   run,   run,   run,   setAddDefaultConstructor,   setBytecodeWriter,   setCreateSubclass,   setDirectory,   setEnforcePropertyRestrictions,   setRedefine,   toManagedTypeName,   toPCSubclassName
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.openjpa.enhance.PCEnhancer Detail:
 public boolean getAddDefaultConstructor() 
    A boolean indicating whether the enhancer should add a no-args constructor if one is not already present in the class. OpenJPA requires that a no-arg constructor (whether created by the compiler or by the user) be present in a PC.
 static BCField getAssignedField(BCMethod meth) 
    Return the field assigned in the given method, or null if none. Package-protected and static for testing.
 public PCEnhancer.AuxiliaryEnhancer[] getAuxiliaryEnhancers() 
    Gets the auxiliary enhancers registered as services .
 public BytecodeWriter getBytecodeWriter() 
 public boolean getCreateSubclass() 
    Whether the enhancer should make its arguments persistence-capable, or generate a persistence-capable subclass.
 public File getDirectory() 
    The base build directory to generate code to. The proper package structure will be created beneath this directory. Defaults to overwriting the existing class file if null.
 public 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.
 public BCClass getManagedTypeBytecode() 
    Return the bytecode representation of the managed class being manipulated. This is usually the same as #getPCBytecode , except when running the enhancer to redefine and subclass existing persistent types.
 public ClassMetaData getMetaData() 
    Return the metadata for the class being manipulated, or null if not a persistent type.
 public BCClass getPCBytecode() 
    Return the bytecode representation of the persistence-capable class being manipulated.
 public boolean getRedefine() 
    Whether the enhancer should mutate its arguments, or just run validation and optional subclassing logic on them. Usually used in conjunction with setCreateSubclass(true).
 static BCField getReturnedField(BCMethod meth) 
    Return the field returned by the given method, or null if none. Package-protected and static for testing.
 public Class getType(ClassMetaData meta) 
    Return the concrete type for the given class, i.e. impl for managed interfaces
 public boolean isAlreadyRedefined() 
    Whether the type that this instance is enhancing has already been redefined.
 public boolean isAlreadySubclassed() 
    Whether the type that this instance is enhancing has already been subclassed in this instance's environment classloader.
 public static boolean isPCSubclassName(String className) 
    Whether or not className is the name for a dynamically-created persistence-capable subclass.
 public 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.
    • -properties/-p <properties file>: The path to a OpenJPA properties file containing information as outlined in Configuration ; optional.
    • -<property name> <property value>: All bean properties of the standard OpenJPA OpenJPAConfiguration can be set by using their names and supplying a value; for example:
    • -directory/-d <build directory>: The path to the base directory where enhanced classes are stored. By default, the enhancer overwrites the original .class file with the enhanced version. Use this option to store the generated .class file in another directory. The package structure will be created beneath the given directory.
    • -addDefaultConstructor/-adc [true/t | false/f]: Whether to add a default constructor to persistent classes missing one, as opposed to throwing an exception. Defaults to true.
    • -tmpClassLoader/-tcl [true/t | false/f]: Whether to load the pre-enhanced classes using a temporary class loader. Defaults to true. Set this to false when attempting to debug class loading errors.
    • -enforcePropertyRestrictions/-epr [true/t | false/f]: Whether to throw an exception if a PROPERTY access entity appears to be violating standard property restrictions. Defaults to false.
    Each additional argument can be either the full class name of the type to enhance, the path to the .java file for the type, the path to the .class file for the type, or the path to a .jdo file listing one or more types to enhance. If the type being enhanced has metadata, it will be enhanced as a persistence capable class. If not, it will be considered a persistence aware class, and all access to fields of persistence capable classes will be replaced by the appropriate get/set method. If the type explicitly declares the persistence-capable interface, it will not be enhanced. Thus, it is safe to invoke the enhancer on classes that are already enhanced.
 public  void record() throws IOException 
    Write the generated bytecode.
 public int run() 
    Perform bytecode enhancements.
 public static boolean run(String[] args,
    Options opts) 
    Run the tool. Returns false if invalid options given. Runs against all the persistence units defined in the resource to parse.
 public static boolean run(OpenJPAConfiguration conf,
    String[] args,
    Options opts) throws IOException 
    Run the tool. Returns false if invalid options given.
 public static boolean run(OpenJPAConfiguration conf,
    String[] args,
    PCEnhancer.Flags flags,
    MetaDataRepository repos,
    BytecodeWriter writer,
    ClassLoader loader) throws IOException 
    Enhance the given classes.
 public  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. OpenJPA requires that a no-arg constructor (whether created by the compiler or by the user) be present in a PC.
 public  void setBytecodeWriter(BytecodeWriter writer) 
 public  void setCreateSubclass(boolean subclass) 
    Whether the enhancer should make its arguments persistence-capable, or generate a persistence-capable subclass.
 public  void setDirectory(File dir) 
    The base build directory to generate code to. The proper package structure will be creaed beneath this directory. Defaults to overwriting the existing class file if null.
 public  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.
 public  void setRedefine(boolean redefine) 
    Whether the enhancer should mutate its arguments, or just run validation and optional subclassing logic on them. Usually used in conjunction with setCreateSubclass(true).
 public static String toManagedTypeName(String className) 
    If className is a dynamically-created persistence-capable subclass name, returns the name of the class that it subclasses. Otherwise, returns className.
 static String toPCSubclassName(Class cls)