public class DynamicTablesHelper
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
DynamicTablesHelper.CacheData
DMO data to be cached for a dynamically defined temp-table.
|
private static class |
DynamicTablesHelper.CacheKey
A hashable key that encapsulates the characteristics which uniquely define the structure of
a dynamic temp-table; namely, its field and index definitions.
|
private class |
DynamicTablesHelper.Context
Context local information, used to clean up resources when the context ends and to respond
to queries about temp-table resources in use.
|
private static class |
DynamicTablesHelper.DMOInfo
Class which contains information about a dynamically define DMO, including the compiled
interface and implementation classes, and mappings between the legacy and converted fields.
|
private class |
DynamicTablesHelper.DMOResourceManager
An instance of this class manages resources requiring cleanup, across all contexts.
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<DynamicTablesHelper.CacheKey,DynamicTablesHelper.CacheData> |
cache
Cache for dynamically converted and compiled DMO resources
|
private java.lang.Object |
cacheLock
Lock object on which to synchronize cache operations
|
private ContextLocal<DynamicTablesHelper.Context> |
context
Containers for context-specific data.
|
private java.util.List<java.io.File> |
createdDirectories
List of directories that are newly created.
|
(package private) static java.lang.String |
DMO_BASE_PACKAGE
Base package for generated DMOs.
|
(package private) static java.lang.String |
DMO_IFACE_CATEGORY
Category name for DMO interfaces, used in conversion rules.
|
private DynamicTablesHelper.DMOResourceManager |
dmoResourceManager
Cross-context manager which cleans up shared DMO resources once they go out of scope
|
private static java.util.Set<java.lang.String> |
existingEntries
List of entries present in the jar.
|
private static DynamicTablesHelper |
instance
Singleton instance.
|
private static CentralLogger |
LOG
Logger.
|
private java.io.File |
persistentCacheJarFile
File object corresponding to the jar file with dynamic table DMO classes.
|
private java.lang.String |
persistentCacheJarPath
Path to the jar file where dynamic table DMO classes will be placed at server shutdown.
|
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
persistentCacheMap
Cache used to find out if a dynamic table DMO needs to be assembled or exists saved on disk.
|
private java.io.File |
persistentCacheMapFile
File object corresponding to the file with data used to identify cached dynamic table DMO classes.
|
private java.lang.String |
persistentCacheMapPath
Path to the file containing data used to identify cached dynamic table DMO classes.
|
(package private) static java.util.Map<ParmType,java.lang.Integer> |
propTypeToProgress
Param type to Progress type.
|
private static AsmClassLoader |
systemInMemoryClassLoader
In-memory class loader
|
private java.util.concurrent.atomic.AtomicLong |
tableCounter
Counter used for generation of unique names for dynamic tables.
|
private java.lang.String |
tempLibFilePath
Name of a temporary directory where .class files of dynamic table DMO classes are saved.
|
private java.lang.String |
temporaryJarName
Path to the jar file that will temprarily exist at server shutdown.
|
private boolean |
usePersistentCache
Marks if dynamic table DMO classes generated will be saved to/read from a persistent cache.
|
| Modifier | Constructor and Description |
|---|---|
private |
DynamicTablesHelper()
Private constructor to enforce singleton.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) static long |
assignIds(Aast root,
long startId)
Traverse an AST and assign unique IDs to all of its nodes.
|
private void |
cleanupDirectories()
Cleans up newly created directories.
|
void |
createCache()
Method meant to create a Jar file containing dynamic table classes that were
cached to disk, so that they are not generated every time the server is started.
|
private void |
createCacheHelper(java.io.File source,
java.util.jar.JarOutputStream target,
java.util.Set<java.lang.String> packages)
Helper method for creating the dynamic table classes jar/cache.
|
private void |
createDirectoryHierarchy(java.io.File dir)
Ensures the directory hierarchy exists by creating any missing directories.
|
(package private) boolean |
createDynamicDMO(TempTableBuilder builder,
java.lang.String legacyTableName,
java.lang.String legacyPeerName,
boolean isBeforeTable)
Generate DMO interface, implementation class and mapping document and register the new DMO type.
|
(package private) void |
deregisterBuilder(TempTableBuilder builder)
Deregister the given temp-table builder from the DMO resource manager.
|
(package private) void |
deregisterDmoUser(TempTableBuilder builder)
Remove this dynamic temp-table from the DMO users.
|
private void |
extractIndexes(DmoMeta dmoMeta,
java.util.ArrayList<P2JIndex> fwdIndexes)
Extracts the list of indexes from an interface into an array.
|
(package private) static Persistence |
findExistingTable(java.lang.String fullTableName)
Search for an existing table with the specified name.
|
private static Persistence |
findMetaPersistence(java.lang.String pdb,
java.lang.String tableName)
Find the
Persistence object that is associated with the given database and table. |
(package private) Aast |
generateSchemaAst(TempTableBuilder builder,
java.lang.String ifaceName,
java.lang.String tableName,
java.lang.String legacyTableName,
java.util.Map<java.lang.String,java.lang.String> fields4GLtoORM,
java.lang.String legacyPeerName,
boolean isBeforeTable)
Generate AST that represents the target table and has the same structure as .p2o files from
the conversion stage.
|
(package private) static java.lang.String |
get4GLFieldName(java.lang.Class<? extends DataModelObject> dmoIface,
java.lang.String dmoFieldName)
Get 4GL field name by DMO field name for a dynamic DMO.
|
(package private) static java.lang.String |
get4GLTableName(Persistence persistence,
java.lang.String tableName4GL)
Get original 4GL table name.
|
(package private) static java.lang.String |
getHibernateFieldName(java.lang.Class<? extends DataModelObject> dmoIface,
int fieldId)
Get DMO field name by field creation id for a dynamic DMO.
|
(package private) static java.lang.String |
getHibernateFieldName(java.lang.Class<? extends DataModelObject> dmoIface,
java.lang.String name4gl)
Get DMO field name by 4GL field name for a dynamic DMO.
|
static DynamicTablesHelper |
getInstance()
Get singleton instance of the helper.
|
(package private) static TempTableBuilder |
getTableInfo(RecordBuffer buffer)
Returns the
TempTableBuilder object that contains information about the 4GL
representation of the table or null if there is no corresponding dynamic table
for the specified record buffer. |
private void |
initializePersistentCacheData()
Method called at class initialization, meant to read from disk the data regarding
the dynamic table classes cache, saved in the form of a HashMap object.
|
(package private) static boolean |
isDynamicTableBuffer(RecordBuffer buffer)
Allows to determine if the buffer is for a dynamic table.
|
(package private) static java.lang.String[] |
parseTableName(java.lang.String fullTableName)
Get table name and database name from the string which represents full table name
|
private static java.lang.String |
rightTrim(java.lang.String str)
Convenience method to remove trailing whitespace (space, tab, line feed, carriage return) from the
string.
|
private void |
saveDynamicDmoToDisk(java.lang.String className,
byte[] code)
Method used to save to disk a dynamic table class generated at runtime as a .class file.
|
(package private) static boolean |
tableExists(Persistence persistence,
java.lang.String tableName4GL)
Determines if the specified table exists.
|
private void |
updatePersistentCacheMap()
Method used to update/create the file on disk that retains data about the
dynamic table classes cache, in the form of a HashMap object.
|
private static void |
writeJarIndex(java.util.jar.JarOutputStream jos,
java.util.Set<java.lang.String> packages)
Writes the jar index to the jar file's META-INF directory.
|
static final java.lang.String DMO_BASE_PACKAGE
static final java.lang.String DMO_IFACE_CATEGORY
static final java.util.Map<ParmType,java.lang.Integer> propTypeToProgress
private static final CentralLogger LOG
private static volatile DynamicTablesHelper instance
private static AsmClassLoader systemInMemoryClassLoader
private final java.util.Map<DynamicTablesHelper.CacheKey,DynamicTablesHelper.CacheData> cache
private final java.lang.Object cacheLock
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> persistentCacheMap
private boolean usePersistentCache
private java.lang.String tempLibFilePath
private java.lang.String persistentCacheJarPath
private java.lang.String persistentCacheMapPath
private java.lang.String temporaryJarName
private java.io.File persistentCacheJarFile
private java.util.List<java.io.File> createdDirectories
private static java.util.Set<java.lang.String> existingEntries
private java.io.File persistentCacheMapFile
private final ContextLocal<DynamicTablesHelper.Context> context
private final java.util.concurrent.atomic.AtomicLong tableCounter
private final DynamicTablesHelper.DMOResourceManager dmoResourceManager
private DynamicTablesHelper()
public static DynamicTablesHelper getInstance()
static java.lang.String getHibernateFieldName(java.lang.Class<? extends DataModelObject> dmoIface, java.lang.String name4gl)
dmoIface - DMO interface that corresponds the target dynamic DMO class.name4gl - 4GL field name.null if no
corresponding name was found.static java.lang.String getHibernateFieldName(java.lang.Class<? extends DataModelObject> dmoIface, int fieldId)
dmoIface - DMO interface that corresponds the target dynamic DMO class.fieldId - 4GL field id.null if no
corresponding name was found.static java.lang.String get4GLFieldName(java.lang.Class<? extends DataModelObject> dmoIface, java.lang.String dmoFieldName)
dmoIface - DMO interface that corresponds the target dynamic DMO class.dmoFieldName - DMO field name.null if no
corresponding name was found.static java.lang.String[] parseTableName(java.lang.String fullTableName)
fullTableName - The string which represents full table name. Can have two formats:
"databaseName.tableName" or "tableName".null if the database name wasn't specified in the
full table name.static boolean isDynamicTableBuffer(RecordBuffer buffer)
buffer - Buffer to check.true if buffer is for a dynamic table.static TempTableBuilder getTableInfo(RecordBuffer buffer)
TempTableBuilder object that contains information about the 4GL
representation of the table or null if there is no corresponding dynamic table
for the specified record buffer.buffer - Record buffer that corresponds to the target dynamic table.static boolean tableExists(Persistence persistence, java.lang.String tableName4GL)
persistence - Persistence which corresponds the target database.tableName4GL - 4GL table name.true if the specified table exists.static Persistence findExistingTable(java.lang.String fullTableName)
fullTableName - Table name in format "databaseName.tableName" or "tableName". In the latter case
table search is performed in all permanent databases and then the temporary
database. Dynamic tables are ignored.null if there is
no such table.static java.lang.String get4GLTableName(Persistence persistence, java.lang.String tableName4GL)
persistence - Persistence which corresponds the target database.tableName4GL - 4GL table name (case-insensitive, may have trailing spaces).static long assignIds(Aast root, long startId)
root - The root node of the AST.startId - First available id for assignment.private static Persistence findMetaPersistence(java.lang.String pdb, java.lang.String tableName)
Persistence object that is associated with the given database and table.pdb - Physical database name of primary database.tableName - Unqualified table name.Persistence object if table is foundprivate static java.lang.String rightTrim(java.lang.String str)
str - Target string.private void saveDynamicDmoToDisk(java.lang.String className,
byte[] code)
className - The name of the newly generated class that will be saved to disk.code - The contents of the class file as a byte array.private void initializePersistentCacheData()
private void updatePersistentCacheMap()
public void createCache()
private void createDirectoryHierarchy(java.io.File dir)
dir - The directory to create.private void cleanupDirectories()
private void createCacheHelper(java.io.File source,
java.util.jar.JarOutputStream target,
java.util.Set<java.lang.String> packages)
throws java.io.IOException
source - The class file or directory containing class files that will be added to the jar.target - The stream used to add files to the jar.packages - The set to collect package names.java.io.IOException - Exception that can be thrown by the JarOutputStream object, not handled here.private static void writeJarIndex(java.util.jar.JarOutputStream jos,
java.util.Set<java.lang.String> packages)
throws java.io.IOException
jos - The JarOutputStream to write the index to.packages - The set of package names to include in the index.java.io.IOException - Exception that can be thrown by the JarOutputStream object, not handled here.boolean createDynamicDMO(TempTableBuilder builder, java.lang.String legacyTableName, java.lang.String legacyPeerName, boolean isBeforeTable)
builder - Temporary table builder containing definitions of the target table.legacyTableName - The legacy name of the table.legacyPeerName - The legacy name of the table's peer. May be null.isBeforeTable - Flag indicating the DMO is being built for a before table.true on success.void deregisterBuilder(TempTableBuilder builder)
builder - Builder to be deregistered.void deregisterDmoUser(TempTableBuilder builder)
builder - Builder to be deregistered.private void extractIndexes(DmoMeta dmoMeta, java.util.ArrayList<P2JIndex> fwdIndexes)
dmoMeta - the metadata collection of the DMO interface.fwdIndexes - The destination array where the index data will be stored.Aast generateSchemaAst(TempTableBuilder builder, java.lang.String ifaceName, java.lang.String tableName, java.lang.String legacyTableName, java.util.Map<java.lang.String,java.lang.String> fields4GLtoORM, java.lang.String legacyPeerName, boolean isBeforeTable)
builder - Temporary table builder containing definitions of the target table.ifaceName - The name of the target DMO interface.tableName - The name of the target SQL table.legacyTableName - The legacy (Progress) name of the table.fields4GLtoORM - Map 4GL field names to ORM names.legacyPeerName - The legacy name of the table's peer. May be null.isBeforeTable - Flag indicating the DMO is being built for a before table.