public final class ConversionPool
extends java.lang.Object
pattern engines
used for
runtime conversion of dynamically defined persistence constructs, such as temp-tables and
queries. A shared pool is used, rather than instantiating pattern engines as needed, because
these objects are very expensive to create and configure. The instances in the pool are
created and configured to their specific conversion task once, then stored for use many times
across contexts.
A conversion task is performed by invoking the runTask(ConversionProfile, Aast...)
method, which requires the caller to specify a profile which defines the conversion task to
be performed, and to provide one or more target ASTs on which to operate. Any objects stored
during the conversion task are available through the ConversionPool.Results
object returned.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
ConversionPool.Results
Object which holds the objects stored in the pattern engine by its conversion task.
|
Modifier and Type | Field and Description |
---|---|
private static ConversionPool |
instance
Singleton instance of this class
|
private static java.util.logging.Logger |
LOG
Logger
|
private java.util.Map<ConversionProfile,java.util.Stack<PatternEngine>> |
pool
Map of pattern engine stacks, keyed by conversion profile
|
Modifier | Constructor and Description |
---|---|
private |
ConversionPool()
Private constructor.
|
Modifier and Type | Method and Description |
---|---|
private void |
addEngine(ConversionProfile profile)
Add a pattern engine instance to the stack associated with the given conversion profile.
|
static void |
initialize()
Initialize the conversion pool by loading all necessary, permanent schemas and creating the
initial pattern engine instances.
|
static boolean |
isInitialized()
Indicate whether the conversion pool was initialized successfully.
|
private PatternEngine |
popEngine(ConversionProfile profile)
Pop a pattern engine instance from its stack in order to perform a conversion task.
|
private void |
pushEngine(ConversionProfile profile,
PatternEngine engine)
Push a pattern engine instance back onto its stack, so it can be used again.
|
(package private) static ConversionPool.Results |
runTask(ConversionProfile profile,
Aast... targetAsts)
Run a specific conversion task against the given ASTs, as defined by the provided profile.
|
(package private) static ConversionPool.Results |
runTask(ConversionProfile profile,
ConversionPool.Results initialValues,
Aast... targetAsts)
Run a specific conversion task against the given ASTs, as defined by the provided profile.
|
private static java.util.logging.Logger LOG
private static ConversionPool instance
private final java.util.Map<ConversionProfile,java.util.Stack<PatternEngine>> pool
public static void initialize() throws ConfigurationException
ConfigurationException
- if there is an error loading schemas or creating pattern engine instances.java.lang.IllegalStateException
- if this method is called more than once.public static boolean isInitialized()
true
if initialized, else false
.static ConversionPool.Results runTask(ConversionProfile profile, Aast... targetAsts)
profile
- Enumeration value defining the conversion profile to apply to the target ASTs.targetAsts
- Source ASTs upon which to operate.static ConversionPool.Results runTask(ConversionProfile profile, ConversionPool.Results initialValues, Aast... targetAsts)
profile
- Enumeration value defining the conversion profile to apply to the target ASTs.initialValues
- A ConversionPool.Results
object from a previous task which is used to initialize the
pattern engine for this task with a set of starting values. This provides a way to
pass results from one task's pattern engine to the next in a pipeline. May be
null
.targetAsts
- Source ASTs upon which to operate.private void addEngine(ConversionProfile profile) throws ConfigurationException
profile
- Conversion profile which will determine the task performed by the new pattern
engine instance.ConfigurationException
- if there is an error instantiating and initializing the new pattern engine object.private void pushEngine(ConversionProfile profile, PatternEngine engine)
profile
- Profile which defines the pattern engine's conversion task.engine
- Pattern engine instance to be pushed.private PatternEngine popEngine(ConversionProfile profile)
profile
- Profile which defines the pattern engine's conversion task.