public final class P2OLookup extends java.lang.Object implements DataModelTokenTypes
P2JIndex
,
P2JIndexComponent
Modifier and Type | Class and Description |
---|---|
private static class |
P2OLookup.WorkArea
Container with user-specific data.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ABBREVIATED
Key for "abbreviated" index column AST annotation
|
static java.lang.String |
CASE_SENSITIVE
Key for "case-sensitive" annotation in data model AST
|
static java.lang.String |
CFG_NAME
Name of schema dictionary configuration
|
private java.util.Map<java.lang.Long,Aast> |
classByIDMap
Map of AST IDs to class ASTs
|
static java.lang.String |
DATATYPE
Key for "datatype" property AST annotation
|
private java.util.Set<java.lang.String> |
denormalizedProperties
Set of historical fully qualified denormalized properties of fields with custom extent
|
static java.lang.String |
DESCEND
Key for "descend" index column AST annotation
|
static java.lang.String |
EXTENT
Key for "extent" property AST annotation
|
static java.lang.String |
FOREIGN
Key for "foreign" relation AST annotation
|
private java.util.Map<java.lang.String,java.util.Set<java.lang.Long>> |
foreignReferenceMap
Map of historical table names to sets of referencing tables
|
static java.lang.String |
HISTORICAL
Key for "historical" class/property AST annotation
|
private java.util.Set<java.lang.String> |
historicalMetaTables
Stores the list of meta tables
|
static java.lang.String |
IGNORE_CASE
Key for "ignore-case" index column AST annotation
|
private java.util.Map<java.lang.String,java.util.List<P2JIndex>> |
indexMap
Map of historical table names to index descriptors
|
private java.util.Map<java.lang.String,java.util.Map<java.lang.Long,java.lang.String>> |
javaNameMap
Map of historical table/field names to Java class/property names
|
private java.util.Set<java.lang.String> |
javaNames
Set of all unqualified DMO Java interface names
|
private java.lang.String |
javaPackage
Java package associated with this lookup instance
|
private static ContextLocal<P2OLookup.WorkArea> |
local
Container with user-specific data.
|
private java.lang.String |
metaPackage
Java package associated with this lookup instance metadata
|
private java.util.Map<java.lang.String,java.lang.String> |
originalNamesMap
Map with normalized to original names of table/field names.
|
static java.lang.String |
P2O_POSTFIX
File extension appended to schema and source filenames
|
static java.lang.String |
PACKAGE
Key for "package" database AST annotation
|
private static java.util.Map<java.lang.String,P2OLookup> |
permSchemaMap
Shared map of permanent database schema names to
P2OLookup instances |
static java.lang.String |
PRIMARY
Key for "primary" index AST annotation
|
private java.util.Map<java.lang.Long,Aast> |
propsMap
Map of property AST unique IDs to the AST nodes.
|
static java.lang.String |
READ_ONLY
Key for "read-only" class AST annotation
|
private java.util.Set<java.lang.String> |
readOnlyTables
Set of schema names of read-only tables
|
static java.lang.String |
REFERENCES
Key for "references" relation AST annotation
|
static java.lang.String |
REFID
Key for "refid" index column AST annotation
|
static java.lang.String |
SYNTHETIC
Key for "synthetic" index AST annotation
|
static java.lang.String |
TABLE
Key for "table" class AST annotation
|
private static java.lang.String |
TEMP_TABLE_KEY
Key for current temp table schema in schema map
|
static java.lang.String |
UNIQUE
Key for "unique" index AST annotation
|
static java.lang.String |
VALIDATABLE
Key for "validatable" property AST annotation
|
private java.util.Set<java.lang.String> |
validatables
Set of schema names of validatable fields
|
static java.lang.String |
WORD
Key for "word" index AST annotation
|
BOOL_FALSE, BOOL_TRUE, CLASS, COMPOSITE, CONSTR_COL, DATA_MODEL, DATE_LITERAL, DATETIME_LITERAL, DATETIME_TZ_LITERAL, DEC_LITERAL, GENERATOR, INDEX, INDEX_COL, INITIAL, MANY_TO_ONE, NULL_LITERAL, NUM_LITERAL, ONE_TO_MANY, ONE_TO_ONE, PROPERTY, SEQUENCE, STRING, UNKNOWN
Modifier | Constructor and Description |
---|---|
private |
P2OLookup(java.lang.String schema)
Constructor which initializes this object with the information in the
P2O AST associated with
schema . |
private |
P2OLookup(java.lang.String schema,
java.lang.String filename)
Constructor which initializes this object with the information in the
P2O AST stored in
filename . |
Modifier and Type | Method and Description |
---|---|
private void |
addJavaName(java.lang.String originalName,
java.lang.String propertyName,
java.lang.Long index,
java.lang.String denormalizedPropertyName)
Adds property name to javaNameMap where the key is legacy field name and value is map
based on nullable index.
|
static java.lang.String |
beanMethodName(java.lang.String prefix,
java.lang.String historical)
Compose a bean-like getter/setter method name from the Java DMO
property associated with the specified, legacy, Progress field name.
|
static java.lang.String |
beanMethodName(java.lang.String prefix,
java.lang.String historical,
java.lang.Long index)
Compose a bean-like getter/setter method name from the Java DMO
property associated with the specified, legacy, Progress field name.
|
private boolean |
containsDMOInterface(java.lang.String name)
Report whether the given class name is the unqualified name of any DMO
interface in the schema represented by this lookup object.
|
static void |
dumpTableDependencies(java.lang.String historical)
Dump an exhaustive tree of nested table dependencies.
|
private void |
dumpTableDependencies(java.lang.String historical,
int indent)
Dump an exhaustive tree of nested table dependencies.
|
private java.util.List<P2JIndex> |
getIndexes(java.lang.String historical)
Get the full list of index descriptors associated with a Progress table.
|
private static P2OLookup |
getInstance(java.lang.String historical,
int type)
Get or create a
P2OLookup instance, given a schema name or
a fully qualified, legacy table or field name. |
private java.lang.String |
getJavaName(java.lang.String historical)
Get the converted, Java name of the class or property associated with
the given, legacy table or field name (respectively).
|
private java.lang.String |
getJavaName(java.lang.String historical,
java.lang.Long index)
Get the converted, Java name of the class or property associated with
the given, legacy table or field name (respectively).
|
private java.lang.String |
getJavaPackage(boolean meta)
Get the Java package name for the DMO interface classes associated with
this lookup object's schema.
|
private java.util.Set<java.lang.String> |
getLegacyFieldNames(java.lang.String historical)
Get the set of legacy field names for a particular legacy table.
|
static java.util.Iterator<P2JIndex> |
indexes(java.lang.String historical)
Get an iterator on all the index descriptors associated with the given,
legacy table.
|
static void |
initialize()
Initialize a
P2OLookup instance for the schema of each primary database managed by
this server. |
private void |
initialize(java.lang.String schema)
Initialize this
P2OLookup instance by loading the P2O AST associated with the
specified schema, walking it, and extracting and organizing the relevant information. |
private void |
initialize(java.lang.String schema,
Aast root,
boolean meta)
Initialize this
P2OLookup instance by walking the given
P2O AST and extracting and organizing the relevant information. |
private void |
initializeIndexes(java.lang.String historical,
Aast classAst)
Compose a list of index descriptors for the index children of the
given P2O class node and map it to the given, legacy table name.
|
private void |
initializeRelations(java.lang.String historical,
Aast classAst)
Compose and store the set of tables which refer to a database table via
a foreign key, given the referent table's P2O class node and its legacy
name.
|
static boolean |
isDenormalizedProperty(java.lang.String historical)
Check if given historical fully qualified property is denormalized.
|
static boolean |
isDMOInterface(java.lang.String name)
Report whether the given class name is the unqualified name of any DMO
interface, in any schema tracked by the current P2J configuration.
|
static boolean |
isDMOInterface(java.lang.String name,
java.lang.String schema)
Report whether the given class name is the unqualified name of a DMO interface, in the
schema tracked by the current P2J configuration. |
static boolean |
isForeignReference(java.lang.String historical)
Report whether the given, historical table will be mapped in the
converted application to a database table which represents a foreign
reference of another table's foreign key.
|
static boolean |
isReadOnly(java.lang.String historical)
Indicate whether a DMO class represents a read-only table, given its schema name.
|
static boolean |
isValidatable(java.lang.String historical)
Indicate whether a DMO property can be validated at runtime, given its
legacy schema name.
|
static java.lang.String |
javaName(java.lang.String historical,
int type)
Retrieve a Java class or variable name, based upon the legacy Progress
schema name of the corresponding table or field, respectively.
|
static java.lang.String |
javaName(java.lang.String historical,
int type,
java.lang.Long index)
Retrieve a Java class or variable name, based upon the legacy Progress schema name of the
corresponding table or field, respectively.
|
static java.lang.String |
javaPackage(java.lang.String historical)
Retrieve the Java package name of the DMO associated with the given
legacy Progress table name.
|
static java.lang.String |
javaPropertyName(java.lang.String historical,
boolean qualified)
Retrieve a Java property name, based upon the legacy Progress schema
name of the corresponding table or field, respectively.
|
static java.lang.String |
javaPropertyName(java.lang.String historical,
boolean qualified,
java.lang.Long index)
Retrieve a Java property name, based upon the legacy Progress schema
name of the corresponding table or field, respectively.
|
static java.util.Set<java.lang.String> |
legacyFieldNames(java.lang.String historical)
Retrieve the full set of fully qualified, legacy field names for a
legacy Progress table.
|
private Aast |
loadAst(java.lang.String database)
Load the persisted, P2O AST associated with the specified database
schema.
|
static void |
loadTemporarySchema(java.lang.String filename)
Attempt to load the P2O AST stored in
filename , which must
represent a temp/work-table schema. |
private static P2OLookup.WorkArea |
locate()
Get the context-local
P2OLookup.WorkArea instance. |
static void |
main(java.lang.String[] args)
Test harness for property name lookup feature.
|
private static java.util.Iterator<java.lang.String> |
schemaNames()
Get an iterator on all schema names managed by the current P2J
configuration.
|
public static final java.lang.String CFG_NAME
public static final java.lang.String P2O_POSTFIX
public static final java.lang.String PACKAGE
public static final java.lang.String HISTORICAL
public static final java.lang.String DATATYPE
public static final java.lang.String EXTENT
public static final java.lang.String VALIDATABLE
public static final java.lang.String READ_ONLY
public static final java.lang.String TABLE
public static final java.lang.String UNIQUE
public static final java.lang.String PRIMARY
public static final java.lang.String SYNTHETIC
public static final java.lang.String WORD
public static final java.lang.String REFID
public static final java.lang.String DESCEND
public static final java.lang.String IGNORE_CASE
public static final java.lang.String CASE_SENSITIVE
public static final java.lang.String ABBREVIATED
public static final java.lang.String FOREIGN
public static final java.lang.String REFERENCES
private static final java.lang.String TEMP_TABLE_KEY
private static final ContextLocal<P2OLookup.WorkArea> local
private static final java.util.Map<java.lang.String,P2OLookup> permSchemaMap
P2OLookup
instancesprivate final java.util.Set<java.lang.String> historicalMetaTables
private final java.util.Map<java.lang.Long,Aast> classByIDMap
private final java.util.Map<java.lang.String,java.util.Map<java.lang.Long,java.lang.String>> javaNameMap
private final java.util.Map<java.lang.String,java.lang.String> originalNamesMap
javaNameMap
but not here, then the name is already the
original form.private final java.util.Set<java.lang.String> denormalizedProperties
private final java.util.Map<java.lang.String,java.util.List<P2JIndex>> indexMap
private final java.util.Map<java.lang.String,java.util.Set<java.lang.Long>> foreignReferenceMap
private final java.util.Map<java.lang.Long,Aast> propsMap
private final java.util.Set<java.lang.String> validatables
private final java.util.Set<java.lang.String> readOnlyTables
private final java.util.Set<java.lang.String> javaNames
private java.lang.String javaPackage
private java.lang.String metaPackage
private P2OLookup(java.lang.String schema) throws SchemaException
schema
.schema
- Database schema name which determines which P2O AST to load.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.private P2OLookup(java.lang.String schema, java.lang.String filename) throws SchemaException
filename
. This variant is intended to
be used to load temp/work-table schema information. If there is no
file with name filename
, we still update the static
schema map, in order to replace the P2OLookup
instance
(if any) already associated with schema
. This ensures
that we are not using out-of-date temp table schema information.schema
- Database schema name to which this instance is mapped.filename
- Name of file containing the P2O AST to load. File may or may
not exist.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.public static void initialize() throws SchemaException
P2OLookup
instance for the schema of each primary database managed by
this server.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.public static void loadTemporarySchema(java.lang.String filename)
filename
, which must
represent a temp/work-table schema. This method should be invoked by
conversion service pattern workers which need to load temporary schema
information upon loading a new source file AST. A new instance of this
class is created as a result, and is stored in the schema map, under
the temp table schema key. If this method is invoked more than once in
succession with the same file name, only the first invocation triggers
the P2O AST to be loaded.
If no file exists with the name filename
, an empty
instance of this class is stored in the schema map under the temp table
schema key. This ensures that an out-of-date P2OLookup
instance is not maintained under the temp table key beyond it useful
life.
filename
- Name of file containing the P2O AST to load. File may or may
not exist, but this value may not be null
.java.lang.RuntimeException
- if there is any error loading or parsing the P2O AST data for
the given file; non-existence of the file is not considered
an error.public static boolean isDMOInterface(java.lang.String name) throws SchemaException
name
- An unqualified class name.true
if name
collides with any DMO
interface in any schema, else false
.SchemaException
- if there is an error loading schema names from configuration.public static boolean isDMOInterface(java.lang.String name, java.lang.String schema) throws SchemaException
schema
tracked by the current P2J configuration.name
- An unqualified class name.schema
- The name of the schema to look into.true
if name
is present as java name of a table from
the specified schema
and false
if schema
does not exist or it does not contain such interface.SchemaException
- if there is an error loading schema names from configuration.public static boolean isForeignReference(java.lang.String historical) throws SchemaException
historical
- Fully qualified, legacy Progress table name (not mandatory normalized).true
if the given table represents the foreign
end of a one-to-one or a one-to-many relation between two
tables.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.public static void dumpTableDependencies(java.lang.String historical) throws SchemaException
historical
- Fully qualified, legacy Progress table name.SchemaException
- if there is any error loading the AST from persistence.public static java.lang.String javaPackage(java.lang.String historical) throws SchemaException
historical
- Fully qualified, legacy, Progress schema name for a table.null
if no
associated DMO or package name was found.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.public static java.lang.String javaName(java.lang.String historical, int type) throws SchemaException
historical
- Fully qualified, legacy, Progress schema name for a table or
field.type
- EntityName
constant to indicate whether
historical
represents a table or a field.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence;
if the table or field portion of historical
cannot be resolved to a corresponding Java name.public static java.lang.String javaName(java.lang.String historical, int type, java.lang.Long index) throws SchemaException
historical
- Fully qualified, legacy, Progress schema name for a table or field (may not be
normalized).type
- EntityName
constant to indicate whether historical
represents a table or a field.index
- Zero-based index of custom property name for denormalized field with extent,
otherwise null.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence;
if the table or field portion of historical
cannot be resolved to a
corresponding Java name.public static java.util.Set<java.lang.String> legacyFieldNames(java.lang.String historical) throws SchemaException
historical
- Fully qualified, legacy, Progress schema name for a table.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence;
if historical
does not represent a known table.public static java.lang.String javaPropertyName(java.lang.String historical, boolean qualified) throws SchemaException
historical
- Fully qualified, legacy, Progress schema name for a table or
field.qualified
- true
if property name should be qualified with a
buffer name; false
if it should remain
unqualified.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence;
if the table or field portion of historical
cannot be resolved to a corresponding Java name.public static java.lang.String javaPropertyName(java.lang.String historical, boolean qualified, java.lang.Long index) throws SchemaException
historical
- Fully qualified, legacy, Progress schema name for a table or
field.qualified
- true
if property name should be qualified with a
buffer name; false
if it should remain
unqualified.index
- Zero-based index of custom property name for denormalized field with extent,
otherwise null.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence;
if the table or field portion of historical
cannot be resolved to a corresponding Java name.public static java.util.Iterator<P2JIndex> indexes(java.lang.String historical) throws SchemaException
historical
- Fully qualified, legacy Progress table name (may not be normalized).historical
.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.public static java.lang.String beanMethodName(java.lang.String prefix, java.lang.String historical) throws SchemaException
prefix
.prefix
- Verb to prepend to the capitalized property name; typically,
"get", "is", or "set".historical
- Fully qualified, legacy, Progress schema name for a database
field.SchemaException
- if this request results in the loading of a persisted P2O AST
and there is any error loading P2J schema configuration data
or loading the AST from persistence; if the field portion of
historical
cannot be resolved to a corresponding
Java name.public static java.lang.String beanMethodName(java.lang.String prefix, java.lang.String historical, java.lang.Long index) throws SchemaException
prefix
.prefix
- Verb to prepend to the capitalized property name; typically,
"get", "is", or "set".historical
- Fully qualified, legacy, Progress schema name for a database
field.index
- Zero-based index of custom property name for denormalized field with extent,
otherwise null.SchemaException
- if this request results in the loading of a persisted P2O AST
and there is any error loading P2J schema configuration data
or loading the AST from persistence; if the field portion of
historical
cannot be resolved to a corresponding
Java name.public static boolean isDenormalizedProperty(java.lang.String historical) throws SchemaException
historical
- Historical fully qualified property name.true
if given property is denormalized.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.public static boolean isValidatable(java.lang.String historical) throws SchemaException
historical
- Fully qualified, legacy Progress field name.true
if the field should be validated at runtime,
else false
.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.public static boolean isReadOnly(java.lang.String historical) throws SchemaException
historical
- Fully qualified, legacy Progress table name.true
if the table is read-only, else false
.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.private static java.util.Iterator<java.lang.String> schemaNames() throws SchemaException
SchemaException
- if there is an error loading schema names from configuration.private static P2OLookup.WorkArea locate()
P2OLookup.WorkArea
instance.private static P2OLookup getInstance(java.lang.String historical, int type) throws SchemaException
P2OLookup
instance, given a schema name or
a fully qualified, legacy table or field name. If the specified schema
has not been processed previously, a new instance is created and
cached; otherwise, a cached instance is returned.historical
- Schema name or fully qualified, legacy table or field name (may not be normalized).type
- EntityName
type, indicating whether the name
historical
represents a schema, table, or field.P2OLookup
instance.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.private java.lang.String getJavaPackage(boolean meta)
meta
- Return the metadata package name.private boolean containsDMOInterface(java.lang.String name)
name
- An unqualified class name.true
if name
collides with any DMO
interface in this schema, else false
.private java.lang.String getJavaName(java.lang.String historical)
historical
- Fully qualified, legacy table or field name. Must be normalized (in lowercase).private java.lang.String getJavaName(java.lang.String historical, java.lang.Long index)
historical
- Fully qualified, legacy table or field name. Must be normalized (in lowercase).index
- Zero-based index of custom property name for denormalized field with extent,
otherwise null.private java.util.Set<java.lang.String> getLegacyFieldNames(java.lang.String historical)
historical
- Fully qualified, legacy table or field name (not necessarily normalized).private java.util.List<P2JIndex> getIndexes(java.lang.String historical)
historical
- Fully qualified, legacy table name (not necessarily normalized).historical
. The list may be empty, but will not be null
.private void initialize(java.lang.String schema) throws SchemaException
P2OLookup
instance by loading the P2O AST associated with the
specified schema, walking it, and extracting and organizing the relevant information.
Currently, initialization does the following:
After the primary schema is walked, we also walk the metadata schema, loading all of its elements under the primary schema. This ensures all metadata references are resolved to the correct database.
schema
- Name of database schema associated with the target P2O AST.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.private void initialize(java.lang.String schema, Aast root, boolean meta) throws SchemaException
P2OLookup
instance by walking the given
P2O AST and extracting and organizing the relevant information.
Currently, initialization does the following:
schema
- Name of database schema associated with the target P2O AST.root
- Root node of P2O AST to inspect.meta
- Flags the schema as metadata information.SchemaException
- if there is any error loading P2J schema configuration data;
if there is any error loading the AST from persistence.private void addJavaName(java.lang.String originalName, java.lang.String propertyName, java.lang.Long index, java.lang.String denormalizedPropertyName)
originalName
- Legacy field name (not necessarily normalized).propertyName
- Property name.index
- Null-based index of custom property name for denormalized field with extent,
otherwise null.denormalizedPropertyName
- Denormalized property name for denormalized field with extent,
otherwise null.private void initializeIndexes(java.lang.String historical, Aast classAst)
historical
- Fully qualified, legacy table name (not necessarily normalized).classAst
- P2O AST node describing a DMO; the direct parent of all P2O index nodes.private void initializeRelations(java.lang.String historical, Aast classAst)
historical
- Fully qualified, legacy table name (may not be normalized).classAst
- P2O AST node describing a DMO; the direct parent of all P2O relation nodes.private Aast loadAst(java.lang.String database) throws ConfigurationException, AstException
database
- Logical name of database schema associated with the P2O
AST to be loaded.database
.ConfigurationException
- if there is any error loading P2J schema configuration data.AstException
- if there is any error loading the AST from persistence.private void dumpTableDependencies(java.lang.String historical, int indent)
historical
- Fully qualified, legacy Progress table name.indent
- Level of indent to apply when printing this table.public static void main(java.lang.String[] args)
args
- Not used.