<?xml version="1.0"?>
<!-- Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. -->
<miv>
<!--
/*
    NO CHANGES MADE HERE - ALREADY MISSING NOT_SO_NEW COLUMNS
    If this is to be used, synchronize with DB2/SQLServer definitions
    If not, it should be removed

 ******************************************************************************
 * WARNING: For non-DB2/SQLSERVER miv types, the "implementation" will be to  *
 *          return constants. As they are brought on line, the owner/developer*
 *          should add real implementations were possible.                    *
 ******************************************************************************
    Added three columns at end of current miv_columns query (see DB2/SQLSERVER):
      NULL CHARSET, 1 BYTES_PER_CHAR, 'N' USE_CHAR_SEMANTICS

      CHARSET: The IANA charset [RFC 2978] corresponding to the character
               set/code page defined for this attribute on the metadata source.

      BYTES_PER_CHAR: The (max) number of bytes required to represent a 
                      character in the charset. int, default = 1

      USE_CHAR_SEMANTICS: Did the definition for this attribute on the metadata
                          source specify character semantics? (Y/N) default N
 */
-->

<miv_tables type="SQLStatement" default="true">
        SELECT rtrim(table_name) table_name, rtrim(table_name) || '  ' || substr(comments, 1, 2000)  business_name, substr(comments, 1, 2000) description 
        FROM all_tab_comments<Parameter name="dblink"/> atc  
        WHERE table_type = 'TABLE' 
                AND owner = <Parameter name="owner"/>   
                AND NOT EXISTS (SELECT table_name 
                                FROM all_snapshots<Parameter name="dblink"/> 
                                WHERE table_name = atc.table_name 
                                      AND owner = <Parameter name="owner"/>) 
</miv_tables>

<miv_views type="SQLStatement" default="true">
	SELECT rtrim(v.view_name) view_name, 
               rtrim(v.view_name) || '  ' || substr(atc.comments, 1, 2000)  business_name, 
               substr(atc.comments, 1, 2000) description,
               v.text view_definition
	FROM all_views<Parameter name="dblink"/> v,
             all_tab_comments<Parameter name="dblink"/> atc
	WHERE   v.view_name = atc.table_name
                AND atc.table_type = 'VIEW'
		AND v.owner = <Parameter name = "owner"/>
	ORDER BY view_name
</miv_views>

<miv_sequences type="SQLStatement" default="true">
	SELECT rtrim(sequence_name) sequence_name, rtrim(sequence_name) business_name, '' description
	FROM all_sequences<Parameter name="dblink"/>
	WHERE sequence_owner = <Parameter name="owner"/>
	ORDER BY sequence_name
</miv_sequences>

<miv_columns type="SQLStatement" default="true">
	SELECT ac.table_name entity_name, 
               ac.column_id position, 
               rtrim(ac.column_name) column_name, 
	       rtrim(ac.data_type) data_type, 
               ac.data_length length, 
               ac.data_precision precision, 
               ac.data_scale scale, 
               substr(acc.comments, 1, 2000) description, 
               ac.nullable isNullable,
               '' DATA_TYPE_OWNER,
               '' DATA_DEFAULT,
                decode(ac.CHARACTER_SET_NAME, NULL, ac.CHARACTER_SET_NAME, NLS_CHARSET_NAME(NLS_CHARSET_ID(ac.CHARACTER_SET_NAME))) CHARSET,
                decode(ac.CHAR_LENGTH,NULL, 1, 0, 1,ac.DATA_LENGTH/ac.CHAR_LENGTH) BYTES_PER_CHAR,
                decode(ac.CHAR_USED,'C', 'Y','N') USE_CHAR_SEMANTICS
        FROM all_tab_columns<Parameter name="dblink"/> ac, all_col_comments<Parameter name="dblink"/> acc
	WHERE acc.table_name = ac.table_name
		AND ac.column_name = acc.column_name
		AND ac.owner = <Parameter name="owner"/>
		AND acc.owner = <Parameter name="owner"/>
	ORDER BY ac.table_name, ac.column_id
</miv_columns>

<miv_unique_keys type="SQLStatement" default="true">
	SELECT ac.table_name entity_name, rtrim(ac.constraint_name) key_name, rtrim(ac.constraint_name) business_name, '' description, rtrim(ac.constraint_type) constraint_type
	FROM all_constraints<Parameter name="dblink"/> ac
	WHERE upper(ac.constraint_type) in ('U', 'P')
		AND ac.owner = <Parameter name="owner"/>
	ORDER BY ac.constraint_name
</miv_unique_keys>

<miv_foreign_keys type="SQLStatement" default="true">
	SELECT ac.table_name entity_name, rtrim(ac.constraint_name) foreign_key_name,
		rtrim(ac.constraint_name) business_name, '' description, rtrim(ac.r_constraint_name) unique_key_name
	FROM all_constraints<Parameter name="dblink"/> ac
	WHERE upper(ac.constraint_type) = 'R'
		AND ac.owner = <Parameter name="owner"/>
	ORDER BY ac.constraint_name
</miv_foreign_keys>


<miv_key_columns type="SQLStatement" default="true">
	SELECT constraint_name key_name, rtrim(substr(column_name, 1, 50)) column_name, position
	FROM all_cons_columns<Parameter name="dblink"/>
	WHERE owner = <Parameter name="owner"/>
</miv_key_columns>
 
<miv_fk_tables type="SQLStatement" default="true">
	SELECT  rtrim(ac1.table_name) orig_table_name,
		rtrim(ac2.table_name) foreign_table_name,
		substr(atc.comments, 1, 2000) foreign_table_description
	FROM 	all_constraints<Parameter name="dblink"/> ac2,
	      	all_tab_comments<Parameter name="dblink"/> atc,
		all_constraints<Parameter name="dblink"/> ac1
	WHERE	upper(ac1.constraint_type) = 'R'
		AND ac1.owner = ac2.owner
		AND ac1.owner = <Parameter name="owner"/>
		AND upper(atc.table_type)='TABLE'
		AND ac2.constraint_name = ac1.r_constraint_name
		AND ac2.table_name = atc.table_name
		AND ac2.owner = atc.owner
	ORDER BY orig_table_name
</miv_fk_tables>

<miv_capabilities type="ResultSet">
	<table_supported>true</table_supported>
	<view_supported>true</view_supported>
	<sequence_supported>true</sequence_supported>
	<table_name_filter_supported>true</table_name_filter_supported>
	<view_name_filter_supported>true</view_name_filter_supported>
	<sequence_name_filter_supported>true</sequence_name_filter_supported>
	<business_area_supported>false</business_area_supported>	
	<business_area_table_supported>false</business_area_table_supported>	
	<business_area_view_supported>false</business_area_view_supported>	
	<business_area_sequence_supported>false</business_area_sequence_supported>	
	<application_owner_supported>true</application_owner_supported>
	<table_fklevel_supported>true</table_fklevel_supported>
	<reimport_supported>true</reimport_supported>
	<data_object_at_leaf_levels>false</data_object_at_leaf_levels>
	<multiple_tree_supported>false</multiple_tree_supported>
</miv_capabilities>

</miv>
