Ensuring Valid Views When Applying a Feature Schema Against a Foreign Schema

FDO API

 
Ensuring Valid Views When Applying a Feature Schema Against a Foreign Schema
 
 
 

The ApplySchema command can creates invalid views when the feature schema is applied against a foreign schema. When you apply against a foreign schema, tables and columns are not automatically created if they do not already exist. A view is created, however, in the connected data store that references these foreign tables and columns. ApplySchema succeeds even if certain tables or columns cannot be obtained for various reasons, such as:

  • The database link to the foreign tables is invalid.
  • The Oracle instance containing the foreign tables is shut down or unreachable due to network problems.
  • The foreign table or column simply does not exist.

When one of these situations occurs, ApplySchema creates invalid (dangling) views because these views reference tables or columns that cannot be reached.

Invalid views can occur regardless of whether schema overrides have been specified because the default schema mappings can also reference unreachable tables or columns. For example, if the feature schema being applied has a Pole class with no table name override, the Pole class is mapped to the POLE table in the foreign schema and a POLE view (referencing the POLE table) is created in the data store that the Oracle provider is currently connected to. If the POLE table does not exist, then the POLE view is dangling, or invalid.

Use one of the following procedures to correct invalid views, depending on whether the correct table name was specified (either through a schema override or the default class to table mapping rule):

Procedure When Table Name Is Correct

If the table name is correct, but it is not reachable for the reasons listed above:

  1. Create the table or make it reachable by fixing the database link, fixing network problems, or starting the Oracle instance that contains the table.
  2. Recompile the view that references the table.

The Oracle SQL statement for recompiling the view is:

Alter view <view_name> compile;

If there are a number of views to recompile, an alternative method is to use the following procedure for a wrong table name, but only do Steps 1 and 3.

Procedure When Wrong Table Name Is Specified

If the wrong table name is specified, to ensure valid views:

  1. Destroy the feature schema. As long as the feature schema maps onto a foreign schema, destroying it does not result in loss of data. No tables or columns are dropped, only the referencing views created by FDO Provider for Oracle are dropped.
  2. Fix the schema overrides to supply the proper table name. In some cases, you may need to add a schema override. For example, if a class named "Pole" corresponds to the foreign table "telco_pole", then a table name override must be specified for the Pole class, since the class and table names differ.
  3. Re-apply the feature schema.

If your feature schema contains a mixture of classes mapped to foreign tables and classes mapped to non-foreign tables, then the procedure is slightly more complex, especially if any non-foreign table contains data. In this case, the following steps must be done programmatically throughout the FDO API:

  1. Describe the feature schema using the DescribeSchema command. Retain this description.
  2. Remove every class, except the one with the wrong table name, from the feature schema returned. However, do not delete the classes (that is, do not call FdoClassDefinition::Delete()).
  3. Describe the feature schema again (ensure that you retain the feature schema from the first Describe).
  4. Delete the class with the wrong table name from the feature schema returned by the second Describe (by calling its FdoClassDefinition::Delete() function).
  5. Fix the schema overrides to supply the proper table name.
  6. Ensure that FdoIApplySchema::SetIgnoreStates() is set to false, then Apply the feature schema described from Step 3. This deletes the class to repair.
  7. Ensure that FdoIApplySchema::SetIgnoreStates() is set to true, then Apply the feature schema described from Step 1, along with the schema overrides. This re-creates the class to repair.

Overrides Capable of Causing Invalid Views

Any schema mapping between a feature schema element and a table or column can create invalid views. This is true for mappings specified through schema overrides or for default mappings. The specific schema mappings that can cause invalid views are as follows:

  • Class to Table name
  • Class to Geometry Column name
  • Data Property to Column name
  • Geometric Property to Column name
  • Object Property to Table name