public class DataNucleusEnhancer extends Object
You can use the DataNucleusEnhancer in two ways :-
The programmatic way would be something like this :-
DataNucleusEnhancer enhancer = new DataNucleusEnhancer(); enhancer.setVerbose().addPersistenceUnit("myPersistenceUnit").enhance();enhancing all classes specified by the persistence unit.
Modifier and Type | Field and Description |
---|---|
static NucleusLogger |
LOGGER
Logger for enhancing.
|
protected ClassLoader |
userClassLoader
User-provided class loader.
|
Constructor and Description |
---|
DataNucleusEnhancer(String apiName,
Properties props)
Constructor for an enhancer specifying the API and class enhancer and optional properties.
|
Modifier and Type | Method and Description |
---|---|
DataNucleusEnhancer |
addClass(String className,
byte[] bytes)
Method to add the specified class (and its input bytes) to the list of classes to enhance.
|
DataNucleusEnhancer |
addClasses(String... classNames)
Method to add the specified classes to the list of classes to enhance.
|
DataNucleusEnhancer |
addFiles(String... filenames)
Method to add the specified files to the list of components to enhance.
|
DataNucleusEnhancer |
addJar(String jarFileName)
Method to add the classes defined by the specified jar to the list of components to enhance.
|
protected void |
addMessage(String msg,
boolean error)
Method to add a message at the required output level.
|
DataNucleusEnhancer |
addPersistenceUnit(PersistenceUnitMetaData pumd)
Method to add the classes defined by the persistence-unit to the list of classes to enhance.
|
DataNucleusEnhancer |
addPersistenceUnit(String persistenceUnitName)
Method to add the classes defined by the persistence-unit to the list of classes to enhance.
|
int |
enhance()
Method to enhance all classes defined by addClass, addClasses, addJar, addPersistenceUnit, addFiles.
|
protected boolean |
enhanceClass(ClassMetaData cmd,
ClassEnhancer enhancer,
boolean store)
Method to enhance the class defined by the MetaData.
|
protected ClassEnhancer |
getClassEnhancer(ClassMetaData cmd,
byte[] bytes)
Method to return an instance of the ClassEnhancer for use with this class.
|
ClassLoader |
getClassLoader()
Accessor for the user-defined class loader for enhancement (if any).
|
byte[] |
getEnhancedBytes(String className)
Accessor for the enhanced bytes of any classes just enhanced.
|
String |
getEnhancerVersion() |
protected Collection<FileMetaData> |
getFileMetadataForInput()
Method that processes the registered components to enhance, and loads the metadata for
them into the MetaDataManager, returning the associated FileMetaData.
|
MetaDataManager |
getMetaDataManager()
Accessor for the MetaDataManager.
|
String |
getOutputDirectory()
Acessor for the output directory.
|
byte[] |
getPkClassBytes(String className)
Accessor for the bytes of any pk classes just created.
|
Properties |
getProperties()
Accessor for global properties defining this enhancer.
|
boolean |
isVerbose()
Accessor for the verbose setting
|
static void |
main(String[] args)
Entry point for command line enhancer.
|
protected void |
resetEnhancement()
Method to throw away any previously stored enhancement results.
|
DataNucleusEnhancer |
setClassLoader(ClassLoader loader)
Method to set the class loader to use for loading the class(es) to be enhanced.
|
DataNucleusEnhancer |
setDetachListener(boolean flag)
Mutator for whether to allow generation of default constructor where needed.
|
DataNucleusEnhancer |
setGenerateConstructor(boolean flag)
Mutator for whether to allow generation of default constructor where needed.
|
DataNucleusEnhancer |
setGeneratePK(boolean flag)
Mutator for whether to allow generation of PKs where needed.
|
DataNucleusEnhancer |
setOutputDirectory(String dir)
Mutator for the output directory where any classes will be written.
|
DataNucleusEnhancer |
setSystemOut(boolean sysout)
Mutator for whether to output to system out.
|
DataNucleusEnhancer |
setVerbose(boolean verbose)
Mutator for the verbose flag
|
int |
validate()
Method to validate all classes defined by addClass, addClasses, addJar, addPersistenceUnit, addFiles.
|
protected boolean |
validateClass(ClassMetaData cmd,
ClassEnhancer enhancer)
Method to validate the enhancement state of the class defined by the MetaData.
|
public static final NucleusLogger LOGGER
protected ClassLoader userClassLoader
public DataNucleusEnhancer(String apiName, Properties props)
apiName
- Name of the API to use; defines which MetaDataManager to utilise.props
- properties controlling enhancementpublic MetaDataManager getMetaDataManager()
public String getOutputDirectory()
public DataNucleusEnhancer setOutputDirectory(String dir)
dir
- the output directorypublic ClassLoader getClassLoader()
public DataNucleusEnhancer setClassLoader(ClassLoader loader)
loader
- The loaderpublic boolean isVerbose()
public DataNucleusEnhancer setVerbose(boolean verbose)
verbose
- the verbose to setpublic DataNucleusEnhancer setSystemOut(boolean sysout)
sysout
- Whether to use sysoutpublic DataNucleusEnhancer setGeneratePK(boolean flag)
flag
- Whether to enable thispublic DataNucleusEnhancer setGenerateConstructor(boolean flag)
flag
- Whether to enable thispublic DataNucleusEnhancer setDetachListener(boolean flag)
flag
- Whether to enable thispublic DataNucleusEnhancer addClass(String className, byte[] bytes)
className
- Name of the class (in the format "mydomain.MyClass")bytes
- Bytes of the classpublic DataNucleusEnhancer addClasses(String... classNames)
classNames
- Names of the classespublic DataNucleusEnhancer addFiles(String... filenames)
filenames
- Names of the filespublic DataNucleusEnhancer addJar(String jarFileName)
jarFileName
- Name of the jar filepublic DataNucleusEnhancer addPersistenceUnit(String persistenceUnitName)
persistenceUnitName
- Name of the persistence-unitpublic DataNucleusEnhancer addPersistenceUnit(PersistenceUnitMetaData pumd)
pumd
- The persistence-unit metadata (dynamically created)public int enhance()
public int validate()
protected Collection<FileMetaData> getFileMetadataForInput()
public byte[] getEnhancedBytes(String className)
className
- Name of the classNucleusException
- if no bytes are available for the specified classpublic byte[] getPkClassBytes(String className)
className
- Name of the classNucleusException
- if no bytes are available for the specified classprotected void resetEnhancement()
protected ClassEnhancer getClassEnhancer(ClassMetaData cmd, byte[] bytes)
cmd
- MetaData for the classbytes
- Bytes (if provided)protected void addMessage(String msg, boolean error)
msg
- The messageerror
- Whether the message is an error, so log at error level (otherwise info)protected boolean enhanceClass(ClassMetaData cmd, ClassEnhancer enhancer, boolean store)
cmd
- MetaData for the classenhancer
- ClassEnhancer to usestore
- Whether to store the class after enhancingprotected boolean validateClass(ClassMetaData cmd, ClassEnhancer enhancer)
cmd
- MetaData for the classenhancer
- ClassEnhancer to usepublic Properties getProperties()
public String getEnhancerVersion()
Copyright © 2019. All rights reserved.