<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.oracle.com/owb/miv"
            targetNamespace="http://www.oracle.com/owb/miv"
            elementFormDefault="qualified">
  <xsd:element name="miv">
    <xsd:annotation>
      <xsd:documentation>
        The root MIV element. The MIV defines how metadata should be read from a
        system. Each item being imported will have signature/interface that the
        SQL should project.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="miv_business_areas"  type="miv_sql_info" maxOccurs="1"
                     minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how business areas should be
              integrated. The context for the item is the schema or schemas
              selected.
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_business_area_objects"  type="miv_sql_info" maxOccurs="1"
                     minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how business area objects should be
              integrated. The context for the item is the schema or schemas
              selected.
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_schemas" type="miv_sql_info_base"
                     maxOccurs="1"  minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element defines the way to represent a schema - as in a
              schema from a database system for example. The query provided here
              should project a single column with the schema name. For example
              with Oracle;
              eg.
              select username from all_users
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_tables" type="miv_sql_info" maxOccurs="1" minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how tables should be integrated. The
              context for the table is the schema or schemas selected. The SQL
              query provided should project a single column with the name of the
              table. The query will be invoked for each schema selected, and the
              parameter named 'owner' will be available within the query for the
              SQL template provided.
              ie. For DB2UDB, the following query returns the tables for the
              schema selected;
              eg
              SELECT rtrim(tabname) table_name 
                      FROM syscat.tables  
                      WHERE tabschema = &lt;Parameter name="owner"/&gt; 
                              AND type = 'T'   
                              AND status = 'N'   
                      ORDER BY table_name
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_views"  type="miv_sql_info" maxOccurs="1" minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how views should be integrated. The
              context for the table is the schema or schemas selected. The SQL
              query provided should project a single column with the name of the
              viewe. The query will be invoked for each schema selected, and the
              parameter named 'owner' will be available within the query for the
              SQL template provided. ie. For DB2UDB, the following query returns
              the views for the schema selected; 
              eg. 
              SELECT rtrim(viewname) view_name,
                             text view_definition        
              	FROM syscat.views
              	WHERE viewschema = &lt;Parameter name="owner"/&gt; 
              	ORDER BY view_name
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_sequences" type="miv_sql_info" minOccurs="0" maxOccurs="1">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how sequences should be integrated. The
              context for the table is the schema or schemas selected. The SQL
              query provided should project a single column with the name of the
              sequence. The query will be invoked for each schema selected, and
              the parameter named 'owner' will be available within the query for
              the SQL template provided.
              ie. For DB2UDB, the following query returns the sequences for the
              schema;
              SELECT rtrim(seqname) sequence_name
              	FROM syscat.sequences
              	WHERE seqschema = &lt;Parameter name="owner"/&gt; 
              	ORDER BY sequence_name
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_columns" type="miv_sql_info" maxOccurs="1" minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how columns should be integrated. The
              context for the item is the schema or schemas selected and the
              table or view. The quert provided should project the following
              columns; tab_or_view_name column_name postion datatype length
              precision scale description nulls_allowed default codepage 1 'N';
              eg for DB2
              SELECT rtrim(col.tabname) entity_name, 
                             rtrim(col.colname), 
                             col.colno position, 
                             col.typename, 
                             col.length, 
                             col.length, 
                             col.scale, 
                             col.remarks, 
                             col.nulls,
                             col.default,
                             CHAR(col.codepage),
                             1,
                             'N'
                      FROM syscat.columns col
                      WHERE col.tabschema = &lt;Parameter name="owner"/&gt;
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_unique_keys" type="miv_sql_info" maxOccurs="1" minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how unique keys should be integrated. The
              context for the item is the schema or schemas selected and the
              table or view. The query should project the following columns;
              table_or_view_name key_name business_name description key_type (U,
              P or K);
              eg.
              SELECT rtrim(tabname) entity_name, 
                            rtrim(constname) key_name,
                            rtrim(constname) business_name,
                            remarks description,
                            rtrim(type)
                    FROM    syscat.tabconst
                    WHERE   upper(type) IN ('U', 'P', 'K')
                    AND     tabschema = &lt;Parameter name="owner"/&gt; 
                    ORDER BY key_name
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_foreign_keys" type="miv_sql_info" maxOccurs="1" minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how foreign keys should be integrated. The
              context for the item is the schema or schemas selected and the
              table or view. The query should project the following columns;
              table_or_view_name key_name business_name description
              referenced_key_name;
              eg.
              SELECT rtrim(fkkey.tabname) entity_name, 
                           rtrim(fkkey.constname) key_name, 
                           rtrim(fkkey.constname) business_name, 
                           '' description, 
                           fkkey.refkeyname 
                    FROM   syscat.references fkkey 
                    WHERE  fkkey.tabschema = &lt;Parameter name="owner"/&gt;
                    ORDER BY key_name
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_key_columns" type="miv_sql_info" minOccurs="0" maxOccurs="1">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how the key columns should be integrated.
              The context for the item is the schema or schemas selected and the
              key name. The query should project the following columns; key_name
              column_name position;
              eg.
              SELECT rtrim(col.constname) key_name, 
                           rtrim(col.colname) column_name, 
                           col.colseq position 
                    FROM   syscat.keycoluse col, 
                           syscat.keycoluse refcol 
                    WHERE  col.tabname = refcol.tabname 
                    AND    col.colname = refcol.colname 
                    AND    col.tabschema = refcol.tabschema 
                    AND    col.constname = refcol.constname
                    AND    col.tabschema = &lt;Parameter name="owner"/&gt; 
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_fk_tables" type="miv_sql_info" maxOccurs="1" minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how the tables referenced by the foreign
              keys should be integrated. The context for the item is the schema
              or schemas selected and the key name. The query should project the
              following columns; orig_table_name foreign_table_name
              foreign_table_description;
              eg.
              SELECT  rtrim(refkey.tabname) orig_table_name,
                            rtrim(refkey.reftabname) foreign_table_name,
                            fktable.remarks foreign_table_description
                    FROM    syscat.references refkey,
                            syscat.tables fktable,
                            syscat.tabconst const
                    WHERE   refkey.tabname = fktable.tabname
                    AND     refkey.tabschema = fktable.tabschema
                    AND     upper(const.type) = 'F'
                    AND     const.tabname = fktable.tabname
                    AND     const.tabschema = fktable.tabschema
                    AND     refkey.tabschema = &lt;Parameter name="owner"/&gt;
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_functions"  type="miv_sql_info" maxOccurs="1" minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how functions keys should be integrated.
              The context for the item is the schema or schemas selected.
              eg.
               SELECT  b.ROUTINENAME, a.SPECIFICNAME, b.PARMNAME,
                           b.TYPENAME, b.ROWTYPE 
                   FROM SYSCAT.ROUTINES a, SYSCAT.ROUTINEPARMS b
                   WHERE  b.SPECIFICNAME = a.SPECIFICNAME
                   AND      b.ROUTINESCHEMA = &lt;Parameter name="owner"/&gt;
                   AND     b.SPECIFICNAME
                           IN ( SELECT  DISTINCT SPECIFICNAME
                                FROM
                                        SYSCAT.ROUTINES
                                WHERE   FUNCTIONTYPE = 'S'
                                AND     LANGUAGE = 'SQL' AND ROUTINESCHEMA =
              &lt;Parameter name="owner"/&gt;
                                AND ROUTINENAME LIKE &lt;Parameter
              name="filter"/&gt;
                              )
                  ORDER BY a.SPECIFICNAME
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_parameters"  type="miv_sql_info" maxOccurs="1" minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how parameters should be integrated. The
              context for the item is the schema or schemas selected and the
              function.
              eg.
              SELECT ROUTINENAME, PARMNAME, TYPENAME, ROWTYPE, ORDINAL 
                  FROM  SYSCAT.ROUTINEPARMS 
                  WHERE  ROUTINESCHEMA = &lt;Parameter name="owner"/&gt; 
                  AND      SPECIFICNAME = &lt;Parameter name="object"/&gt;
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_implementations"  type="miv_sql_info" maxOccurs="1" minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how function implementations should be
              integrated. The context for the item is the schema or schemas
              selected and the function.
              eg.
              SELECT ROUTINENAME, TEXT  
                  FROM    SYSCAT.ROUTINES 
                  WHERE  ROUTINESCHEMA = &lt;Parameter name="owner"/&gt; 
                  AND     ROUTINETYPE ='F' 
                  AND       SPECIFICNAME = &lt;Parameter name="object"/&gt;
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_function_overloading_supported"  type="miv_sql_info" maxOccurs="1"
                     minOccurs="0">
          <xsd:annotation>
            <xsd:documentation>
              This element determines how  function overloading should be
              integrated. The context for the item is the schema or schemas
              selected and the function.
            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
        <xsd:element name="miv_capabilities" minOccurs="1" maxOccurs="1">
          <xsd:annotation>
            <xsd:documentation>
              Define what capabiltiies the MIV supports. Some systems will not
              support views for example others have no functions. The elements
              defined here will inform the OWB MIV of what functionality the MIV
              supports.
            </xsd:documentation>
          </xsd:annotation>
          <xsd:complexType>
           <xsd:sequence minOccurs="0" maxOccurs="1">
            <xsd:element name="table_supported" type="miv_support" default="true"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports the import of tables. The
                    text value for the element may be true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="view_supported" type="miv_support" default="false"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports the import of views. The
                    text value for the element may be true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="sequence_supported" type="miv_support" default="false"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports the import of sequences.
                    The text value for the element may be true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="table_name_filter_supported" type="miv_support" default="true"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports filtering of tables when
                    tables are imported. The text value for the element may be
                    true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="view_name_filter_supported" type="miv_support" default="false"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports filtering of views when
                    views are imported. The text value for the element may be
                    true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="sequence_name_filter_supported" type="miv_support" default="false"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports filtering of sequences
                    when sequences are imported. The text value for the element
                    may be true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="business_area_supported" type="miv_support" default="false"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports the import of objects via
                    a business area. Business areas are common in large
                    application environments. The text value for the element may
                    be true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="business_area_table_supported" type="miv_support" default="false"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports the import of tables via a
                    business area. Business areas are common in large
                    application environments. The text value for the element may
                    be true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="business_area_view_supported" type="miv_support" default="false"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports the import of views via a
                    business area. Business areas are common in large
                    application environments. The text value for the element may
                    be true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="business_area_sequence_supported"
                         type="miv_support" default="false" minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports the import of sequences
                    via a business area. Business areas are common in large
                    application environments. The text value for the element may
                    be true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="application_owner_supported" type="miv_support" default="true"
                         minOccurs="0"/>
            <xsd:element name="table_fklevel_supported" type="miv_support" default="true"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether this MIV supports the import of foreign key
                    tables. The text value for the element may be true or false.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="reimport_supported" type="miv_support" default="true"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Defines whether reimport is supported.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="data_object_at_leaf_levels" type="miv_support" default="true"
                         minOccurs="0"/>
            <xsd:element name="multiple_tree_supported" type="miv_support" default="false"
                         minOccurs="0"/>
            <xsd:element name="function_supported" type="miv_support" default="false"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Define whether function import is supported.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
            <xsd:element name="function_name_filter_supported" type="miv_support" default="false"
                         minOccurs="0">
                <xsd:annotation>
                  <xsd:documentation>
                    Define whether when importing functions they can be filtered.
                  </xsd:documentation>
                </xsd:annotation>
              </xsd:element>
           </xsd:sequence>
           <xsd:attribute name="type" default="ResultSet" type="xsd:string" use="required"/>
           <xsd:attribute name="default" default="true"/>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
    <!--The OWB MIV framework provides a mechanism for adding custom integration poviders for metadata into OWB.
-->
  </xsd:element>
    <xsd:simpleType name="miv_sql_base">
    <xsd:restriction base="xsd:string">
      <xsd:minLength value="0"/>
      <xsd:maxLength value="32000"/>
    </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="miv_support">
    <xsd:restriction base="xsd:string">
    </xsd:restriction>
    </xsd:simpleType>
  <xsd:complexType name="miv_sql_info_base" mixed="true">
    <xsd:attribute name="type" type="xsd:string" default="SQLStatement"
                       use="required"/>
    <xsd:attribute name="default"  type="xsd:string" default="true"/>
  </xsd:complexType>
  <xsd:complexType name="miv_sql_info"  mixed="true">
    <xsd:sequence>
      <xsd:element name="Parameter" maxOccurs="unbounded" minOccurs="0">
        <xsd:annotation>
          <xsd:documentation>
            Parameters to template SQL that the user can have replaced when the
            queries are executed. The parameters supported include;
            	owner
            	dblink
            	object
            	filter
          </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
          <xsd:attribute name="name" type="miv_parameter_name"/>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="type" type="xsd:string" default="SQLStatement"
                       use="required"/>
    <xsd:attribute name="default"  type="xsd:string" default="true"/>
  </xsd:complexType>
  <xsd:simpleType name="miv_parameter_name">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="owner"/>
      <xsd:enumeration value="dblink"/>
      <xsd:enumeration value="object"/>
      <xsd:enumeration value="filter"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:annotation>
    <xsd:documentation>
      MIV XML Schema. Generic Metadata Integration Framework.
    </xsd:documentation>
  </xsd:annotation>
</xsd:schema>
